Search this API

y.geom
Class OrientedRectangle

java.lang.Object
  extended by y.geom.OrientedRectangle
All Implemented Interfaces:
PlaneObject

public class OrientedRectangle
extends java.lang.Object
implements PlaneObject

An oriented rectangle in 2D coordinate space with double precision coordinates. The rectangle's height extends from its anchor point in the direction of its up vector (ux, uy). Its width extends from its anchor point in direction (-uy, ux) (i.e. perpendicular to the up vector). This means that an oriented rectangle with anchor point (0, 0) width 100, height 10, and up vector (0, -1) is a paraxial rectangle with upper left corner (0, -10) and lower right corner (100, 0).

 

Constructor Summary
OrientedRectangle(double anchorX, double anchorY, double width, double height)
          Creates a new instance using the provided values to initialize anchor and size.
OrientedRectangle(double anchorX, double anchorY, double width, double height, double upX, double upY)
          Creates a new instance using the provided values to initialize anchor, size, and up vector.
OrientedRectangle(OrientedRectangle rect)
          Creates a new instance using the provided rectangle's values to initialize anchor, size, and up vector.
OrientedRectangle(YPoint anchor, YDimension size)
          Creates a new instance using the provided values to initialize the anchor and size.
OrientedRectangle(YPoint position, YDimension size, YVector upVector)
          Creates a new instance using the provided values to initialize anchor, size, and up vector.
OrientedRectangle(YRectangle rect)
          Creates a new instance using the provided rectangle's values to initialize anchor and size.
 
Method Summary
 void adoptValues(OrientedRectangle other)
          Copies the actual values from the given OrientedRectangle to this instance.
static YPoint[] calcPoints(OrientedRectangle rect)
          Determines the four corner points of an oriented rectangle.
static double[] calcPointsInDouble(OrientedRectangle rect)
          Determines the coordinates of the four corners of an oriented rectangle.
 boolean contains(double x, double y)
          Determines whether or not the specified point lies inside this oriented rectangle.
 boolean contains(double x, double y, boolean closed)
          Determines whether or not the specified point lies inside this oriented rectangle.
static boolean contains(OrientedRectangle rect, double x, double y, double eps)
          Determines whether the given oriented rectangle contains the provided point, using an epsilon value.
static boolean contains(OrientedRectangle r1, OrientedRectangle r2, double eps)
          Determines whether the given rectangle r1 contains rectangle r2, using an epsilon value.
static boolean contains(OrientedRectangle rect, YPoint p, double eps)
          Determines whether the given oriented rectangle contains the provided point, using an epsilon value.
 boolean equals(java.lang.Object o)
           
 YPoint getAnchor()
          Returns the anchor of this oriented rectangle.
 double getAnchorX()
          Returns the x-coordinate of this rectangle's anchor point.
 double getAnchorY()
          Returns the y-coordinate of this rectangle's anchor point.
 double getAngle()
          Returns the angle (measured in radians) of this rectangle.
 YRectangle getBoundingBox()
          Calculates the paraxial bounding box of this oriented rectangle.
 YPoint getCenter()
          Returns the current center of the oriented rectangle.
 double getHeight()
          Returns the height of this rectangle.
 OrientedRectangle getMovedInstance(double dx, double dy)
          Creates a new OrientedRectangle instance whose anchor point is moved by the specified distance values, but has the same width, height, and up vector as this rectangle.
 OrientedRectangle getResizedInstance(double width, double height)
          Creates a new OrientedRectangle instance that has the specified width and height, but has the same anchor point and up vector as this rectangle.
 YDimension getSize()
          Returns the size of this rectangle.
 double getUpX()
          Returns the x-component of this rectangle's up vector.
 double getUpY()
          Returns the y-component of this rectangle's up vector.
 double getWidth()
          Returns the width of this rectangle.
 int hashCode()
           
static YPoint intersectionPoint(OrientedRectangle rect, LineSegment line, double eps)
          Determines an intersection point of the specified oriented rectangle and the specified line segment.
static boolean intersects(OrientedRectangle rect, LineSegment line, double eps)
          Determines whether or not the specified oriented rectangle and the specified line segment intersect.
static boolean intersects(OrientedRectangle orientedRectangle, YRectangle rectangle, double eps)
          Determines whether a rectangle intersects an oriented rectangle, given an epsilon.
 boolean isEmpty()
          Returns whether this instance has negative width or height.
 void moveBy(double dx, double dy)
          Moves this rectangle by applying the offset to the anchor.
 void setAnchor(double x, double y)
          Sets the anchor of this rectangle.
 void setAnchor(YPoint anchor)
          Sets the anchor of this rectangle.
 void setAngle(double angle)
          Sets the angle of this rectangle.
 void setCenter(double cx, double cy)
          Sets the anchor of the OrientedRectangle so that the center of the rectangle coincides with the given coordinate pair.
 void setCenter(YPoint center)
          Sets the anchor of the OrientedRectangle so that the center of the rectangle coincides with the given point.
 void setSize(double width, double height)
          Sets the size of this rectangle.
 void setSize(YDimension size)
          Sets the size of this rectangle.
 void setUpVector(double upX, double upY)
          Sets the components of the up vector to the new values.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrientedRectangle

public OrientedRectangle(YRectangle rect)
Creates a new instance using the provided rectangle's values to initialize anchor and size. The oriented rectangle's up vector will be (0, -1).

Parameters:
rect - the provided rectangle.

OrientedRectangle

public OrientedRectangle(OrientedRectangle rect)
Creates a new instance using the provided rectangle's values to initialize anchor, size, and up vector.

Parameters:
rect - the provided rectangle.

OrientedRectangle

public OrientedRectangle(YPoint anchor,
                         YDimension size)
Creates a new instance using the provided values to initialize the anchor and size. The oriented rectangle's up vector will be (0, -1).

Parameters:
anchor - The provider for the dynamic anchor of this instance.
size - The provider for the dynamic size of this instance.

OrientedRectangle

public OrientedRectangle(YPoint position,
                         YDimension size,
                         YVector upVector)
Creates a new instance using the provided values to initialize anchor, size, and up vector.

Parameters:
position - The provider for the dynamic anchor of this instance.
size - The provider for the dynamic size of this instance.
upVector - The up vector.

OrientedRectangle

public OrientedRectangle(double anchorX,
                         double anchorY,
                         double width,
                         double height)
Creates a new instance using the provided values to initialize anchor and size. The oriented rectangle's up vector will be (0, -1).

Parameters:
anchorX - The x coordinate of the anchor of the oriented rectangle.
anchorY - The y coordinate of the anchor of the oriented rectangle.
width - The width of the rectangle.
height - The height of the rectangle.

OrientedRectangle

public OrientedRectangle(double anchorX,
                         double anchorY,
                         double width,
                         double height,
                         double upX,
                         double upY)
Creates a new instance using the provided values to initialize anchor, size, and up vector.

Parameters:
anchorX - The x coordinate of the anchor of the oriented rectangle.
anchorY - The y coordinate of the anchor of the oriented rectangle.
width - The width of the rectangle.
height - The height of the rectangle.
upX - The x component of the up vector.
upY - The y component of the up vector.
Method Detail

isEmpty

public boolean isEmpty()
Returns whether this instance has negative width or height.


getAnchor

public YPoint getAnchor()
Returns the anchor of this oriented rectangle.


setAnchor

public void setAnchor(YPoint anchor)
Sets the anchor of this rectangle.

Parameters:
anchor - the new anchor point of this rectangle.

setAnchor

public void setAnchor(double x,
                      double y)
Sets the anchor of this rectangle.

Parameters:
x - the new x-coordinate of the anchor point.
y - the new y-coordinate of the anchor point.

getAnchorX

public double getAnchorX()
Returns the x-coordinate of this rectangle's anchor point.


getAnchorY

public double getAnchorY()
Returns the y-coordinate of this rectangle's anchor point.


getSize

public YDimension getSize()
Returns the size of this rectangle.

Returns:
the size of this rectangle.

setSize

public void setSize(YDimension size)
Sets the size of this rectangle.

Parameters:
size - the new size.

setSize

public void setSize(double width,
                    double height)
Sets the size of this rectangle.

Parameters:
width - the new width.
height - the new height.

getWidth

public double getWidth()
Returns the width of this rectangle.

Returns:
the width of this rectangle.

getHeight

public double getHeight()
Returns the height of this rectangle.

Returns:
the height of this rectangle.

setUpVector

public void setUpVector(double upX,
                        double upY)
Sets the components of the up vector to the new values.

Parameters:
upX - The x component of the normalized up vector.
upY - The y component of the normalized up vector.

getUpX

public double getUpX()
Returns the x-component of this rectangle's up vector.

Returns:
the x-component of this rectangle's up vector.

getUpY

public double getUpY()
Returns the y-component of this rectangle's up vector.

Returns:
the y-component of this rectangle's up vector.

getAngle

public double getAngle()
Returns the angle (measured in radians) of this rectangle. The angle of an oriented rectangle is the angle between the vector (0, -1) and the rectangle's up vector in counter clockwise order. An angle of 0 means the up vector points up in direction (0, -1).

Returns:
the angle (measured in radians) of this rectangle.

setAngle

public void setAngle(double angle)
Sets the angle of this rectangle. The angle of an oriented rectangle is the angle between the vector (0, -1) and the rectangle's up vector in counter clockwise order. An angle of 0 means the up vector points up in direction (0, -1).

Parameters:
angle - the new angle in radians.

moveBy

public void moveBy(double dx,
                   double dy)
Moves this rectangle by applying the offset to the anchor.

Parameters:
dx - The x offset to move the rectangle's position by.
dy - The y offset to move the rectangle's position by.

getCenter

public YPoint getCenter()
Returns the current center of the oriented rectangle.

Returns:
the current center of the rectangle.

setCenter

public void setCenter(YPoint center)
Sets the anchor of the OrientedRectangle so that the center of the rectangle coincides with the given point.

Parameters:
center - the new center coordinates.

setCenter

public void setCenter(double cx,
                      double cy)
Sets the anchor of the OrientedRectangle so that the center of the rectangle coincides with the given coordinate pair.

Parameters:
cx - The x coordinate of the center.
cy - The y coordinate of the center.

getBoundingBox

public YRectangle getBoundingBox()
Calculates the paraxial bounding box of this oriented rectangle.

Specified by:
getBoundingBox in interface PlaneObject
Returns:
the paraxial bounding box of this oriented rectangle.

contains

public boolean contains(double x,
                        double y)
Determines whether or not the specified point lies inside this oriented rectangle.

Parameters:
x - the x-coordinate of the point to check.
y - the y-coordinate of the point to check.
Returns:
true iff the specified point lies inside; false otherwise.

contains

public boolean contains(double x,
                        double y,
                        boolean closed)
Determines whether or not the specified point lies inside this oriented rectangle.

Parameters:
x - the x-coordinate of the point to check.
y - the y-coordinate of the point to check.
closed - if true, all points on the border of the rectangle are considered to be contained.
Returns:
true iff the specified point lies inside; false otherwise.

calcPoints

public static YPoint[] calcPoints(OrientedRectangle rect)
Determines the four corner points of an oriented rectangle.

Parameters:
rect - The rectangle to determine the bounds.
Returns:
the array of corner points.

calcPointsInDouble

public static double[] calcPointsInDouble(OrientedRectangle rect)
Determines the coordinates of the four corners of an oriented rectangle.

Parameters:
rect - The rectangle to determine the bounds.
Returns:
the array of coordinates of the corner points in which each even index has the x-coordinate and each odd index the y-coordinate

intersects

public static boolean intersects(OrientedRectangle orientedRectangle,
                                 YRectangle rectangle,
                                 double eps)
Determines whether a rectangle intersects an oriented rectangle, given an epsilon.

Parameters:
orientedRectangle - The oriented rectangle to test.
rectangle - The rectangle to test.
eps - A positive value allows for fuzzy hit testing. If the point lies outside the given object but it's distance is less than or equal to that value, it will be considered a hit.
Returns:
Whether they have a non-empty intersection.

contains

public static boolean contains(OrientedRectangle rect,
                               YPoint p,
                               double eps)
Determines whether the given oriented rectangle contains the provided point, using an epsilon value.

Parameters:
rect - The rectangle.
p - The point to test.
eps - fuzziness range. A positive value allows for fuzzy hit testing. If a point lies outside the given rectangle, but its distance is less than or equal to that value, it will be considered a hit.
Returns:
true if the point lies inside the rectangle; false otherwise.

contains

public static boolean contains(OrientedRectangle rect,
                               double x,
                               double y,
                               double eps)
Determines whether the given oriented rectangle contains the provided point, using an epsilon value.

Parameters:
rect - The rectangle.
x - x-coordinate of the point to test.
y - y-coordinate of the point to test.
eps - fuzziness range. A positive value allows for fuzzy hit testing. If a point lies outside the given rectangle, but its distance is less than or equal to that value, it will be considered a hit.
Returns:
true if the point lies inside the rectangle; false otherwise.

contains

public static boolean contains(OrientedRectangle r1,
                               OrientedRectangle r2,
                               double eps)
Determines whether the given rectangle r1 contains rectangle r2, using an epsilon value.

Parameters:
r1 - The first rectangle.
r2 - The second rectangle.
eps - A positive value allows for fuzzy hit testing. If the point lies outside the given object but it's distance is less than or equal to that value, it will be considered a hit.
Returns:
true iff the r1 contains r2.

intersects

public static boolean intersects(OrientedRectangle rect,
                                 LineSegment line,
                                 double eps)
Determines whether or not the specified oriented rectangle and the specified line segment intersect.

Returns:
true if the rectangle and the segment intersect and false otherwise.

intersectionPoint

public static YPoint intersectionPoint(OrientedRectangle rect,
                                       LineSegment line,
                                       double eps)
Determines an intersection point of the specified oriented rectangle and the specified line segment. Note: there might be more than one intersection point. However this method only returns one intersection point or null if there is no intersection.

Returns:
an intersection point of the specified oriented rectangle and the specified line segment or null if the rectangle and the segment do not intersect.

toString

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

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getMovedInstance

public OrientedRectangle getMovedInstance(double dx,
                                          double dy)
Creates a new OrientedRectangle instance whose anchor point is moved by the specified distance values, but has the same width, height, and up vector as this rectangle.

Parameters:
dx - the distance to move the anchor point in x-direction. A positive value means "move" to the right, a negative value means "move" to the left.
dy - the distance to move the anchor point in y-direction. A positive value means "move" downwards, a negative value means "move" upwards.
Returns:
a new OrientedRectangle instance whose anchor point is moved by the specified distance values.

getResizedInstance

public OrientedRectangle getResizedInstance(double width,
                                            double height)
Creates a new OrientedRectangle instance that has the specified width and height, but has the same anchor point and up vector as this rectangle.

Parameters:
width - the width of the new rectangle.
height - the height of the new rectangle.
Returns:
a new OrientedRectangle instance that has the specified width and height.

adoptValues

public void adoptValues(OrientedRectangle other)
Copies the actual values from the given OrientedRectangle to this instance.

Parameters:
other - the OrientedRectangle to retrieve the values from

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.