Class PrecisionRectangle

java.lang.Object
org.eclipse.draw2d.geometry.Rectangle
org.eclipse.draw2d.geometry.PrecisionRectangle
All Implemented Interfaces:
Serializable, Cloneable, Translatable

public final class PrecisionRectangle extends Rectangle
A Rectangle implementation using floating point values which are truncated into the inherited integer fields. The use of floating point prevents rounding errors from accumulating.
See Also:
  • Field Details

    • preciseHeight

      public double preciseHeight
      Deprecated.
      Use setPreciseHeight(double) and preciseHeight() instead. This field will become private in the future.
      Double value for height
    • preciseWidth

      public double preciseWidth
      Deprecated.
      Use setPreciseWidth(double) and preciseWidth() instead. This field will become private in the future.
      Double value for width
    • preciseX

      public double preciseX
      Deprecated.
      Use setPreciseX(double) and preciseX() instead. This field will become private in the future.
      Double value for X
    • preciseY

      public double preciseY
      Deprecated.
      Use setPreciseX(double) and preciseY() instead. This field will become private in the future.
      Double value for Y
  • Constructor Details

    • PrecisionRectangle

      public PrecisionRectangle()
      Constructs a new PrecisionRectangle with all values 0.
    • PrecisionRectangle

      public PrecisionRectangle(double x, double y, double width, double height)
      Constructs a PrecisionRectangle with the provided values.
      Parameters:
      x - X location
      y - Y location
      width - Width of the rectangle
      height - Height of the rectangle
      Since:
      3.7
    • PrecisionRectangle

      public PrecisionRectangle(Point p, Dimension d)
      Constructs a new PrecisionRectangle from a given Point and a Dimension
      Parameters:
      p - The Point to specify x and y location of the PrecisionRectangle
      d - The Dimension to use for width and height of the PrecisionRectangle
      Since:
      3.7
    • PrecisionRectangle

      public PrecisionRectangle(Rectangle rect)
      Constructs a new PrecisionRectangle from the given integer Rectangle.
      Parameters:
      rect - the base rectangle
  • Method Details

    • contains

      public boolean contains(double x, double y)
      Description copied from class: Rectangle
      Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Overrides:
      contains in class Rectangle
      Parameters:
      x - X value
      y - Y value
      Returns:
      true if the coordinates are within this Rectangle
      See Also:
    • contains

      public boolean contains(int x, int y)
      Description copied from class: Rectangle
      Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Overrides:
      contains in class Rectangle
      Parameters:
      x - X value
      y - Y value
      Returns:
      true if the coordinates are within this Rectangle
      See Also:
    • contains

      public boolean contains(Point p)
      Description copied from class: Rectangle
      Returns whether the given point is within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.
      Overrides:
      contains in class Rectangle
      Parameters:
      p - Point being tested for containment
      Returns:
      true if the Point is within this Rectangle
      See Also:
    • contains

      public boolean contains(Rectangle rect)
      Description copied from class: Rectangle
      Returns true if the given rectangle is contained within the boundaries of this Rectangle.
      Overrides:
      contains in class Rectangle
      Parameters:
      rect - the Rectangle to test
      Returns:
      true if the Rectangle is within this Rectangle
      See Also:
    • equals

      public boolean equals(Object o)
      Description copied from class: Rectangle
      Returns whether the input object is equal to this Rectangle or not. Rectangles are equivalent if their x, y, height, and width values are the same.
      Overrides:
      equals in class Rectangle
      Parameters:
      o - Object being tested for equality
      Returns:
      Returns the result of the equality test
      See Also:
    • expand

      public Rectangle expand(double h, double v)
      Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience. The location of its center is kept constant.
      Overrides:
      expand in class Rectangle
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      this for convenience
      Since:
      3.4
    • expand

      public Rectangle expand(Insets insets)
      Description copied from class: Rectangle
      Expands the horizontal and vertical sides of this Rectangle by the width and height of the given Insets, and returns this for convenience.
      Overrides:
      expand in class Rectangle
      Parameters:
      insets - contains the amounts to expand on each side
      Returns:
      this for convenience
      See Also:
    • expand

      public Rectangle expand(int h, int v)
      Description copied from class: Rectangle
      Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience. The location of its center is kept constant.
      Overrides:
      expand in class Rectangle
      Parameters:
      h - Horizontal increment
      v - Vertical increment
      Returns:
      this for convenience
      See Also:
    • getBottom

      public Point getBottom()
      Description copied from class: Rectangle
      Returns a new Point representing the middle point of the bottom side of this Rectangle.
      Overrides:
      getBottom in class Rectangle
      Returns:
      Point at the bottom of the Rectangle
      See Also:
    • getBottomLeft

      public Point getBottomLeft()
      Description copied from class: Rectangle
      Returns a new Point representing the bottom left point of this Rectangle.
      Overrides:
      getBottomLeft in class Rectangle
      Returns:
      Point at the bottom left of the rectangle
      See Also:
    • getBottomRight

      public Point getBottomRight()
      Description copied from class: Rectangle
      Returns a new Point representing the bottom right point of this Rectangle.
      Overrides:
      getBottomRight in class Rectangle
      Returns:
      Point at the bottom right of the rectangle
      See Also:
    • getCenter

      public Point getCenter()
      Description copied from class: Rectangle
      Returns a new point representing the center of this Rectangle.
      Overrides:
      getCenter in class Rectangle
      Returns:
      Point at the center of the rectangle
      See Also:
    • getCopy

      public Rectangle getCopy()
      Description copied from class: Rectangle
      Returns a new Rectangle which has the exact same parameters as this Rectangle.
      Overrides:
      getCopy in class Rectangle
      Returns:
      Copy of this Rectangle
      See Also:
    • getPreciseCopy

      public PrecisionRectangle getPreciseCopy()
      Returns a precise copy of this.
      Returns:
      a precise copy
    • getTop

      public Point getTop()
      Description copied from class: Rectangle
      Returns a new Point which represents the middle point of the top side of this Rectangle.
      Overrides:
      getTop in class Rectangle
      Returns:
      Point at the top of the Rectangle
      See Also:
    • getTopLeft

      public Point getTopLeft()
      Description copied from class: Rectangle
      Returns a new Point which represents the top left hand corner of this Rectangle.
      Overrides:
      getTopLeft in class Rectangle
      Returns:
      Point at the top left of the rectangle
      See Also:
    • getTopRight

      public Point getTopRight()
      Description copied from class: Rectangle
      Returns a new Point which represents the top right hand corner of this Rectangle.
      Overrides:
      getTopRight in class Rectangle
      Returns:
      Point at the top right of the rectangle
      See Also:
    • intersect

      public Rectangle intersect(Rectangle rect)
      Description copied from class: Rectangle
      Sets the size of this Rectangle to the intersection region with the Rectangle supplied as input, and returns this for convenience. The location and dimensions are set to zero if there is no intersection with the input Rectangle.
      Overrides:
      intersect in class Rectangle
      Parameters:
      rect - Rectangle for the calculating intersection.
      Returns:
      this for convenience
      See Also:
    • performScale

      public void performScale(double factor)
      Description copied from interface: Translatable
      Scales this object by the scale factor.
      Specified by:
      performScale in interface Translatable
      Overrides:
      performScale in class Rectangle
      Parameters:
      factor - The scale factor
      See Also:
    • performTranslate

      public void performTranslate(int dx, int dy)
      Description copied from interface: Translatable
      Translates this object horizontally by dx and vertically by dy.
      Specified by:
      performTranslate in interface Translatable
      Overrides:
      performTranslate in class Rectangle
      Parameters:
      dx - The amount to translate horizontally
      dy - The amount to translate vertically
      See Also:
    • preciseBottom

      public double preciseBottom()
      Returns the bottom coordinte in double precision.
      Returns:
      the precise bottom
    • preciseHeight

      public double preciseHeight()
      Description copied from class: Rectangle
      Returns double height
      Overrides:
      preciseHeight in class Rectangle
      Returns:
      double height
      See Also:
    • preciseRight

      public double preciseRight()
      Returns the right side in double precision.
      Returns:
      the precise right
    • preciseWidth

      public double preciseWidth()
      Description copied from class: Rectangle
      Returns double width
      Overrides:
      preciseWidth in class Rectangle
      Returns:
      double width
      See Also:
    • preciseX

      public double preciseX()
      Description copied from class: Rectangle
      Returns double x coordinate
      Overrides:
      preciseX in class Rectangle
      Returns:
      double x coordinate
      See Also:
    • preciseY

      public double preciseY()
      Description copied from class: Rectangle
      Returns double y coordinate
      Overrides:
      preciseY in class Rectangle
      Returns:
      double y coordinate
      See Also:
    • resize

      public Rectangle resize(Dimension d)
      Description copied from class: Rectangle
      Resizes this Rectangle by the Dimension provided as input and returns this for convenience. This Rectange's width will become this.width + sizeDelta.width. Likewise for height.
      Overrides:
      resize in class Rectangle
      Parameters:
      d - Resize data as a Dimension
      Returns:
      this for convenience
      See Also:
    • resize

      public Rectangle resize(double w, double h)
      Description copied from class: Rectangle
      Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.
      Overrides:
      resize in class Rectangle
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      this for convenience
      See Also:
    • resize

      public Rectangle resize(int w, int h)
      Description copied from class: Rectangle
      Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.
      Overrides:
      resize in class Rectangle
      Parameters:
      w - Amount by which width is to be resized
      h - Amount by which height is to be resized
      Returns:
      this for convenience
      See Also:
    • setBounds

      public Rectangle setBounds(int x, int y, int width, int height)
      Description copied from class: Rectangle
      Sets the x, y, width, and height values of this Rectangle to the provided values.
      Overrides:
      setBounds in class Rectangle
      Parameters:
      x - The new x
      y - The new y
      width - The new width
      height - The new height
      Returns:
      this for convenience
      See Also:
    • setBounds

      public Rectangle setBounds(Point location, Dimension size)
      Description copied from class: Rectangle
      Sets the location and size of this rectangle to the provided ones.
      Overrides:
      setBounds in class Rectangle
      Parameters:
      location - The new location
      size - The new size
      Returns:
      this for convenience
      See Also:
    • setBounds

      public Rectangle setBounds(Rectangle rect)
      Description copied from class: Rectangle
      Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.
      Overrides:
      setBounds in class Rectangle
      Parameters:
      rect - Rectangle providing the bounding values
      Returns:
      this for convenience
      See Also:
    • setHeight

      public void setHeight(double value)
      Deprecated.
      Sets the height.
      Parameters:
      value - the new height
    • setHeight

      public Rectangle setHeight(int height)
      Description copied from class: Rectangle
      Sets the height of this Rectangle to the specified one.
      Overrides:
      setHeight in class Rectangle
      Parameters:
      height - The new height
      Returns:
      this for convenience.
      See Also:
    • setLocation

      public Rectangle setLocation(int x, int y)
      Description copied from class: Rectangle
      Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.
      Overrides:
      setLocation in class Rectangle
      Parameters:
      x - The new X coordinate
      y - The new Y coordinate
      Returns:
      this for convenience
      See Also:
    • setLocation

      public Rectangle setLocation(Point loc)
      Description copied from class: Rectangle
      Sets the location of this Rectangle to the point given as input and returns this for convenience.
      Overrides:
      setLocation in class Rectangle
      Parameters:
      loc - New position of this Rectangle
      Returns:
      this for convenience
      See Also:
    • setPreciseBounds

      public PrecisionRectangle setPreciseBounds(double x, double y, double width, double height)
      Sets the preciseX, preciseY, preciseWidth, and preciseHeight values of this PrecisionRectangle to the provided values and updates the integer values of x, y, width, and height accordingly.
      Parameters:
      x - The new x
      y - The new y
      width - The new width
      height - The new height
      Returns:
      this for convenience
      Since:
      3.7
    • setPreciseHeight

      public PrecisionRectangle setPreciseHeight(double value)
      Sets the height of this PrecisionRectangle to the specified value.
      Parameters:
      value - The new height.
      Returns:
      this for convenience
      Since:
      3.7
    • setPreciseLocation

      public PrecisionRectangle setPreciseLocation(double x, double y)
      Sets the preciseX and preciseY values of this PrecisionRectangle to the provided values and updates the integer values of x and y accordingly.
      Parameters:
      x - The new x value
      y - The new y value
      Returns:
      this for convenience
      Since:
      3.7
    • setPreciseLocation

      public PrecisionRectangle setPreciseLocation(PrecisionPoint loc)
      Sets the precise location of this PrecisionRectangle
      Parameters:
      loc - The new location
      Returns:
      this for convenience.
      Since:
      3.7
    • setPreciseSize

      public PrecisionRectangle setPreciseSize(double w, double h)
      Sets the preciseWidth and preciseHeight values of this PrecisionRectangle to the provided values and updates the integer values of width and height accordingly.
      Parameters:
      w - The new width
      h - The new height
      Returns:
      this for convenience.
      Since:
      3.7
    • setPreciseSize

      public PrecisionRectangle setPreciseSize(PrecisionDimension size)
      Set the size of this PrecisionRectangle to the given dimension's width and height. Returns this for convenience.
      Parameters:
      size - The new size
      Returns:
      this for convenience.
      Since:
      3.7
    • setPreciseWidth

      public PrecisionRectangle setPreciseWidth(double value)
      Sets the width of this PrecisionRectangle to the specified one.
      Parameters:
      value - The new width
      Returns:
      this for convenience
      Since:
      3.7
    • setPreciseX

      public PrecisionRectangle setPreciseX(double value)
      Sets the x value.
      Parameters:
      value - The new x value
      Returns:
      this for convenience
      Since:
      3.7
    • setPreciseY

      public PrecisionRectangle setPreciseY(double value)
      Sets the y value.
      Parameters:
      value - the new y value
      Returns:
      this for convenience
      Since:
      3.7
    • setSize

      public Rectangle setSize(Dimension d)
      Description copied from class: Rectangle
      Sets the width and height of this Rectangle to the width and height of the given Dimension and returns this for convenience.
      Overrides:
      setSize in class Rectangle
      Parameters:
      d - The new Dimension
      Returns:
      this for convenience
      See Also:
    • setSize

      public Rectangle setSize(int w, int h)
      Description copied from class: Rectangle
      Sets the width of this Rectangle to w and the height of this Rectangle to h and returns this for convenience.
      Overrides:
      setSize in class Rectangle
      Parameters:
      w - The new width
      h - The new height
      Returns:
      this for convenience
      See Also:
    • setWidth

      public void setWidth(double value)
      Deprecated.
      Sets the width.
      Parameters:
      value - the new width
    • setWidth

      public Rectangle setWidth(int width)
      Description copied from class: Rectangle
      Sets the width of this Rectangle to the specified one.
      Overrides:
      setWidth in class Rectangle
      Parameters:
      width - The new width
      Returns:
      this for convenience.
      See Also:
    • setX

      public void setX(double value)
      Deprecated.
      Use setPreciseX(double) instead.
      Sets the x value.
      Parameters:
      value - the new x value
    • setX

      public Rectangle setX(int value)
      Description copied from class: Rectangle
      Sets the x value of the Rectangle and returns this for convenience.
      Overrides:
      setX in class Rectangle
      Parameters:
      value - The new x value
      Returns:
      this for convenience
      See Also:
    • setY

      public void setY(double value)
      Deprecated.
      Use setPreciseX(double) instead.
      Sets the y value.
      Parameters:
      value - the new y value
    • setY

      public Rectangle setY(int value)
      Description copied from class: Rectangle
      Sets the y value of the Rectangle and returns this for convenience.
      Overrides:
      setY in class Rectangle
      Parameters:
      value - The new y value
      Returns:
      this for convenience
      See Also:
    • shrink

      public Rectangle shrink(double h, double v)
      Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience. The center of this Rectangle is kept constant.
      Overrides:
      shrink in class Rectangle
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      Since:
      3.4
    • shrink

      public Rectangle shrink(Insets insets)
      Description copied from class: Rectangle
      Shrinks this rectangle by the amount specified in insets.
      Overrides:
      shrink in class Rectangle
      Parameters:
      insets - Insets to be removed from the Rectangle
      Returns:
      this for convenience
      See Also:
    • shrink

      public Rectangle shrink(int h, int v)
      Description copied from class: Rectangle
      Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience. If the given reduction amount of larger than the current Rectangle.width() or Rectangle.height() of the rectangle, 0 is used instead. The center of this Rectangle is kept constant.
      Overrides:
      shrink in class Rectangle
      Parameters:
      h - Horizontal reduction amount
      v - Vertical reduction amount
      Returns:
      this for convenience
      See Also:
    • touches

      public boolean touches(Rectangle rect)
      Description copied from class: Rectangle
      Returns true if the input Rectangle touches this Rectangle.
      Overrides:
      touches in class Rectangle
      Parameters:
      rect - Rectangle being checked for contact
      Returns:
      true if rect touches this Rectangle
      See Also:
    • translate

      public Rectangle translate(double dx, double dy)
      Description copied from class: Rectangle
      Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
      Overrides:
      translate in class Rectangle
      Parameters:
      dx - Shift along X axis
      dy - Shift along Y axis
      Returns:
      this for convenience
      See Also:
    • translate

      public Rectangle translate(int dx, int dy)
      Description copied from class: Rectangle
      Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.
      Overrides:
      translate in class Rectangle
      Parameters:
      dx - Shift along X axis
      dy - Shift along Y axis
      Returns:
      this for convenience
      See Also:
    • translate

      public Rectangle translate(Point p)
      Description copied from class: Rectangle
      Moves this Rectangle horizontally by the x value of the given Point and vertically by the y value of the given Point, then returns this Rectangle for convenience.
      Overrides:
      translate in class Rectangle
      Parameters:
      p - Point which provides translation information
      Returns:
      this for convenience
      See Also:
    • transpose

      public Rectangle transpose()
      Description copied from class: Rectangle
      Switches the x and y values, as well as the width and height of this Rectangle. Useful for orientation changes.
      Overrides:
      transpose in class Rectangle
      Returns:
      this for convenience
      See Also:
    • union

      public Rectangle union(double x, double y)
      Description copied from class: Rectangle
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
      Overrides:
      union in class Rectangle
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      this for convenience
      See Also:
    • union

      public Rectangle union(double x, double y, double w, double h)
      Description copied from class: Rectangle
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
      Overrides:
      union in class Rectangle
      Parameters:
      x - X coordinate of desired union.
      y - Y coordinate of desired union.
      w - Width of desired union.
      h - Height of desired union.
      Returns:
      this for convenience
      See Also:
    • union

      public Rectangle union(int x, int y)
      Description copied from class: Rectangle
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).
      Overrides:
      union in class Rectangle
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      this for convenience
      See Also:
    • union

      public Rectangle union(int x, int y, int w, int h)
      Description copied from class: Rectangle
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).
      Overrides:
      union in class Rectangle
      Parameters:
      x - X coordinate of desired union.
      y - Y coordinate of desired union.
      w - Width of desired union.
      h - Height of desired union.
      Returns:
      this for convenience
      See Also:
    • union

      public void union(Point p)
      Description copied from class: Rectangle
      Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point.
      Overrides:
      union in class Rectangle
      Parameters:
      p - Point to be unioned with this Rectangle
      See Also:
    • union

      Deprecated.
      Use union(Rectangle) instead
      Unions the given PrecisionRectangle with this rectangle and returns this for convenience.
      Parameters:
      rect - the rectangle being unioned
      Returns:
      this for convenience
      Since:
      3.0
    • union

      public Rectangle union(Rectangle rect)
      Description copied from class: Rectangle
      Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle.
      Overrides:
      union in class Rectangle
      Parameters:
      rect - Rectangle to be unioned with this Rectangle
      Returns:
      this for convenience
      See Also:
    • updateInts

      public void updateInts()
      Deprecated.
      This method should not be accessed by clients any more (it will be made private in future releases). The update of integer and precision fields is performed automatically if preciseX, preciseY, preciseWidth, and preciseHeight field values are not manipulated directly, but only via respective methods offered by this class.
      Updates the integer values based on the current precise values.
      Since:
      3.0