Class GRect

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

    public class GRect
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Simple immutable rectangle class for multiple use accepting negative width and height.
    Author:
    Christopher Mindus
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static GRect[] EMPTY_ARRAY
      Empty array of Rect's.
      static GRect ZERO
      Zero rectangle.
    • Constructor Summary

      Constructors 
      Constructor Description
      GRect()
      Constructor for x=y=cx=cy=0.
      GRect​(int x, int y, int cx, int cy)
      Constructor.
      GRect​(ReadTransaction trans)
      Constructor from a Transaction.
      GRect​(java.lang.String string)
      Constructor from a String formatted as "x,y,cx,cy".
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(SendTransaction trans)
      Appends the rectangle to a transaction.
      GRect clone()
      Clones this instance.
      boolean equals​(java.lang.Object o)
      Checks if two rectangles are equal.
      int getCX()
      Gets the width.
      int getCY()
      Gets the height.
      int getHeight()
      Gets the height.
      int getWidth()
      Gets the width.
      int getX()
      Gets the X position.
      int getY()
      Gets the Y position.
      int hashCode()
      Hash code.
      boolean isInside​(Position p)
      Checks if a position is inside.
      java.lang.String toString()
      Formats to a string as "x,y,cx,cy".
      • Methods inherited from class java.lang.Object

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

      • EMPTY_ARRAY

        public static final GRect[] EMPTY_ARRAY
        Empty array of Rect's.
      • ZERO

        public static final GRect ZERO
        Zero rectangle.
    • Constructor Detail

      • GRect

        public GRect()
        Constructor for x=y=cx=cy=0.
      • GRect

        public GRect​(java.lang.String string)
        Constructor from a String formatted as "x,y,cx,cy".
        Parameters:
        string - The string.
        Throws:
        java.lang.IllegalArgumentException - If the string is not well formatted.
      • GRect

        public GRect​(ReadTransaction trans)
        Constructor from a Transaction.
        Parameters:
        trans - The transaction.
      • GRect

        public GRect​(int x,
                     int y,
                     int cx,
                     int cy)
        Constructor.
        Parameters:
        x - X position.
        y - Y position.
        cx - Width.
        cy - Height.
    • Method Detail

      • isInside

        public boolean isInside​(Position p)
        Checks if a position is inside.
        Parameters:
        p - The position.
        Returns:
        true if inside, false otherwise.
      • equals

        public boolean equals​(java.lang.Object o)
        Checks if two rectangles are equal. Supports comparison with Rect.
        Overrides:
        equals in class java.lang.Object
      • clone

        public GRect clone()
        Clones this instance.
        Overrides:
        clone in class java.lang.Object
        Returns:
        As GRect is immutable, cloning will return "this".
      • hashCode

        public int hashCode()
        Hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Returns the hash code.
      • toString

        public java.lang.String toString()
        Formats to a string as "x,y,cx,cy".
        Overrides:
        toString in class java.lang.Object
      • append

        public void append​(SendTransaction trans)
        Appends the rectangle to a transaction.
        Parameters:
        trans - Transaction to append to.
      • getX

        public int getX()
        Gets the X position.
        Returns:
        The X position.
      • getY

        public int getY()
        Gets the Y position.
        Returns:
        The Y position.
      • getCX

        public int getCX()
        Gets the width.
        Returns:
        The width.
      • getCY

        public int getCY()
        Gets the height.
        Returns:
        The height.
      • getWidth

        public int getWidth()
        Gets the width.
        Returns:
        The width.
      • getHeight

        public int getHeight()
        Gets the height.
        Returns:
        The height.