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 intCNR_BLBottom-left cornerstatic intCNR_BRBottom-right cornerstatic intCNR_TLTop-left cornerstatic intCNR_TRTop-right cornerorg.jogamp.vecmath.Point2fcorner1org.jogamp.vecmath.Point2fcorner2protected org.jogamp.vecmath.Vector2frotation -
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.Objectclone()booleancontains(org.jogamp.vecmath.Point2f point)org.jogamp.vecmath.Point2fgetCenterPt()org.jogamp.vecmath.Point2fgetCorner(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.Vector2fgetDiagonal()floatgetDiagonalLength()floatgetHeight()Returns the width of this rectangle, which is a distance along the edge perpendicular torotation.org.jogamp.vecmath.Vector2fgetRotation()Returns a copy of this rectangle's rotation vector.java.util.ArrayList<LineSegment2D>getSides()org.jogamp.vecmath.Point2fgetVertex(int i)java.util.ArrayList<org.jogamp.vecmath.Point2f>getVertices()floatgetWidth()Returns the width of this rectangle, which is a distance alongrotation.voidresetRotation()Resets the rotation vector of this rectangle to its default of (1, 0) - the x-axis.voidsetRotation(org.jogamp.vecmath.Vector2f v)Sets the rotation vector of this rectangle, specifying the orientation of its top and bottom edges.voidsetVertices(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, writeXMLMethods 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:
getCenterPtin classShape2D
-
getDiagonalLength
public float getDiagonalLength() -
getVertices
public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()- Specified by:
getVerticesin classShape2D
-
setVertices
public void setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)- Specified by:
setVerticesin classShape2D
-
getVertex
public org.jogamp.vecmath.Point2f getVertex(int i) -
clone
public java.lang.Object clone()
-