Package org.geotools.geometry.util
Class XRectangle2D
Object
RectangularShape
Rectangle2D
XRectangle2D
- All Implemented Interfaces:
Shape,Serializable,Cloneable
Serializable, high-performance double-precision rectangle. Instead of using
x, y, width and
height, this class store rectangle's coordinates into the following fields: xmin, xmax,
ymin et ymax. Methods likes contains and intersects are faster, which make this
class more appropriate for using intensively inside a loop. Furthermore, this class work correctly with
infinites and NaN values.- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Rectangle2D
Rectangle2D.Double, Rectangle2D.Float -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Rectangle2DAn immutable instance of aRectangle2Dwith bounds extending toward infinities.protected doubleMaximal x coordinate.protected doubleMinimal x coordinate.protected doubleMaximal y coordinate.protected doubleMinimal y coordinate.Fields inherited from class Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a default rectangle.XRectangle2D(double x, double y, double width, double height) Construct a rectangle with the specified location and dimension.XRectangle2D(Rectangle2D rect) Construct a rectangle with the same coordinates than the supplied rectangle. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double x, double y) Adds a point, specified by the double precision argumentsxandy, to thisRectangle2D.voidadd(Rectangle2D rect) Adds aRectangle2Dobject to thisRectangle2D.booleancontains(double x, double y) Tests if a specified coordinate is inside the boundary of thisRectangle2D.booleancontains(double x, double y, double width, double height) Tests if the interior of thisRectangle2Dentirely contains the specified set of rectangular coordinates.booleancontains(Rectangle2D rect) Tests if the interior of this shape entirely contains the specified rectangle.static booleancontainsInclusive(Rectangle2D outter, Rectangle2D inner) Tests if the interior of theinnerrectangle is contained in the interior and/or the edge of theoutterrectangle.static XRectangle2DcreateFromExtremums(double xmin, double ymin, double xmax, double ymax) Create a rectangle using maximal x and y values rather than width and height.Returns a newRectangle2Dobject representing the intersection of thisRectangle2Dwith the specifiedRectangle2D.createUnion(Rectangle2D rect) Returns a newRectangle2Dobject representing the union of thisRectangle2Dwith the specifiedRectangle2D.static booleanequalsEpsilon(Rectangle2D rect1, Rectangle2D rect2) Returnstrueif the two rectangles are equals up to an epsilon value.doubleReturns the X coordinate of the center of the rectangle.doubleReturns the Y coordinate of the center of the rectangle.doubleReturns the height of the framing rectangle indoubleprecision.doublegetMaxX()Returns the largest X coordinate of the rectangle.doublegetMaxY()Returns the largest Y coordinate of the rectangle.doublegetMinX()Returns the smallest X coordinate of the rectangle.doublegetMinY()Returns the smallest Y coordinate of the rectangle.doublegetWidth()Returns the width of the framing rectangle indoubleprecision.doublegetX()Returns the X coordinate of the upper left corner of the framing rectangle indoubleprecision.doublegetY()Returns the Y coordinate of the upper left corner of the framing rectangle indoubleprecision.static booleanintersectInclusive(Rectangle2D rect1, Rectangle2D rect2) Tests if the interior and/or the edge of two rectangles intersect.static booleanintersectInclusive(Shape shape, Rectangle2D rect) Tests if the interior of theShapeintersects the interior of a specified rectangle.booleanintersects(double x, double y, double width, double height) Tests if the interior of thisRectangle2Dintersects the interior of a specified set of rectangular coordinates.booleanintersects(Rectangle2D rect) Tests if the interior of this shape intersects the interior of a specified rectangle.booleanisEmpty()Determines whether theRectangularShapeis empty.intoutcode(double x, double y) Determines where the specified coordinates lie with respect to thisRectangle2D.voidsetRect(double x, double y, double width, double height) Sets the location and size of thisRectangle2Dto the specified double values.voidSets thisRectangle2Dto be the same as the specifiedRectangle2D.toString()Returns theStringrepresentation of thisRectangle2D.Methods inherited from class Rectangle2D
add, equals, getBounds2D, getPathIterator, getPathIterator, hashCode, intersect, intersectsLine, intersectsLine, outcode, setFrame, unionMethods inherited from class RectangularShape
clone, contains, getBounds, getFrame, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
-
Field Details
-
INFINITY
An immutable instance of aRectangle2Dwith bounds extending toward infinities. ThegetMinX()andgetMinY()methods return alwaysDouble.NEGATIVE_INFINITY, while thegetMaxX()andgetMaxY()methods return alwaysDouble.POSITIVE_INFINITY. This rectangle can be used as argument in theXRectangle2Dconstructor for initializing a newXRectangle2Dto infinite bounds. -
xmin
protected double xminMinimal x coordinate. -
ymin
protected double yminMinimal y coordinate. -
xmax
protected double xmaxMaximal x coordinate. -
ymax
protected double ymaxMaximal y coordinate.
-
-
Constructor Details
-
XRectangle2D
public XRectangle2D()Construct a default rectangle. Initial coordinates are(0,0,0,0). -
XRectangle2D
public XRectangle2D(double x, double y, double width, double height) Construct a rectangle with the specified location and dimension. This constructor uses the same signature thanRectangle2Dfor consistency. -
XRectangle2D
Construct a rectangle with the same coordinates than the supplied rectangle.- Parameters:
rect- The rectangle, ornullin none (in which case this constructor is equivalents to the no-argument constructor). UseINFINITYfor initializing thisXRectangle2Dwith infinite bounds.
-
-
Method Details
-
createFromExtremums
Create a rectangle using maximal x and y values rather than width and height. This factory avoid the problem of NaN values when extremums are infinite numbers. -
isEmpty
public boolean isEmpty()Determines whether theRectangularShapeis empty. When theRectangularShapeis empty, it encloses no area.- Specified by:
isEmptyin classRectangularShape- Returns:
trueif theRectangularShapeis empty;falseotherwise.
-
getX
public double getX()Returns the X coordinate of the upper left corner of the framing rectangle indoubleprecision.- Specified by:
getXin classRectangularShape- Returns:
- the x coordinate of the upper left corner of the framing rectangle.
-
getY
public double getY()Returns the Y coordinate of the upper left corner of the framing rectangle indoubleprecision.- Specified by:
getYin classRectangularShape- Returns:
- the y coordinate of the upper left corner of the framing rectangle.
-
getWidth
public double getWidth()Returns the width of the framing rectangle indoubleprecision.- Specified by:
getWidthin classRectangularShape- Returns:
- the width of the framing rectangle.
-
getHeight
public double getHeight()Returns the height of the framing rectangle indoubleprecision.- Specified by:
getHeightin classRectangularShape- Returns:
- the height of the framing rectangle.
-
getMinX
public double getMinX()Returns the smallest X coordinate of the rectangle.- Overrides:
getMinXin classRectangularShape
-
getMinY
public double getMinY()Returns the smallest Y coordinate of the rectangle.- Overrides:
getMinYin classRectangularShape
-
getMaxX
public double getMaxX()Returns the largest X coordinate of the rectangle.- Overrides:
getMaxXin classRectangularShape
-
getMaxY
public double getMaxY()Returns the largest Y coordinate of the rectangle.- Overrides:
getMaxYin classRectangularShape
-
getCenterX
public double getCenterX()Returns the X coordinate of the center of the rectangle.- Overrides:
getCenterXin classRectangularShape
-
getCenterY
public double getCenterY()Returns the Y coordinate of the center of the rectangle.- Overrides:
getCenterYin classRectangularShape
-
setRect
public void setRect(double x, double y, double width, double height) Sets the location and size of thisRectangle2Dto the specified double values.- Specified by:
setRectin classRectangle2D- Parameters:
x- the x coordinates to which to set the location of the upper left corner of thisRectangle2Dy- the y coordinates to which to set the location of the upper left corner of thisRectangle2Dwidth- the value to use to set the width of thisRectangle2Dheight- the value to use to set the height of thisRectangle2D
-
setRect
Sets thisRectangle2Dto be the same as the specifiedRectangle2D.- Overrides:
setRectin classRectangle2D- Parameters:
r- the specifiedRectangle2D
-
intersects
public boolean intersects(double x, double y, double width, double height) Tests if the interior of thisRectangle2Dintersects the interior of a specified set of rectangular coordinates.- Specified by:
intersectsin interfaceShape- Overrides:
intersectsin classRectangle2D- Parameters:
x- the x coordinates of the upper left corner of the specified set of rectangular coordinatesy- the y coordinates of the upper left corner of the specified set of rectangular coordinateswidth- the width of the specified set of rectangular coordinatesheight- the height of the specified set of rectangular coordinates- Returns:
trueif thisRectangle2Dintersects the interior of a specified set of rectangular coordinates;falseotherwise.
-
intersects
Tests if the interior of this shape intersects the interior of a specified rectangle. This methods overrides the defaultRectangle2Dimplementation in order to work correctly with infinites and NaN values.- Specified by:
intersectsin interfaceShape- Overrides:
intersectsin classRectangularShape- Parameters:
rect- the specified rectangle.- Returns:
trueif this shape and the specified rectangle intersect each other.- See Also:
-
intersectInclusive
Tests if the interior and/or the edge of two rectangles intersect. This method is similar tointersects(Rectangle2D)except for the following points:- This method doesn't test only if the interiors intersect. It tests for the edges as well.
- This method tests also rectangle with zero width or
height (which are empty according
Shapecontract). However, rectangle with negative width or height are still considered as empty. - This method work correctly with infinites and NaN values.
- Parameters:
rect1- The first rectangle to test.rect2- The second rectangle to test.- Returns:
trueif the interior and/or the edge of the two specified rectangles intersects.
-
intersectInclusive
Tests if the interior of theShapeintersects the interior of a specified rectangle. This method might conservatively returntruewhen there is a high probability that the rectangle and the shape intersect, but the calculations to accurately determine this intersection are prohibitively expensive. This is similar toShape.intersects(Rectangle2D), except that this method tests also rectangle with zero width or height (which are empty accordingShapecontract). However, rectangle with negative width or height are still considered as empty.
This method is said inclusive because it try to mimicintersectInclusive(Rectangle2D, Rectangle2D)behavior, at least for rectangle with zero width or height.- Parameters:
shape- The shape.rect- The rectangle to test for inclusion.- Returns:
trueif the interior of the shape and the interior of the specified rectangle intersect, or are both highly likely to intersect.
-
equalsEpsilon
Returnstrueif the two rectangles are equals up to an epsilon value. -
contains
public boolean contains(double x, double y, double width, double height) Tests if the interior of thisRectangle2Dentirely contains the specified set of rectangular coordinates.- Specified by:
containsin interfaceShape- Overrides:
containsin classRectangle2D- Parameters:
x- the x coordinates of the upper left corner of the specified set of rectangular coordinatesy- the y coordinates of the upper left corner of the specified set of rectangular coordinateswidth- the width of the specified set of rectangular coordinatesheight- the height of the specified set of rectangular coordinates- Returns:
trueif thisRectangle2Dentirely contains specified set of rectangular coordinates;falseotherwise.
-
contains
Tests if the interior of this shape entirely contains the specified rectangle. This methods overrides the defaultRectangle2Dimplementation in order to work correctly with infinites and NaN values.- Specified by:
containsin interfaceShape- Overrides:
containsin classRectangularShape- Parameters:
rect- the specified rectangle.- Returns:
trueif this shape entirely contains the specified rectangle.
-
contains
public boolean contains(double x, double y) Tests if a specified coordinate is inside the boundary of thisRectangle2D.- Specified by:
containsin interfaceShape- Overrides:
containsin classRectangle2D- Parameters:
x- the x coordinates to test.y- the y coordinates to test.- Returns:
trueif the specified coordinates are inside the boundary of thisRectangle2D;falseotherwise.
-
containsInclusive
Tests if the interior of theinnerrectangle is contained in the interior and/or the edge of theoutterrectangle. This method is similar tocontains(Rectangle2D)except for the following points: This method is said inclusive because it tests bounds as closed interval rather then open interval (the default Java2D behavior). Usage of closed interval is required if at least one rectangle may be the bounding box of a perfectly horizontal or vertical line; such a bounding box has 0 width or height.- Parameters:
outter- The first rectangle to test.inner- The second rectangle to test.- Returns:
trueif the interior ofinneris inside the interior and/or the edge ofoutter.
-
outcode
public int outcode(double x, double y) Determines where the specified coordinates lie with respect to thisRectangle2D. This method computes a binary OR of the appropriate mask values indicating, for each side of thisRectangle2D, whether or not the specified coordinates are on the same side of the edge as the rest of thisRectangle2D.- Specified by:
outcodein classRectangle2D- Returns:
- the logical OR of all appropriate out codes.
- See Also:
-
createIntersection
Returns a newRectangle2Dobject representing the intersection of thisRectangle2Dwith the specifiedRectangle2D.- Specified by:
createIntersectionin classRectangle2D- Parameters:
rect- theRectangle2Dto be intersected with thisRectangle2D- Returns:
- the largest
Rectangle2Dcontained in both the specifiedRectangle2Dand in thisRectangle2D.
-
createUnion
Returns a newRectangle2Dobject representing the union of thisRectangle2Dwith the specifiedRectangle2D.- Specified by:
createUnionin classRectangle2D- Parameters:
rect- theRectangle2Dto be combined with thisRectangle2D- Returns:
- the smallest
Rectangle2Dcontaining both the specifiedRectangle2Dand thisRectangle2D.
-
add
public void add(double x, double y) Adds a point, specified by the double precision argumentsxandy, to thisRectangle2D. The resultingRectangle2Dis the smallestRectangle2Dthat contains both the originalRectangle2Dand the specified point.After adding a point, a call to
containswith the added point as an argument does not necessarily returntrue. Thecontainsmethod does not returntruefor points on the right or bottom edges of a rectangle. Therefore, if the added point falls on the left or bottom edge of the enlarged rectangle,containsreturnsfalsefor that point.- Overrides:
addin classRectangle2D
-
add
Adds aRectangle2Dobject to thisRectangle2D. The resultingRectangle2Dis the union of the twoRectangle2Dobjects.- Overrides:
addin classRectangle2D- Parameters:
rect- theRectangle2Dto add to thisRectangle2D.
-
toString
Returns theStringrepresentation of thisRectangle2D.
-