Class RMRect

  • All Implemented Interfaces:
    java.awt.Shape, java.io.Serializable, java.lang.Cloneable

    public class RMRect
    extends java.awt.geom.Rectangle2D.Double
    This class extends Rectanlge2D to add some convenient rect methods.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D

        java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte MaxXEdge  
      static byte MaxYEdge  
      static byte MinXEdge  
      static byte MinYEdge  
      static RMRect unitRect  
      static RMRect zeroRect  
      • Fields inherited from class java.awt.geom.Rectangle2D.Double

        height, width, x, y
      • Fields inherited from class java.awt.geom.Rectangle2D

        OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
    • Constructor Summary

      Constructors 
      Constructor Description
      RMRect()
      Creates an empty rect.
      RMRect​(double x, double y, double w, double h)
      Creates a rect with the given x, y, width and height (doubles).
      RMRect​(java.awt.geom.Point2D... points)
      Creates a rect enclosing the given array of points.
      RMRect​(java.awt.geom.Rectangle2D aRect)
      Creates a rect from an awt rect.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RMRect clone()
      Standard clone implementation.
      boolean containsRect​(RMRect aRect)
      Returns whether the receiver contains the given rect.
      RMRect divideRect​(double anAmount, byte anEdge)
      Slices rect by given amount (from given edge) - returns remainder.
      RMRect divideRect​(double anAmount, byte anEdge, RMRect aRmndr)
      Slices rect by given amount (from given edge) - returns remainder.
      static RMRect fromXMLString​(java.lang.String aString)
      Creates a rect from an String in XML format as defined in toXMLString().
      RMRect getCorraledRect​(RMRect aRect, float anInset)
      Returns the given rect moved, if needed, to be contained by this rect.
      int getHitEdges​(java.awt.geom.Point2D aPoint, double aRadius)
      Returns the mask of edges hit by the given point.
      double getMidX()
      Returns the x mid-point of the rect.
      double getMidY()
      Returns the y mid-point of the rect.
      RMPoint getOrigin()
      Returns the origin of the rect as an RMPoint.
      RMPoint getPerimeterPointForRadial​(double anAngle, boolean doEllipse)
      Returns the point on the rectangle's perimeter that is intersected by a radial at the given angle from the center of the rect.
      RMPoint[] getPoints()
      Returns an array of four points containing each corner of the rect.
      RMRect inset​(double anInset)
      Insets the receiver rect by the given amount.
      RMRect inset​(double xInset, double yInset)
      Insets the receiver rect by the given amount.
      RMRect insetRect​(double anInset)
      Creates a rect derived from the receiver inset by the given amount.
      RMRect insetRect​(double xInset, double yInset)
      Creates a rect derived from the receiver inset by the given amount.
      RMRect intersectedRect​(RMRect r2)
      Returns the rect formed by the area overlapping with the given rect.
      boolean intersectsRect​(RMRect aRect)
      Returns whether the receiver intersects with the given rect.
      boolean intersectsRectEvenIfEmpty​(RMRect aRect)
      Returns whether the receiver intersects with the given rect.
      RMRect offset​(double dx, double dy)
      Offsets the receiver by the given x & y.
      RMRect offsetRect​(double dx, double dy)
      Creates a rect derived by offsetting the receiver by the given x & y.
      RMRect scale​(double anAmount)
      Scales the receiver rect by the given amount.
      RMRect scaledRect​(double anAmount)
      Creates a rect derived from the receiver scaled by the given amount.
      void setHitEdges​(java.awt.geom.Point2D aPoint, int anEdgeMask)
      Resets the edges of a rect, given a mask of edges and a new point.
      RMRect setOrigin​(double x, double y)
      Sets the origin of the rect.
      RMRect squareRectInRect()
      Creates a rect representing the largest square inside rect.
      java.lang.String toString()
      Returns a String reprsentation of this rect.
      java.lang.String toXMLString()
      Returns an XML string representation of this rect.
      void union​(RMRect r2)
      Unions the receiver rect with the given rect.
      void unionEvenIfEmpty​(RMRect r2)
      Unions the receiver rect with the given rect.
      RMRect unionRect​(RMRect r2)
      Creates a rect encompassing the receiver and the given rect.
      boolean widthsIntersect​(RMRect r2)
      Returns whether the receiver intersects with the given rect (horizontally only).
      • Methods inherited from class java.awt.geom.Rectangle2D.Double

        createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect
      • Methods inherited from class java.awt.geom.Rectangle2D

        add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
      • Methods inherited from class java.awt.geom.RectangularShape

        contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RMRect

        public RMRect()
        Creates an empty rect.
      • RMRect

        public RMRect​(double x,
                      double y,
                      double w,
                      double h)
        Creates a rect with the given x, y, width and height (doubles).
      • RMRect

        public RMRect​(java.awt.geom.Point2D... points)
        Creates a rect enclosing the given array of points.
      • RMRect

        public RMRect​(java.awt.geom.Rectangle2D aRect)
        Creates a rect from an awt rect.
    • Method Detail

      • getOrigin

        public RMPoint getOrigin()
        Returns the origin of the rect as an RMPoint.
      • setOrigin

        public RMRect setOrigin​(double x,
                                double y)
        Sets the origin of the rect.
      • getMidX

        public double getMidX()
        Returns the x mid-point of the rect.
      • getMidY

        public double getMidY()
        Returns the y mid-point of the rect.
      • union

        public void union​(RMRect r2)
        Unions the receiver rect with the given rect.
      • unionRect

        public RMRect unionRect​(RMRect r2)
        Creates a rect encompassing the receiver and the given rect.
      • unionEvenIfEmpty

        public void unionEvenIfEmpty​(RMRect r2)
        Unions the receiver rect with the given rect.
      • intersectsRect

        public boolean intersectsRect​(RMRect aRect)
        Returns whether the receiver intersects with the given rect.
      • intersectsRectEvenIfEmpty

        public boolean intersectsRectEvenIfEmpty​(RMRect aRect)
        Returns whether the receiver intersects with the given rect.
      • intersectedRect

        public RMRect intersectedRect​(RMRect r2)
        Returns the rect formed by the area overlapping with the given rect.
      • widthsIntersect

        public boolean widthsIntersect​(RMRect r2)
        Returns whether the receiver intersects with the given rect (horizontally only).
      • offset

        public RMRect offset​(double dx,
                             double dy)
        Offsets the receiver by the given x & y.
      • offsetRect

        public RMRect offsetRect​(double dx,
                                 double dy)
        Creates a rect derived by offsetting the receiver by the given x & y.
      • squareRectInRect

        public RMRect squareRectInRect()
        Creates a rect representing the largest square inside rect.
      • containsRect

        public boolean containsRect​(RMRect aRect)
        Returns whether the receiver contains the given rect.
      • getPoints

        public RMPoint[] getPoints()
        Returns an array of four points containing each corner of the rect.
      • inset

        public RMRect inset​(double anInset)
        Insets the receiver rect by the given amount.
      • inset

        public RMRect inset​(double xInset,
                            double yInset)
        Insets the receiver rect by the given amount.
      • insetRect

        public RMRect insetRect​(double anInset)
        Creates a rect derived from the receiver inset by the given amount.
      • insetRect

        public RMRect insetRect​(double xInset,
                                double yInset)
        Creates a rect derived from the receiver inset by the given amount.
      • getHitEdges

        public int getHitEdges​(java.awt.geom.Point2D aPoint,
                               double aRadius)
        Returns the mask of edges hit by the given point.
      • setHitEdges

        public void setHitEdges​(java.awt.geom.Point2D aPoint,
                                int anEdgeMask)
        Resets the edges of a rect, given a mask of edges and a new point.
      • divideRect

        public RMRect divideRect​(double anAmount,
                                 byte anEdge)
        Slices rect by given amount (from given edge) - returns remainder.
      • divideRect

        public RMRect divideRect​(double anAmount,
                                 byte anEdge,
                                 RMRect aRmndr)
        Slices rect by given amount (from given edge) - returns remainder.
      • scale

        public RMRect scale​(double anAmount)
        Scales the receiver rect by the given amount.
      • scaledRect

        public RMRect scaledRect​(double anAmount)
        Creates a rect derived from the receiver scaled by the given amount.
      • getPerimeterPointForRadial

        public RMPoint getPerimeterPointForRadial​(double anAngle,
                                                  boolean doEllipse)
        Returns the point on the rectangle's perimeter that is intersected by a radial at the given angle from the center of the rect. Zero degrees is at the 3 o'clock position.
        Parameters:
        anAngle - Angle in degrees.
        doEllipse - Whether to scale radials into ellipse or leave them normal.
        Returns:
        Returns point on perimeter of rect intersected by radial at given angle.
      • getCorraledRect

        public RMRect getCorraledRect​(RMRect aRect,
                                      float anInset)
        Returns the given rect moved, if needed, to be contained by this rect.
      • toString

        public java.lang.String toString()
        Returns a String reprsentation of this rect.
        Overrides:
        toString in class java.awt.geom.Rectangle2D.Double
      • toXMLString

        public java.lang.String toXMLString()
        Returns an XML string representation of this rect.
      • fromXMLString

        public static RMRect fromXMLString​(java.lang.String aString)
        Creates a rect from an String in XML format as defined in toXMLString().
      • clone

        public RMRect clone()
        Standard clone implementation.
        Overrides:
        clone in class java.awt.geom.RectangularShape