Package org.eclipse.draw2d.geometry
Class PrecisionRectangle
java.lang.Object
org.eclipse.draw2d.geometry.Rectangle
org.eclipse.draw2d.geometry.PrecisionRectangle
- All Implemented Interfaces:
Serializable
,Cloneable
,Translatable
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 Summary
FieldsModifier and TypeFieldDescriptiondouble
Deprecated.double
Deprecated.UsesetPreciseWidth(double)
andpreciseWidth()
instead.double
Deprecated.UsesetPreciseX(double)
andpreciseX()
instead.double
Deprecated.UsesetPreciseX(double)
andpreciseY()
instead. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new PrecisionRectangle with all values 0.PrecisionRectangle
(double x, double y, double width, double height) Constructs a PrecisionRectangle with the provided values.PrecisionRectangle
(Point p, Dimension d) Constructs a new PrecisionRectangle from a given Point and a DimensionPrecisionRectangle
(Rectangle rect) Constructs a new PrecisionRectangle from the given integer Rectangle. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(double x, double y) Returns whether the given coordinates are within the boundaries of this Rectangle.boolean
contains
(int x, int y) Returns whether the given coordinates are within the boundaries of this Rectangle.boolean
Returns whether the given point is within the boundaries of this Rectangle.boolean
Returnstrue
if the given rectangle is contained within the boundaries of this Rectangle.boolean
Returns whether the input object is equal to this Rectangle or not.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.expand
(int h, int v) Expands the horizontal and vertical sides of this Rectangle with the values provided as input, and returns this for convenience.Expands the horizontal and vertical sides of this Rectangle by the width and height of the given Insets, and returns this for convenience.Returns a new Point representing the middle point of the bottom side of this Rectangle.Returns a new Point representing the bottom left point of this Rectangle.Returns a new Point representing the bottom right point of this Rectangle.Returns a new point representing the center of this Rectangle.getCopy()
Returns a new Rectangle which has the exact same parameters as this Rectangle.Returns a precise copy of this.getTop()
Returns a new Point which represents the middle point of the top side of this Rectangle.Returns a new Point which represents the top left hand corner of this Rectangle.Returns a new Point which represents the top right hand corner of this Rectangle.Sets the size of this Rectangle to the intersection region with the Rectangle supplied as input, and returns this for convenience.void
performScale
(double factor) Scales this object by the scale factor.void
performTranslate
(int dx, int dy) Translates this object horizontally bydx
and vertically bydy
.double
Returns the bottom coordinte in double precision.double
Returnsdouble
heightdouble
Returns the right side in double precision.double
Returnsdouble
widthdouble
preciseX()
Returnsdouble
x coordinatedouble
preciseY()
Returnsdouble
y coordinateresize
(double w, double h) Resizes this Rectangle by the values supplied as input and returns this for convenience.resize
(int w, int h) Resizes this Rectangle by the values supplied as input and returns this for convenience.Resizes this Rectangle by the Dimension provided as input and returns this for convenience.setBounds
(int x, int y, int width, int height) Sets the x, y, width, and height values of this Rectangle to the provided values.Sets the location and size of this rectangle to the provided ones.Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.void
setHeight
(double value) Deprecated.UsesetPreciseHeight(double)
instead.setHeight
(int height) Sets the height of this Rectangle to the specified one.setLocation
(int x, int y) Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.setLocation
(Point loc) Sets the location of this Rectangle to the point given as input and returns this for convenience.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.setPreciseHeight
(double value) Sets the height of this PrecisionRectangle to the specified value.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.Sets the precise location of this PrecisionRectanglesetPreciseSize
(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.Set the size of this PrecisionRectangle to the given dimension's width and height.setPreciseWidth
(double value) Sets the width of this PrecisionRectangle to the specified one.setPreciseX
(double value) Sets the x value.setPreciseY
(double value) Sets the y value.setSize
(int w, int h) Sets the width of this Rectangle to w and the height of this Rectangle to h and returns this for convenience.Sets the width and height of this Rectangle to the width and height of the given Dimension and returns this for convenience.void
setWidth
(double value) Deprecated.UsesetPreciseWidth(double)
instead.setWidth
(int width) Sets the width of this Rectangle to the specified one.void
setX
(double value) Deprecated.UsesetPreciseX(double)
instead.setX
(int value) Sets the x value of the Rectangle and returns this for convenience.void
setY
(double value) Deprecated.UsesetPreciseX(double)
instead.setY
(int value) Sets the y value of the Rectangle and returns this for convenience.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.shrink
(int h, int v) Shrinks the sides of this Rectangle by the horizontal and vertical values provided as input, and returns this Rectangle for convenience.Shrinks this rectangle by the amount specified ininsets
.boolean
Returnstrue
if the input Rectangle touches this Rectangle.translate
(double dx, double dy) Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.translate
(int dx, int dy) Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.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.Switches the x and y values, as well as the width and height of this Rectangle.union
(double x, double y) Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).union
(double x, double y, double w, double h) Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).union
(int x, int y) Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the coordinate (x,y).union
(int x, int y, int w, int h) Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the rectangle (x, y, w, h).void
Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point.union
(PrecisionRectangle rect) Deprecated.Useunion(Rectangle)
insteadUpdates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle.void
Deprecated.This method should not be accessed by clients any more (it will be made private in future releases).Methods inherited from class org.eclipse.draw2d.geometry.Rectangle
bottom, crop, equals, getCropped, getExpanded, getExpanded, getExpanded, getHorizontalInterval, getIntersection, getLeft, getLocation, getPosition, getResized, getResized, getResized, getRight, getShrinked, getShrinked, getShrinked, getSize, getTranslated, getTranslated, getTranslated, getTransposed, getUnion, getUnion, getVerticalInterval, hashCode, height, intersects, isEmpty, left, right, scale, scale, setBottom, setRight, shrinkLeft, shrinkTop, top, toString, union, width, x, y
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.draw2d.geometry.Translatable
performTranslate, performTranslate, performTranslate
-
Field Details
-
preciseHeight
public double preciseHeightDeprecated.UsesetPreciseHeight(double)
andpreciseHeight()
instead. This field will become private in the future.Double value for height -
preciseWidth
public double preciseWidthDeprecated.UsesetPreciseWidth(double)
andpreciseWidth()
instead. This field will become private in the future.Double value for width -
preciseX
public double preciseXDeprecated.UsesetPreciseX(double)
andpreciseX()
instead. This field will become private in the future.Double value for X -
preciseY
public double preciseYDeprecated.UsesetPreciseX(double)
andpreciseY()
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 locationy
- Y locationwidth
- Width of the rectangleheight
- Height of the rectangle- Since:
- 3.7
-
PrecisionRectangle
Constructs a new PrecisionRectangle from a given Point and a Dimension- Parameters:
p
- The Point to specify x and y location of the PrecisionRectangled
- The Dimension to use for width and height of the PrecisionRectangle- Since:
- 3.7
-
PrecisionRectangle
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. -
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. -
contains
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. -
contains
Description copied from class:Rectangle
Returnstrue
if the given rectangle is contained within the boundaries of this Rectangle. -
equals
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. -
expand
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. -
expand
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. -
expand
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. -
getBottom
Description copied from class:Rectangle
Returns a new Point representing the middle point of the bottom side of this Rectangle. -
getBottomLeft
Description copied from class:Rectangle
Returns a new Point representing the bottom left point of this Rectangle.- Overrides:
getBottomLeft
in classRectangle
- Returns:
- Point at the bottom left of the rectangle
- See Also:
-
getBottomRight
Description copied from class:Rectangle
Returns a new Point representing the bottom right point of this Rectangle.- Overrides:
getBottomRight
in classRectangle
- Returns:
- Point at the bottom right of the rectangle
- See Also:
-
getCenter
Description copied from class:Rectangle
Returns a new point representing the center of this Rectangle. -
getCopy
Description copied from class:Rectangle
Returns a new Rectangle which has the exact same parameters as this Rectangle. -
getPreciseCopy
Returns a precise copy of this.- Returns:
- a precise copy
-
getTop
Description copied from class:Rectangle
Returns a new Point which represents the middle point of the top side of this Rectangle. -
getTopLeft
Description copied from class:Rectangle
Returns a new Point which represents the top left hand corner of this Rectangle.- Overrides:
getTopLeft
in classRectangle
- Returns:
- Point at the top left of the rectangle
- See Also:
-
getTopRight
Description copied from class:Rectangle
Returns a new Point which represents the top right hand corner of this Rectangle.- Overrides:
getTopRight
in classRectangle
- Returns:
- Point at the top right of the rectangle
- See Also:
-
intersect
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. -
performScale
public void performScale(double factor) Description copied from interface:Translatable
Scales this object by the scale factor.- Specified by:
performScale
in interfaceTranslatable
- Overrides:
performScale
in classRectangle
- Parameters:
factor
- The scale factor- See Also:
-
performTranslate
public void performTranslate(int dx, int dy) Description copied from interface:Translatable
Translates this object horizontally bydx
and vertically bydy
.- Specified by:
performTranslate
in interfaceTranslatable
- Overrides:
performTranslate
in classRectangle
- Parameters:
dx
- The amount to translate horizontallydy
- 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
Returnsdouble
height- Overrides:
preciseHeight
in classRectangle
- 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
Returnsdouble
width- Overrides:
preciseWidth
in classRectangle
- Returns:
double
width- See Also:
-
preciseX
public double preciseX()Description copied from class:Rectangle
Returnsdouble
x coordinate -
preciseY
public double preciseY()Description copied from class:Rectangle
Returnsdouble
y coordinate -
resize
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. -
resize
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. -
resize
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. -
setBounds
Description copied from class:Rectangle
Sets the x, y, width, and height values of this Rectangle to the provided values. -
setBounds
Description copied from class:Rectangle
Sets the location and size of this rectangle to the provided ones. -
setBounds
Description copied from class:Rectangle
Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience. -
setHeight
public void setHeight(double value) Deprecated.UsesetPreciseHeight(double)
instead.Sets the height.- Parameters:
value
- the new height
-
setHeight
Description copied from class:Rectangle
Sets the height of this Rectangle to the specified one. -
setLocation
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 classRectangle
- Parameters:
x
- The new X coordinatey
- The new Y coordinate- Returns:
this
for convenience- See Also:
-
setLocation
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 classRectangle
- Parameters:
loc
- New position of this Rectangle- Returns:
this
for convenience- See Also:
-
setPreciseBounds
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 xy
- The new ywidth
- The new widthheight
- The new height- Returns:
- this for convenience
- Since:
- 3.7
-
setPreciseHeight
Sets the height of this PrecisionRectangle to the specified value.- Parameters:
value
- The new height.- Returns:
- this for convenience
- Since:
- 3.7
-
setPreciseLocation
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 valuey
- The new y value- Returns:
- this for convenience
- Since:
- 3.7
-
setPreciseLocation
Sets the precise location of this PrecisionRectangle- Parameters:
loc
- The new location- Returns:
- this for convenience.
- Since:
- 3.7
-
setPreciseSize
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 widthh
- The new height- Returns:
- this for convenience.
- Since:
- 3.7
-
setPreciseSize
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
Sets the width of this PrecisionRectangle to the specified one.- Parameters:
value
- The new width- Returns:
- this for convenience
- Since:
- 3.7
-
setPreciseX
Sets the x value.- Parameters:
value
- The new x value- Returns:
- this for convenience
- Since:
- 3.7
-
setPreciseY
Sets the y value.- Parameters:
value
- the new y value- Returns:
- this for convenience
- Since:
- 3.7
-
setSize
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. -
setSize
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. -
setWidth
public void setWidth(double value) Deprecated.UsesetPreciseWidth(double)
instead.Sets the width.- Parameters:
value
- the new width
-
setWidth
Description copied from class:Rectangle
Sets the width of this Rectangle to the specified one. -
setX
public void setX(double value) Deprecated.UsesetPreciseX(double)
instead.Sets the x value.- Parameters:
value
- the new x value
-
setX
Description copied from class:Rectangle
Sets the x value of the Rectangle and returns this for convenience. -
setY
public void setY(double value) Deprecated.UsesetPreciseX(double)
instead.Sets the y value.- Parameters:
value
- the new y value
-
setY
Description copied from class:Rectangle
Sets the y value of the Rectangle and returns this for convenience. -
shrink
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. -
shrink
Description copied from class:Rectangle
Shrinks this rectangle by the amount specified ininsets
. -
shrink
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 currentRectangle.width()
orRectangle.height()
of the rectangle,0
is used instead. The center of this Rectangle is kept constant. -
touches
Description copied from class:Rectangle
Returnstrue
if the input Rectangle touches this Rectangle. -
translate
Description copied from class:Rectangle
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience. -
translate
Description copied from class:Rectangle
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience. -
translate
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. -
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. -
union
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). -
union
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). -
union
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). -
union
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). -
union
Description copied from class:Rectangle
Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point. -
union
Deprecated.Useunion(Rectangle)
insteadUnions the given PrecisionRectangle with this rectangle and returnsthis
for convenience.- Parameters:
rect
- the rectangle being unioned- Returns:
this
for convenience- Since:
- 3.0
-
union
Description copied from class:Rectangle
Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle. -
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 ifpreciseX
,preciseY
,preciseWidth
, andpreciseHeight
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
-
setPreciseHeight(double)
andpreciseHeight()
instead.