Package mgui.geometry
Class Rect2D
java.lang.Object
mgui.geometry.Shape2D
mgui.geometry.Rect2D
public class Rect2D extends Shape2D
Represents a 2D rectangle. This rectangle is aligned with the x- and y-axes by default, but a
rotation can be specified by setting the
rotation
vector, which represents the
orientation of the top and bottom edges.- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields Modifier and Type Field Description static int
CNR_BL
Bottom-left cornerstatic int
CNR_BR
Bottom-right cornerstatic int
CNR_TL
Top-left cornerstatic int
CNR_TR
Top-right cornerorg.jogamp.vecmath.Point2f
corner1
org.jogamp.vecmath.Point2f
corner2
protected org.jogamp.vecmath.Vector2f
rotation
-
Constructor Summary
Constructors Constructor Description Rect2D()
Rect2D(float x1, float y1, float x2, float y2)
Rect2D(float x1, float y1, float x2, float y2, org.jogamp.vecmath.Vector2f rotation)
Rect2D(Rect2D copy)
Rect2D(org.jogamp.vecmath.Point2f pt1, org.jogamp.vecmath.Point2f pt2)
Rect2D(org.jogamp.vecmath.Point2f pt1, org.jogamp.vecmath.Point2f pt2, org.jogamp.vecmath.Vector2f rotation)
-
Method Summary
Modifier and Type Method Description java.lang.Object
clone()
boolean
contains(org.jogamp.vecmath.Point2f point)
org.jogamp.vecmath.Point2f
getCenterPt()
org.jogamp.vecmath.Point2f
getCorner(int corner)
Returns the corner specified bycorner
, which must be one of the constantsCNR_BL
,CNR_TL
,CNR_BR
, orCNR_TR
.org.jogamp.vecmath.Point2f[]
getCorners()
Returns the four corners of this rectangle, ordered as bottom left, bottom right, top right, and top left.protected org.jogamp.vecmath.Vector2f
getDiagonal()
float
getDiagonalLength()
float
getHeight()
Returns the width of this rectangle, which is a distance along the edge perpendicular torotation
.org.jogamp.vecmath.Vector2f
getRotation()
Returns a copy of this rectangle's rotation vector.java.util.ArrayList<LineSegment2D>
getSides()
org.jogamp.vecmath.Point2f
getVertex(int i)
java.util.ArrayList<org.jogamp.vecmath.Point2f>
getVertices()
float
getWidth()
Returns the width of this rectangle, which is a distance alongrotation
.void
resetRotation()
Resets the rotation vector of this rectangle to its default of (1, 0) - the x-axis.void
setRotation(org.jogamp.vecmath.Vector2f v)
Sets the rotation vector of this rectangle, specifying the orientation of its top and bottom edges.void
setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)
Methods inherited from class mgui.geometry.Shape2D
getBounds, getCoords, getDTD, getLocalName, getProximity, getProximityPoint, getShortXML, getSize, getVertices, getXML, getXML, getXMLSchema, handleXMLElementEnd, handleXMLElementStart, handleXMLString, setCoords, setVertices, transform, transform, writeXML, writeXML, writeXML
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
corner1
public org.jogamp.vecmath.Point2f corner1 -
corner2
public org.jogamp.vecmath.Point2f corner2 -
rotation
protected org.jogamp.vecmath.Vector2f rotation -
CNR_BL
public static final int CNR_BLBottom-left corner- See Also:
- Constant Field Values
-
CNR_TL
public static final int CNR_TLTop-left corner- See Also:
- Constant Field Values
-
CNR_BR
public static final int CNR_BRBottom-right corner- See Also:
- Constant Field Values
-
CNR_TR
public static final int CNR_TRTop-right corner- See Also:
- Constant Field Values
-
-
Constructor Details
-
Rect2D
public Rect2D() -
Rect2D
public Rect2D(org.jogamp.vecmath.Point2f pt1, org.jogamp.vecmath.Point2f pt2) -
Rect2D
public Rect2D(org.jogamp.vecmath.Point2f pt1, org.jogamp.vecmath.Point2f pt2, org.jogamp.vecmath.Vector2f rotation) -
Rect2D
-
Rect2D
public Rect2D(float x1, float y1, float x2, float y2) -
Rect2D
public Rect2D(float x1, float y1, float x2, float y2, org.jogamp.vecmath.Vector2f rotation)
-
-
Method Details
-
setRotation
public void setRotation(org.jogamp.vecmath.Vector2f v)Sets the rotation vector of this rectangle, specifying the orientation of its top and bottom edges. If the angle between this vector and the diagonal between the two corners is greater than PI / 2, its direction is flipped.- Parameters:
v
- the new rotation vector
-
resetRotation
public void resetRotation()Resets the rotation vector of this rectangle to its default of (1, 0) - the x-axis.- Parameters:
v
-
-
getRotation
public org.jogamp.vecmath.Vector2f getRotation()Returns a copy of this rectangle's rotation vector.- Returns:
- a copy of the rotation vector
-
getHeight
public float getHeight()Returns the width of this rectangle, which is a distance along the edge perpendicular torotation
.- Returns:
- the height of this rectangle
-
getWidth
public float getWidth()Returns the width of this rectangle, which is a distance alongrotation
.- Returns:
- the width of this rectangle
-
getDiagonal
protected org.jogamp.vecmath.Vector2f getDiagonal() -
getCorners
public org.jogamp.vecmath.Point2f[] getCorners()Returns the four corners of this rectangle, ordered as bottom left, bottom right, top right, and top left.- Returns:
-
getCorner
public org.jogamp.vecmath.Point2f getCorner(int corner)Returns the corner specified bycorner
, which must be one of the constantsCNR_BL
,CNR_TL
,CNR_BR
, orCNR_TR
.- Parameters:
corner
-- Returns:
- the coordinates of the specified corner
-
getSides
-
contains
public boolean contains(org.jogamp.vecmath.Point2f point) -
getCenterPt
public org.jogamp.vecmath.Point2f getCenterPt()- Overrides:
getCenterPt
in classShape2D
-
getDiagonalLength
public float getDiagonalLength() -
getVertices
public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()- Specified by:
getVertices
in classShape2D
-
setVertices
public void setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)- Specified by:
setVertices
in classShape2D
-
getVertex
public org.jogamp.vecmath.Point2f getVertex(int i) -
clone
public java.lang.Object clone()
-