Class Rectangle2

java.lang.Object
com.ardor3d.math.Rectangle2
All Implemented Interfaces:
Poolable, ReadOnlyRectangle2, Savable, Externalizable, Serializable, Cloneable

public class Rectangle2 extends Object implements Cloneable, Savable, Externalizable, ReadOnlyRectangle2, Poolable

Defines a finite plane within two dimensional space that is specified via an origin (x,y - considered bottom left usually) and a width and height.

This class is at least partially patterned after awt's Rectangle class.
See Also:
  • Constructor Details

    • Rectangle2

      public Rectangle2()
      Constructor creates a new Rectangle2 with its origin at 0,0 and width/height of 0.
    • Rectangle2

      public Rectangle2(int x, int y, int width, int height)
      Constructor creates a new Rectangle2 with using the given x,y,width and height values.
      Parameters:
      x - the x value
      y - the y value
      width - the width
      height - the height
    • Rectangle2

      public Rectangle2(ReadOnlyRectangle2 source)
      Constructor creates a new Rectangle2 using the values of the provided source rectangle.
      Parameters:
      source - the rectangle to copy from
  • Method Details

    • getX

      public int getX()
      Specified by:
      getX in interface ReadOnlyRectangle2
      Returns:
      the x coordinate of the origin of this rectangle.
    • setX

      public void setX(int x)
      Parameters:
      x - the new x coordinate of the origin of this rectangle
    • getY

      public int getY()
      Specified by:
      getY in interface ReadOnlyRectangle2
      Returns:
      the y coordinate of the origin of this rectangle.
    • setY

      public void setY(int y)
      Parameters:
      y - the new y coordinate of the origin of this rectangle
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface ReadOnlyRectangle2
      Returns:
      the width of this rectangle.
    • setWidth

      public void setWidth(int width)
      Parameters:
      width - the new width of this rectangle
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface ReadOnlyRectangle2
      Returns:
      the height of this rectangle.
    • setHeight

      public void setHeight(int height)
      Parameters:
      height - the new height of this rectangle
    • set

      public Rectangle2 set(int x, int y, int width, int height)
    • set

      public Rectangle2 set(ReadOnlyRectangle2 rect)
    • intersect

      public Rectangle2 intersect(ReadOnlyRectangle2 other, Rectangle2 store)
    • intersect

      public static Rectangle2 intersect(ReadOnlyRectangle2 src1, ReadOnlyRectangle2 src2, Rectangle2 store)
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the string representation of this rectangle.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      returns a unique code for this rectangle object based on its values. If two rectangles are numerically equal, they will return the same hash code value.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare for equality
      Returns:
      true if this rectangle and the provided rectangle have the same origin and dimensions
    • clone

      public Rectangle2 clone()
      Specified by:
      clone in interface ReadOnlyRectangle2
      Overrides:
      clone in class Object
      Returns:
      a new instance of Rectangle2 with the same value as this object.
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • getClassTag

      public Class<? extends Rectangle2> getClassTag()
      Specified by:
      getClassTag in interface Savable
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Used with serialization. Not to be called manually.
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - ObjectInput
      Throws:
      IOException - if something wrong occurs while reading
      ClassNotFoundException - if a class is not found
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Used with serialization. Not to be called manually.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - ObjectOutput
      Throws:
      IOException - if something wrong occurs while writing
    • fetchTempInstance

      public static final Rectangle2 fetchTempInstance()
      Returns:
      An instance of Rectangle2 that is intended for temporary use in calculations and so forth. Multiple calls to the method should return instances of this class that are not currently in use.
    • releaseTempInstance

      public static final void releaseTempInstance(Rectangle2 rectangle)
      Releases a Rectangle2 back to be used by a future call to fetchTempInstance. TAKE CARE: this object should no longer have other classes referencing it or "Bad Things" will happen.
      Parameters:
      rectangle - the Rectangle2 to release.