com.partnersoft.geometry.xy
Class XyRectangle

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyRectangle
All Implemented Interfaces:
Immutable, XyArea<XyRectangle>, XyShape<XyRectangle>, java.lang.Iterable<XyPoint>

public class XyRectangle
extends java.lang.Object
implements XyArea<XyRectangle>

A rectangular shape in (x, y) space.

XyRectangles have the usual width and height, are generally (but not necessarily) placed by center, and can be rotated with respect to the axes.

Copyright 2007 Partner Software, Inc.

Version:
$Id: XyRectangle.java 2328 2010-01-06 15:38:22Z paul $
Author:
Paul Reavis

Constructor Summary
XyRectangle(XyPoint center, double width, double height)
          Creates a rectangle, oriented with the x, y axes, with the given center and width and height.
XyRectangle(XyPoint center, XyRotation rotation, double width, double height)
          Creates a rectangle with the given center, rotation, width, and height.
XyRectangle(XyPoint center, XyRotation rotation, XySize size)
          Creates a rectangle with the given center, rotation, width, and height.
XyRectangle(XyPoint center, XySize size)
          Creates a rectangle, oriented with the x, y axes, with the given center and size.
 
Method Summary
 boolean contains(XyPoint point)
          Tests if a point is inside this area.
 boolean equals(java.lang.Object nother)
           
 double getArea()
          Returns the 2-dimensional area covered by this...
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 XyPoint getCenter()
          Center of rectangle.
 double getHeight()
          Retangle height (vertical dimension unless there is a rotation).
 XyPoint getNeCorner()
          The top-right, or "northeast", corner.
 XyPoint getNwCorner()
          The top-left, or "northwest", corner.
 double getPerimeter()
          Returns the total length of the lines and/or curves bounding the area.
 XyRotation getRotation()
          Angle of rotation relative to the X, Y axes.
 XyPoint getSeCorner()
          The bottom-right, or "southeast", corner.
 XySize getSize()
           
 XyPoint getSwCorner()
          The bottom-left, or "southwest", corner.
 double getWidth()
          Retangle width (horizontal dimension unless there is a rotation).
 java.util.Iterator<XyPoint> iterator()
           
static XyRectangle placedByCenter(XyPoint point, double width, double height)
          Creates a new rectangle with the given dimensions whose center is the given point.
static XyRectangle placedByCenter(XyPoint point, XyRotation rotation, double width, double height)
          Creates a new rectangle with the given rotation and dimensions whose center is the given point.
static XyRectangle placedByNeCorner(XyPoint point, double width, double height)
          Creates a new rectangle with the given dimensions whose "northeast" corner is the given point.
static XyRectangle placedByNeCorner(XyPoint point, XyRotation rotation, double width, double height)
          Creates a new rectangle with the given rotation and dimensions whose "northeast" corner is the given point.
static XyRectangle placedByNwCorner(XyPoint point, double width, double height)
          Creates a new rectangle with the given dimensions whose "northwest" corner is the given point.
static XyRectangle placedByNwCorner(XyPoint point, XyRotation rotation, double width, double height)
          Creates a new rectangle with the given rotation and dimensions whose "northwest" corner is the given point.
static XyRectangle placedBySeCorner(XyPoint point, double width, double height)
          Creates a new rectangle with the given dimensions whose "southeast" corner is the given point.
static XyRectangle placedBySeCorner(XyPoint point, XyRotation rotation, double width, double height)
          Creates a new rectangle with the given rotation and dimensions whose "southeast" corner is the given point.
static XyRectangle placedBySwCorner(XyPoint point, double width, double height)
          Creates a new rectangle with the given dimensions whose "southwest" corner is the given point.
static XyRectangle placedBySwCorner(XyPoint point, XyRotation rotation, double width, double height)
          Creates a new rectangle with the given rotation and dimensions whose "southwest" corner is the given point.
 XyRectangle scaledBy(double factor)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyPolygon toPolygon()
          Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).
 XyPolygon toPolygon(XyAngle granulartiy)
          Converts this area to a polygon which approximates it in some fashion.
 java.lang.String toString()
           
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 XyRectangle translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 XyRectangle withCenter(XyPoint point)
          Returns a modified version of this rectangle, with the same dimensions and rotation but the given center point.
 XyRectangle withNeCorner(XyPoint point)
          Returns a modified version of this rectangle, with the same dimensions and rotation but the given "northeast" corner.
 XyRectangle withNwCorner(XyPoint point)
          Returns a modified version of this rectangle, with the same dimensions and rotation but the given "northwest" corner.
 XyRectangle withSeCorner(XyPoint point)
          Returns a modified version of this rectangle, with the same dimensions and rotation but the given "southeast" corner.
 XyRectangle withSwCorner(XyPoint point)
          Returns a modified version of this rectangle, with the same dimensions and rotation but the given "southwest" corner.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XyRectangle

public XyRectangle(XyPoint center,
                   double width,
                   double height)
Creates a rectangle, oriented with the x, y axes, with the given center and width and height.


XyRectangle

public XyRectangle(XyPoint center,
                   XySize size)
Creates a rectangle, oriented with the x, y axes, with the given center and size.


XyRectangle

public XyRectangle(XyPoint center,
                   XyRotation rotation,
                   XySize size)
Creates a rectangle with the given center, rotation, width, and height. The rotation angle is the rotation of the bottom line segment of the rectangle, from left to right relative to the rectangle's rotation.


XyRectangle

public XyRectangle(XyPoint center,
                   XyRotation rotation,
                   double width,
                   double height)
Creates a rectangle with the given center, rotation, width, and height. The rotation angle is the rotation of the bottom line segment of the rectangle, from left to right relative to the rectangle's rotation.

Method Detail

placedBySwCorner

public static XyRectangle placedBySwCorner(XyPoint point,
                                           XyRotation rotation,
                                           double width,
                                           double height)
Creates a new rectangle with the given rotation and dimensions whose "southwest" corner is the given point.


placedBySwCorner

public static XyRectangle placedBySwCorner(XyPoint point,
                                           double width,
                                           double height)
Creates a new rectangle with the given dimensions whose "southwest" corner is the given point.


placedBySeCorner

public static XyRectangle placedBySeCorner(XyPoint point,
                                           XyRotation rotation,
                                           double width,
                                           double height)
Creates a new rectangle with the given rotation and dimensions whose "southeast" corner is the given point.


placedBySeCorner

public static XyRectangle placedBySeCorner(XyPoint point,
                                           double width,
                                           double height)
Creates a new rectangle with the given dimensions whose "southeast" corner is the given point.


placedByNwCorner

public static XyRectangle placedByNwCorner(XyPoint point,
                                           XyRotation rotation,
                                           double width,
                                           double height)
Creates a new rectangle with the given rotation and dimensions whose "northwest" corner is the given point.


placedByNwCorner

public static XyRectangle placedByNwCorner(XyPoint point,
                                           double width,
                                           double height)
Creates a new rectangle with the given dimensions whose "northwest" corner is the given point.


placedByNeCorner

public static XyRectangle placedByNeCorner(XyPoint point,
                                           XyRotation rotation,
                                           double width,
                                           double height)
Creates a new rectangle with the given rotation and dimensions whose "northeast" corner is the given point.


placedByNeCorner

public static XyRectangle placedByNeCorner(XyPoint point,
                                           double width,
                                           double height)
Creates a new rectangle with the given dimensions whose "northeast" corner is the given point.


placedByCenter

public static XyRectangle placedByCenter(XyPoint point,
                                         XyRotation rotation,
                                         double width,
                                         double height)
Creates a new rectangle with the given rotation and dimensions whose center is the given point.


placedByCenter

public static XyRectangle placedByCenter(XyPoint point,
                                         double width,
                                         double height)
Creates a new rectangle with the given dimensions whose center is the given point.


getNwCorner

public XyPoint getNwCorner()
The top-left, or "northwest", corner. Note that due to rotation this may not actually be top-left with respect to the x, y axes.

Returns:
northwest corner point

getSwCorner

public XyPoint getSwCorner()
The bottom-left, or "southwest", corner. Note that due to rotation this may not actually be bottom-left with respect to the x, y axes.

Returns:
southwest corner point

getNeCorner

public XyPoint getNeCorner()
The top-right, or "northeast", corner. Note that due to rotation this may not actually be top-right with respect to the x, y axes.

Returns:
northeast corner point

getSeCorner

public XyPoint getSeCorner()
The bottom-right, or "southeast", corner. Note that due to rotation this may not actually be bottom-right with respect to the x, y axes.

Returns:
northwest corner point

withCenter

public XyRectangle withCenter(XyPoint point)
Returns a modified version of this rectangle, with the same dimensions and rotation but the given center point.


withNwCorner

public XyRectangle withNwCorner(XyPoint point)
Returns a modified version of this rectangle, with the same dimensions and rotation but the given "northwest" corner.


withNeCorner

public XyRectangle withNeCorner(XyPoint point)
Returns a modified version of this rectangle, with the same dimensions and rotation but the given "northeast" corner.


withSwCorner

public XyRectangle withSwCorner(XyPoint point)
Returns a modified version of this rectangle, with the same dimensions and rotation but the given "southwest" corner.


withSeCorner

public XyRectangle withSeCorner(XyPoint point)
Returns a modified version of this rectangle, with the same dimensions and rotation but the given "southeast" corner.


getBounds

public XyBounds getBounds()
Description copied from interface: XyShape
Returns an XyBounds object representing the rectangular extents of this shape.

Specified by:
getBounds in interface XyShape<XyRectangle>

scaledBy

public XyRectangle scaledBy(double factor)
Description copied from interface: XyShape
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Specified by:
scaledBy in interface XyShape<XyRectangle>
Parameters:
factor - scaling factor
Returns:
scaled result

transformedBy

public XyShape transformedBy(XyTransform transform)
Description copied from interface: XyShape
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Specified by:
transformedBy in interface XyShape<XyRectangle>
Parameters:
transform - affine transform to apply.
Returns:
transformed result

translatedBy

public XyRectangle translatedBy(double offsetX,
                                double offsetY)
Description copied from interface: XyShape
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Specified by:
translatedBy in interface XyShape<XyRectangle>
Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

iterator

public java.util.Iterator<XyPoint> iterator()
Specified by:
iterator in interface java.lang.Iterable<XyPoint>

contains

public boolean contains(XyPoint point)
Description copied from interface: XyArea
Tests if a point is inside this area.

Specified by:
contains in interface XyArea<XyRectangle>
Parameters:
point - point to test for containment

getArea

public double getArea()
Description copied from interface: XyArea
Returns the 2-dimensional area covered by this... area.

Specified by:
getArea in interface XyArea<XyRectangle>
Returns:
geometric area of this shape

getPerimeter

public double getPerimeter()
Description copied from interface: XyArea
Returns the total length of the lines and/or curves bounding the area.

Specified by:
getPerimeter in interface XyArea<XyRectangle>
Returns:
geometric perimeter of this shape

getSize

public XySize getSize()

toPolygon

public XyPolygon toPolygon()
Description copied from interface: XyArea
Same as XyArea.toPolygon(XyAngle) with a default angle granularity of 1/60 circle (1 degree, pi/30 radians).

Specified by:
toPolygon in interface XyArea<XyRectangle>

toPolygon

public XyPolygon toPolygon(XyAngle granulartiy)
Description copied from interface: XyArea
Converts this area to a polygon which approximates it in some fashion. For example, a circle can be converted to a polygon with enough sides to roughly approximate its shape. Areas consisting of linked line segments can be represented exactly.

The angle parameter allows a certain level of control of the output. Essentially it dictates the minimum angular granularity used to approximate curved paths. For example, a circle would be turned into a polygon by placing points around the circle, separated by the given angle.

Specified by:
toPolygon in interface XyArea<XyRectangle>

toString

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

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

getWidth

public double getWidth()
Retangle width (horizontal dimension unless there is a rotation).

Returns:
width

getHeight

public double getHeight()
Retangle height (vertical dimension unless there is a rotation).

Returns:
height

getRotation

public XyRotation getRotation()
Angle of rotation relative to the X, Y axes.

Returns:
angle

getCenter

public XyPoint getCenter()
Center of rectangle.