rcssjava.geom
Class Rectangle

java.lang.Object
  extended by rcssjava.geom.Rectangle
All Implemented Interfaces:
Region

public class Rectangle
extends java.lang.Object
implements Region

Implementation of 2d axis-parallel rectangle


Constructor Summary
Rectangle()
          Constructs a rectangle with all point at the origin
Rectangle(double width, double length)
          Constructs a rectangle with the given width and length, and with center at the origin
Rectangle(double width, double length, VecPosition center)
          Constructs a rectangle with the given width and length, and center position
Rectangle(VecPosition p1, VecPosition p2)
          Constructs a rectangle from two corners diagonal from each other
 
Method Summary
 Rectangle add(double d)
          Create a new rectangle shifted in x and y by the given value
 Rectangle add(VecPosition v)
          Create a new rectangle shifted by the given vector
 java.util.Iterator<VecPosition> cornerIterator()
          Get iterator over corners starting with the top-left and moving clockwise
 VecPosition getBottomLeft()
          Get position of bottom-left corner
 VecPosition getBottomRight()
          Get position of bottom-right corner
 LineSegment getBottomSide()
          Get bottom edge
 double getBottomX()
          Get x coordinate of bottom edge
 VecPosition getCenter()
          Get center
 LineSegment getLeftSide()
          Get left edge
 double getLeftY()
          Get y coordinate of left edge
 double getLength()
          Get length
 LineSegment getRightSide()
          Get right edge
 double getRightY()
          Get y coordinate of right edge
 VecPosition getTopLeft()
          Get position of top-left corner
 VecPosition getTopRight()
          Get position of top-right corner
 LineSegment getTopSide()
          Get top edge
 double getTopX()
          Get x coordinate of top edge
 double getWidth()
          Get width
 boolean isInside(VecPosition p)
          Is the given point inside the rectangle?
 void setPoints(VecPosition p1, VecPosition p2)
          Set rectangle from the two diagonal corners given
 java.util.Iterator<LineSegment> sideIterator()
          Get iterator over sides starting with the top and moving clockwise
 Rectangle subtract(double d)
          Create a new rectangle shifted in x and y by the given value in the opposite direction
 Rectangle subtract(VecPosition v)
          Create a new rectangle shifted by the given vector in the opposite direction
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Constructs a rectangle with all point at the origin


Rectangle

public Rectangle(double width,
                 double length)
Constructs a rectangle with the given width and length, and with center at the origin

Parameters:
width - size in y direction
length - size in x direction

Rectangle

public Rectangle(double width,
                 double length,
                 VecPosition center)
Constructs a rectangle with the given width and length, and center position

Parameters:
width - size in y direction
length - size in x direction
center - center of rectangle

Rectangle

public Rectangle(VecPosition p1,
                 VecPosition p2)
Constructs a rectangle from two corners diagonal from each other

Parameters:
p1 - first corner
p2 - second corner
Method Detail

setPoints

public void setPoints(VecPosition p1,
                      VecPosition p2)
Set rectangle from the two diagonal corners given

Parameters:
p1 - first corner
p2 - second corner

getTopLeft

public VecPosition getTopLeft()
Get position of top-left corner

Returns:
corner with largest x and smallest y

getBottomRight

public VecPosition getBottomRight()
Get position of bottom-right corner

Returns:
corner with smallest x and largest y

getTopRight

public VecPosition getTopRight()
Get position of top-right corner

Returns:
corner with largest x and largest y

getBottomLeft

public VecPosition getBottomLeft()
Get position of bottom-left corner

Returns:
corner with smallest x and smallest y

getTopX

public double getTopX()
Get x coordinate of top edge

Returns:
x coordinate of edge with largest x

getBottomX

public double getBottomX()
Get x coordinate of bottom edge

Returns:
x coordinate of edge with smallest x

getLeftY

public double getLeftY()
Get y coordinate of left edge

Returns:
y coordinate of edge with smallest y

getRightY

public double getRightY()
Get y coordinate of right edge

Returns:
y coordinate of edge with largest y

getTopSide

public LineSegment getTopSide()
Get top edge

Returns:
line segment for edge with largest x

getBottomSide

public LineSegment getBottomSide()
Get bottom edge

Returns:
line segment for edge with smallest x

getLeftSide

public LineSegment getLeftSide()
Get left edge

Returns:
line segment for edge with smallest y

getRightSide

public LineSegment getRightSide()
Get right edge

Returns:
line segment for edge with largest y

cornerIterator

public java.util.Iterator<VecPosition> cornerIterator()
Get iterator over corners starting with the top-left and moving clockwise

Returns:
iterator over the corners

sideIterator

public java.util.Iterator<LineSegment> sideIterator()
Get iterator over sides starting with the top and moving clockwise

Returns:
iterator over the sides

isInside

public boolean isInside(VecPosition p)
Is the given point inside the rectangle?

Specified by:
isInside in interface Region
Parameters:
p - test point
Returns:
true if point lies inside

getCenter

public VecPosition getCenter()
Get center

Returns:
position of center

getWidth

public double getWidth()
Get width

Returns:
size of rectangle in y direction

getLength

public double getLength()
Get length

Returns:
size of rectangle in x direction

add

public Rectangle add(double d)
Create a new rectangle shifted in x and y by the given value

Parameters:
d - distance to shift rectangle
Returns:
shifted rectangle

add

public Rectangle add(VecPosition v)
Create a new rectangle shifted by the given vector

Parameters:
v - vector to shift rectangle
Returns:
shifted rectangle

subtract

public Rectangle subtract(double d)
Create a new rectangle shifted in x and y by the given value in the opposite direction

Parameters:
d - distance to shift rectangle
Returns:
shifted rectangle

subtract

public Rectangle subtract(VecPosition v)
Create a new rectangle shifted by the given vector in the opposite direction

Parameters:
v - vector to shift rectangle in opposite direction
Returns:
shifted rectangle

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object