public class YOrientedRectangle extends Object implements IPlaneObject
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 and Description |
---|
YOrientedRectangle(double anchorX,
double anchorY,
double width,
double height)
Creates a new instance using the provided values to initialize anchor and size.
|
YOrientedRectangle(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.
|
YOrientedRectangle(YOrientedRectangle rect)
Creates a new instance using the provided rectangle's values to initialize anchor, size, and up vector.
|
YOrientedRectangle(YPoint anchor,
YDimension size)
Creates a new instance using the provided values to initialize the anchor and size.
|
YOrientedRectangle(YPoint position,
YDimension size,
YVector upVector)
Creates a new instance using the provided values to initialize anchor, size, and up vector.
|
YOrientedRectangle(YRectangle rect)
Creates a new instance using the provided rectangle's values to initialize anchor and size.
|
Modifier and Type | Method and Description |
---|---|
void |
adoptValues(YOrientedRectangle other)
Copies the actual values from the given
OrientedRectangle to this instance. |
static YPoint[] |
calcPoints(YOrientedRectangle rect)
Determines the four corner points of an oriented rectangle.
|
static double[] |
calcPointsInDouble(YOrientedRectangle 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(YOrientedRectangle rect,
double x,
double y,
double eps)
Determines whether the given oriented rectangle contains the provided point, using an epsilon value.
|
static boolean |
contains(YOrientedRectangle r1,
YOrientedRectangle r2,
double eps)
Determines whether the given rectangle r1 contains rectangle r2, using an epsilon value.
|
static boolean |
contains(YOrientedRectangle rect,
YPoint p,
double eps)
Determines whether the given oriented rectangle contains the provided point, using an epsilon value.
|
boolean |
equals(Object o) |
YPoint |
getAnchor()
Gets the anchor of this oriented rectangle.
|
double |
getAnchorX()
Gets the x-coordinate of this rectangle's anchor point.
|
double |
getAnchorY()
Gets the y-coordinate of this rectangle's anchor point.
|
double |
getAngle()
Gets the angle (measured in radians) of this rectangle.
|
YRectangle |
getBoundingBox()
Calculates the paraxial bounding box of this oriented rectangle.
|
YPoint |
getCenter()
Gets the current center of the oriented rectangle.
|
double |
getHeight()
Gets the height of this rectangle.
|
YOrientedRectangle |
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. |
YOrientedRectangle |
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()
Gets the size of this rectangle.
|
double |
getUpX()
Gets the x-component of this rectangle's up vector.
|
double |
getUpY()
Gets the y-component of this rectangle's up vector.
|
double |
getWidth()
Gets the width of this rectangle.
|
int |
hashCode() |
static YPoint |
intersectionPoint(YOrientedRectangle rect,
LineSegment line,
double eps)
Determines an intersection point of the specified oriented rectangle and the specified line segment.
|
static boolean |
intersects(YOrientedRectangle rect,
LineSegment line,
double eps)
Determines whether or not the specified oriented rectangle and the specified line segment intersect.
|
static boolean |
intersects(YOrientedRectangle orientedRectangle,
YRectangle rectangle,
double eps)
Determines whether a rectangle intersects an oriented rectangle, given an epsilon.
|
boolean |
isEmpty()
Gets 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 value)
Sets the anchor of this oriented rectangle.
|
void |
setAngle(double value)
Sets the angle (measured in radians) 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 value)
Sets the current center of the oriented rectangle.
|
void |
setSize(double width,
double height)
Sets the size of this rectangle.
|
void |
setSize(YDimension value)
Sets the size of this rectangle.
|
void |
setUpVector(double upX,
double upY)
Sets the components of the up vector to the new values.
|
String |
toString() |
public YOrientedRectangle(double anchorX, double anchorY, double width, double height)
The oriented rectangle's up vector will be (0, -1)
.
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.public YOrientedRectangle(double anchorX, double anchorY, double width, double height, double upX, double upY)
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.public YOrientedRectangle(YOrientedRectangle rect)
rect
- the provided rectangle.public YOrientedRectangle(YPoint anchor, YDimension size)
The oriented rectangle's up vector will be (0, -1)
.
anchor
- The provider for the dynamic anchor of this instance.size
- The provider for the dynamic size of this instance.public YOrientedRectangle(YPoint position, YDimension size, YVector upVector)
position
- The provider for the dynamic anchor of this instance.size
- The provider for the dynamic size of this instance.upVector
- The up vector.public YOrientedRectangle(YRectangle rect)
The oriented rectangle's up vector will be (0, -1)
.
rect
- the provided rectangle.public void adoptValues(YOrientedRectangle other)
OrientedRectangle
to this instance.other
- the OrientedRectangle
to retrieve the values frompublic static final YPoint[] calcPoints(YOrientedRectangle rect)
rect
- The rectangle to determine the bounds.public static final double[] calcPointsInDouble(YOrientedRectangle rect)
rect
- The rectangle to determine the bounds.public final boolean contains(double x, double y)
x
- the x-coordinate of the point to check.y
- the y-coordinate of the point to check.true
iff the specified point lies inside; false
otherwise.public boolean contains(double x, double y, boolean closed)
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.true
iff the specified point lies inside; false
otherwise.public static final boolean contains(YOrientedRectangle rect, double x, double y, double eps)
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.true
if the point lies inside the rectangle; false
otherwise.public static final boolean contains(YOrientedRectangle r1, YOrientedRectangle r2, double eps)
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.public static final boolean contains(YOrientedRectangle rect, YPoint p, double eps)
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.true
if the point lies inside the rectangle; false
otherwise.public YPoint getAnchor()
setAnchor(YPoint)
public double getAnchorX()
public double getAnchorY()
public double getAngle()
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)
.
setAngle(double)
public YRectangle getBoundingBox()
getBoundingBox
in interface IPlaneObject
public YPoint getCenter()
setCenter(YPoint)
public double getHeight()
public YOrientedRectangle getMovedInstance(double dx, double dy)
OrientedRectangle
instance whose anchor point is moved by the specified distance values, but has
the same width, height, and up vector as this rectangle.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.OrientedRectangle
instance whose anchor point is moved by the specified distance values.public YOrientedRectangle getResizedInstance(double width, double height)
OrientedRectangle
instance that has the specified width and height, but has the same anchor point
and up vector as this rectangle.width
- the width of the new rectangle.height
- the height of the new rectangle.OrientedRectangle
instance that has the specified width and height.public YDimension getSize()
setSize(YDimension)
public double getUpX()
public double getUpY()
public double getWidth()
public static final YPoint intersectionPoint(YOrientedRectangle rect, LineSegment line, double eps)
Note: there might be more than one intersection point. However this method only returns one intersection point or null
if there is no intersection.
null
if the
rectangle and the segment do not intersect.public static final boolean intersects(YOrientedRectangle rect, LineSegment line, double eps)
true
if the rectangle and the segment intersect and false
otherwise.public static final boolean intersects(YOrientedRectangle orientedRectangle, YRectangle rectangle, double eps)
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.public boolean isEmpty()
public void moveBy(double dx, double dy)
dx
- The x offset to move the rectangle's position by.dy
- The y offset to move the rectangle's position by.public void setAnchor(double x, double y)
x
- the new x-coordinate of the anchor point.y
- the new y-coordinate of the anchor point.public void setAnchor(YPoint value)
value
- the new anchor point of this rectangle.getAnchor()
public void setAngle(double value)
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)
.
value
- the angle (measured in radians) of this rectangle.getAngle()
public void setCenter(double cx, double cy)
cx
- The x coordinate of the center.cy
- The y coordinate of the center.public void setCenter(YPoint value)
value
- the current center of the rectangle.getCenter()
public void setSize(double width, double height)
width
- the new width.height
- the new height.public void setSize(YDimension value)
value
- the size of this rectangle.getSize()
public void setUpVector(double upX, double upY)
upX
- The x component of the normalized up vector.upY
- The y component of the normalized up vector.