Package mgui.geometry

Class Rect2D

java.lang.Object
mgui.geometry.Shape2D
mgui.geometry.Rect2D
All Implemented Interfaces:
java.lang.Cloneable, Shape, XMLObject

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 corner
    static int CNR_BR
    Bottom-right corner
    static int CNR_TL
    Top-left corner
    static int CNR_TR
    Top-right corner
    org.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 by corner, which must be one of the constants CNR_BL, CNR_TL, CNR_BR, or CNR_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 to rotation.
    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 along rotation.
    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 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_BL
      Bottom-left corner
      See Also:
      Constant Field Values
    • CNR_TL

      public static final int CNR_TL
      Top-left corner
      See Also:
      Constant Field Values
    • CNR_BR

      public static final int CNR_BR
      Bottom-right corner
      See Also:
      Constant Field Values
    • CNR_TR

      public static final int CNR_TR
      Top-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

      public Rect2D​(Rect2D copy)
    • 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 to rotation.
      Returns:
      the height of this rectangle
    • getWidth

      public float getWidth()
      Returns the width of this rectangle, which is a distance along rotation.
      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 by corner, which must be one of the constants CNR_BL, CNR_TL, CNR_BR, or CNR_TR.
      Parameters:
      corner -
      Returns:
      the coordinates of the specified corner
    • getSides

      public java.util.ArrayList<LineSegment2D> getSides()
    • contains

      public boolean contains​(org.jogamp.vecmath.Point2f point)
      Overrides:
      contains in class Shape2D
    • getCenterPt

      public org.jogamp.vecmath.Point2f getCenterPt()
      Overrides:
      getCenterPt in class Shape2D
    • getDiagonalLength

      public float getDiagonalLength()
    • getVertices

      public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()
      Specified by:
      getVertices in class Shape2D
    • setVertices

      public void setVertices​(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)
      Specified by:
      setVertices in class Shape2D
    • getVertex

      public org.jogamp.vecmath.Point2f getVertex​(int i)
      Specified by:
      getVertex in class Shape2D
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class Shape2D