Package com.adobe.xfa.ut
Class Rect
- java.lang.Object
-
- com.adobe.xfa.ut.Rect
-
public final class Rect extends java.lang.Object
A class to describe a rectangle. It consists of left, top, right, and, bottom extents.Instances of this class are immutable. All change operations return a new instance of this
Rect
class.
-
-
Constructor Summary
Constructors Constructor Description Rect()
Instantiates aRect
of zero extents.Rect(CoordPair topLeft, CoordPair bottomRight)
Instantiates aRect
specified by the givenCoordPair
.Rect(Rect source)
Deprecated.Rect is immutable, so there is no need to copy an instance.Rect(UnitSpan left, UnitSpan top, UnitSpan right, UnitSpan bottom)
Instantiates aRect
specified by the givenUnitSpan
extents.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Rect
add(CoordPair add)
Returns aRect
representing the shift of this object by the givenCoordPair
.UnitSpan
bottom()
Gets this object's bottommost extent.Rect
bottomHeight(UnitSpan newBottom, UnitSpan newHeight)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.CoordPair
bottomLeft()
Gets this object's bottom left coordinate.Rect
bottomLeft(CoordPair newBottomLeft)
Returns aRect
representing the extention of this object using the given bottom leftCoordPair
.CoordPair
bottomRight()
Gets this object's bottom right coordinate.Rect
bottomRight(CoordPair newBottomRight)
Returns aRect
representing the extention of this object using the given bottom rightCoordPair
.CoordPair
centre()
Gets this object's centre coordinate.Rect
changeUnits(int eNewUnits)
Returns aRect
representing the change of this object's unit span units to the given unit code.boolean
contains(CoordPair point)
Determines if this object contains the givenCoordPair
.boolean
contains(Rect rect)
Determines if this object contains the givenRect
.boolean
disjoint(Rect rect)
Determines if this object is disjoint from the givenRect
.boolean
equals(java.lang.Object object)
Determines if this object is equal to the givenObject
.int
hashCode()
UnitSpan
height()
Gets this object's height.Rect
height(UnitSpan newHeight, boolean bStretchTop)
Returns aRect
representing the stretch in height of this object by the givenUnitSpan
.Rect
intersection(Rect intersect)
Returns aRect
representing the intersection of this object with the givenRect
.boolean
isDegenerate()
Determines if this object is degenerate.UnitSpan
left()
Gets this object's leftmost extent.Rect
leftRight(UnitSpan newLeft, UnitSpan newRight)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents.Rect
leftWidth(UnitSpan newLeft, UnitSpan newWidth)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents.boolean
notEquals(java.lang.Object compare)
Determines if this object is not equal to the givenObject
.boolean
overlaps(Rect rect)
Determines if this object overlaps the givenRect
.UnitSpan
right()
Gets this object's rightmost extent.Rect
rightWidth(UnitSpan newRight, UnitSpan newWidth)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents.Rect
rotate(CoordPair point, Angle angle)
Returns aRect
representing the rotation of this object about the givenCoordPair
andAngle
of rotation.Rect
subtract(CoordPair subtract)
Returns aRect
representing the shift of this object and the givenCoordPair
.UnitSpan
top()
Gets this object's topmost extent.Rect
topBottom(UnitSpan newTop, UnitSpan newBottom)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.Rect
topHeight(UnitSpan newTop, UnitSpan newHeight)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.CoordPair
topLeft()
Gets this object's top left coordinate.Rect
topLeft(CoordPair newTopLeft)
Returns aRect
representing the extention of this object using the given top leftCoordPair
.CoordPair
topRight()
Gets this object's top right coordinate.Rect
topRight(CoordPair newTopRight)
Returns aRect
representing the extention of this object using the given top rightCoordPair
.Rect
union(Rect union)
Returns aRect
representing the union of this object with the givenRect
.UnitSpan
width()
Gets this object's width.Rect
width(UnitSpan newWidth, boolean bStretchLeft)
Returns aRect
representing the stretch in width of this object by the givenUnitSpan
.static Rect
zero()
The zero rectangle.
-
-
-
Field Detail
-
ZERO
public static final Rect ZERO
-
-
Constructor Detail
-
Rect
public Rect()
Instantiates aRect
of zero extents.
-
Rect
public Rect(Rect source)
Deprecated.Rect is immutable, so there is no need to copy an instance.Instantiates aRect
from the givenRect
.- Parameters:
source
- theRect
to copy to this object.
-
Rect
public Rect(CoordPair topLeft, CoordPair bottomRight)
Instantiates aRect
specified by the givenCoordPair
.- Parameters:
topLeft
- the top left coordinate of the rectangle.bottomRight
- the bottom right coordinate of the rectangle.
-
Rect
public Rect(UnitSpan left, UnitSpan top, UnitSpan right, UnitSpan bottom)
Instantiates aRect
specified by the givenUnitSpan
extents. The rectangle's extents are normalized such that:- the leftmost extent is set to
min(oLeft, oRight)
, - the rightmost extent is set to
max(oLeft, oRight)
, - the topmost extent is set to
min(oTop, oBottom)
, - the bottommost extent is set to
max(oTop, oBottom)
, - the width is set to
|oLeft - oRight|
, and, - the height is set to
|oTop - oBottom|
.
- Parameters:
left
- the left extent of the rectangle.top
- the top extent of the rectangle.right
- the right extent of the rectangle.bottom
- the bottom extent of the rectangle.
- the leftmost extent is set to
-
-
Method Detail
-
left
public UnitSpan left()
Gets this object's leftmost extent.- Returns:
- the leftmost extent.
-
top
public UnitSpan top()
Gets this object's topmost extent.- Returns:
- the topmost extent.
-
right
public UnitSpan right()
Gets this object's rightmost extent.- Returns:
- the rightmost extent.
-
bottom
public UnitSpan bottom()
Gets this object's bottommost extent.- Returns:
- the bottommost extent.
-
leftRight
public Rect leftRight(UnitSpan newLeft, UnitSpan newRight)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents. The left/right extends are normalized.- Parameters:
newLeft
- the new left extent.newRight
- the new right extent.- Returns:
- a rectangle of the changed width.
-
topBottom
public Rect topBottom(UnitSpan newTop, UnitSpan newBottom)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.- Parameters:
newTop
- the new left extent.newBottom
- the new bottom extent.- Returns:
- a rectangle of the changed height.
-
leftWidth
public Rect leftWidth(UnitSpan newLeft, UnitSpan newWidth)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents.- Parameters:
newLeft
- the new left extent.newWidth
- the new width.- Returns:
- a rectangle of the changed width.
-
rightWidth
public Rect rightWidth(UnitSpan newRight, UnitSpan newWidth)
Returns aRect
representing the change in width of this object by the givenUnitSpan
extents.- Parameters:
newRight
- the new right extent.newWidth
- the new width.- Returns:
- a rectangle of the changed width.
-
topHeight
public Rect topHeight(UnitSpan newTop, UnitSpan newHeight)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.- Parameters:
newTop
- the new top extent.newHeight
- the new height.- Returns:
- a rectangle of the changed height.
-
bottomHeight
public Rect bottomHeight(UnitSpan newBottom, UnitSpan newHeight)
Returns aRect
representing the change in height of this object by the givenUnitSpan
extents.- Parameters:
newBottom
- the new bottom extent.newHeight
- the new height.- Returns:
- a rectangle of the changed height.
-
topLeft
public CoordPair topLeft()
Gets this object's top left coordinate.- Returns:
- the top left coordinate.
-
topRight
public CoordPair topRight()
Gets this object's top right coordinate.- Returns:
- the top right coordinate.
-
bottomLeft
public CoordPair bottomLeft()
Gets this object's bottom left coordinate.- Returns:
- the bottom left coordinate.
-
bottomRight
public CoordPair bottomRight()
Gets this object's bottom right coordinate.- Returns:
- the bottom right coordinate.
-
changeUnits
public Rect changeUnits(int eNewUnits)
Returns aRect
representing the change of this object's unit span units to the given unit code.- Parameters:
eNewUnits
- the new unit code.- Returns:
- a rectangle of the change.
-
topLeft
public Rect topLeft(CoordPair newTopLeft)
Returns aRect
representing the extention of this object using the given top leftCoordPair
.- Parameters:
newTopLeft
- the new top left coordinate.- Returns:
- a rectangle of the extention.
-
topRight
public Rect topRight(CoordPair newTopRight)
Returns aRect
representing the extention of this object using the given top rightCoordPair
.- Parameters:
newTopRight
- the new top right coordinate.- Returns:
- a rectangle of the extention.
-
bottomLeft
public Rect bottomLeft(CoordPair newBottomLeft)
Returns aRect
representing the extention of this object using the given bottom leftCoordPair
.- Parameters:
newBottomLeft
- the new bottom left coordinate.- Returns:
- a rectangle of the extention.
-
bottomRight
public Rect bottomRight(CoordPair newBottomRight)
Returns aRect
representing the extention of this object using the given bottom rightCoordPair
.- Parameters:
newBottomRight
- the new bottom right coordinate.- Returns:
- a rectangle of the extention.
-
height
public UnitSpan height()
Gets this object's height.- Returns:
- the height.
-
width
public UnitSpan width()
Gets this object's width.- Returns:
- the width.
-
height
public Rect height(UnitSpan newHeight, boolean bStretchTop)
Returns aRect
representing the stretch in height of this object by the givenUnitSpan
.- Parameters:
newHeight
- the new height.bStretchTop
- stretch from the top when set; stretch from the bottom when not set.- Returns:
- a rectangle of the stretched height.
-
width
public Rect width(UnitSpan newWidth, boolean bStretchLeft)
Returns aRect
representing the stretch in width of this object by the givenUnitSpan
.- Parameters:
newWidth
- the new width.bStretchLeft
- stretch from the left when set; stretch from the right when not set.- Returns:
- a rectangle of the stretched width.
-
centre
public CoordPair centre()
Gets this object's centre coordinate.- Returns:
- the center of the rectangle.
-
contains
public boolean contains(CoordPair point)
Determines if this object contains the givenCoordPair
.- Parameters:
point
- a coordinate.- Returns:
- true if the coordinate is contained, false otherwise
-
contains
public boolean contains(Rect rect)
Determines if this object contains the givenRect
.- Parameters:
rect
- a rectangle.- Returns:
- true if given the rectangle is contained, false otherwise
-
overlaps
public boolean overlaps(Rect rect)
Determines if this object overlaps the givenRect
.- Parameters:
rect
- a rectangle.- Returns:
- true if the rectangle overlaps, false otherwise
-
disjoint
public boolean disjoint(Rect rect)
Determines if this object is disjoint from the givenRect
. This is slightly different than the result of! overlaps()
in that, if the rectangles share an edge, this will return true.- Parameters:
rect
- a rectangle.- Returns:
- true if the rectangle is disjoint, false otherwise
- See Also:
overlaps(Rect)
-
isDegenerate
public boolean isDegenerate()
Determines if this object is degenerate. Only the zero rectangle is degenerate.- Returns:
- true if this rectangle is degenerate, false otherwise
- See Also:
zero()
-
rotate
public Rect rotate(CoordPair point, Angle angle)
Returns aRect
representing the rotation of this object about the givenCoordPair
andAngle
of rotation.- Parameters:
point
- the point of rotation.angle
- the angle of rotation.- Returns:
- a rectangle of the rotation.
-
equals
public boolean equals(java.lang.Object object)
Determines if this object is equal to the givenObject
. Comparisons with instances of non-Rect
objects are never equal.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- theObject
to compare.- Returns:
- true if equal, false otherwise.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
notEquals
public boolean notEquals(java.lang.Object compare)
Determines if this object is not equal to the givenObject
. Comparisons with instances of non-Rect
objects are always not equal.- Parameters:
compare
- theObject
to compare.- Returns:
- true if not equal, false otherwise
-
add
public Rect add(CoordPair add)
Returns aRect
representing the shift of this object by the givenCoordPair
.- Parameters:
add
- theCoordPair
to add.- Returns:
- a rectangle of the shift.
-
subtract
public Rect subtract(CoordPair subtract)
Returns aRect
representing the shift of this object and the givenCoordPair
.- Parameters:
subtract
- theCoordPair
to subtract.- Returns:
- a rectangle of the shift.
-
union
public Rect union(Rect union)
Returns aRect
representing the union of this object with the givenRect
.- Parameters:
union
- theRect
to unite with.- Returns:
- a rectangle of the union.
-
intersection
public Rect intersection(Rect intersect)
Returns aRect
representing the intersection of this object with the givenRect
.- Parameters:
intersect
- theRect
to intersect with.- Returns:
- a rectangle of the intersection.
-
zero
public static Rect zero()
The zero rectangle.- Returns:
- the rectangle equal to zero.
-
-