Class RectF
java.lang.Object
com.compdfkit.core.android.graphics.RectF
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal floatcenterX()final floatcenterY()booleancontains(float x, float y) Returns true if (x,y) is inside the rectangle.booleancontains(float left, float top, float right, float bottom) Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle.booleanReturns true iff the specified rectangle r is inside or equal to this rectangle.booleaninthashCode()final floatheight()voidinset(float dx, float dy) Inset the rectangle by (dx,dy).booleanintersect(float left, float top, float right, float bottom) If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.booleanIf the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.booleanintersects(float left, float top, float right, float bottom) Returns true if this rectangle intersects the specified rectangle.static booleanintersects(RectF a, RectF b) Returns true iff the two specified rectangles intersect.final booleanisEmpty()Returns true if the rectangle is empty (left >= right or top >= bottom)voidoffset(float dx, float dy) Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.voidoffsetTo(float newLeft, float newTop) Offset the rectangle to a specific (left, top) position, keeping its width and height the same.voidPrint short representation to given writer.voidscale(float scale) Scales up the rect by the given scale.voidset(float left, float top, float right, float bottom) Set the rectangle's coordinates to the specified values.voidCopy the coordinates from src into this rectangle.voidsetEmpty()Set the rectangle to (0,0,0,0)booleansetIntersect(RectF a, RectF b) If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.voidsort()Swap top/bottom or left/right if there are flipped (i.e.Return a string representation of the rectangle in a compact form.Return a string representation of the rectangle in a compact form.toString()voidunion(float x, float y) Update this Rect to enclose itself and the [x,y] coordinate.voidunion(float left, float top, float right, float bottom) Update this Rect to enclose itself and the specified rectangle.voidUpdate this Rect to enclose itself and the specified rectangle.final floatwidth()
-
Field Details
-
left
public float left -
top
public float top -
right
public float right -
bottom
public float bottom
-
-
Constructor Details
-
RectF
public RectF()Create a new empty RectF. All coordinates are initialized to 0. -
RectF
public RectF(float left, float top, float right, float bottom) Create a new rectangle with the specified coordinates. Note: no range checking is performed, so the caller must ensure that left <= right and top <= bottom.- Parameters:
left- The X coordinate of the left side of the rectangletop- The Y coordinate of the top of the rectangleright- The X coordinate of the right side of the rectanglebottom- The Y coordinate of the bottom of the rectangle
-
RectF
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).- Parameters:
r- The rectangle whose coordinates are copied into the new rectangle.
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
toString
-
toShortString
Return a string representation of the rectangle in a compact form. -
toShortString
Return a string representation of the rectangle in a compact form. -
printShortString
Print short representation to given writer. -
isEmpty
public final boolean isEmpty()Returns true if the rectangle is empty (left >= right or top >= bottom) -
width
public final float width()- Returns:
- the rectangle's width. This does not check for a valid rectangle (i.e. left <= right) so the result may be negative.
-
height
public final float height()- Returns:
- the rectangle's height. This does not check for a valid rectangle (i.e. top <= bottom) so the result may be negative.
-
centerX
public final float centerX()- Returns:
- the horizontal center of the rectangle. This does not check for a valid rectangle (i.e. left <= right)
-
centerY
public final float centerY()- Returns:
- the vertical center of the rectangle. This does not check for a valid rectangle (i.e. top <= bottom)
-
setEmpty
public void setEmpty()Set the rectangle to (0,0,0,0) -
set
public void set(float left, float top, float right, float bottom) Set the rectangle's coordinates to the specified values. Note: no range checking is performed, so it is up to the caller to ensure that left <= right and top <= bottom.- Parameters:
left- The X coordinate of the left side of the rectangletop- The Y coordinate of the top of the rectangleright- The X coordinate of the right side of the rectanglebottom- The Y coordinate of the bottom of the rectangle
-
set
Copy the coordinates from src into this rectangle.- Parameters:
src- The rectangle whose coordinates are copied into this rectangle.
-
offset
public void offset(float dx, float dy) Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.- Parameters:
dx- The amount to add to the rectangle's left and right coordinatesdy- The amount to add to the rectangle's top and bottom coordinates
-
offsetTo
public void offsetTo(float newLeft, float newTop) Offset the rectangle to a specific (left, top) position, keeping its width and height the same.- Parameters:
newLeft- The new "left" coordinate for the rectanglenewTop- The new "top" coordinate for the rectangle
-
inset
public void inset(float dx, float dy) Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards, making the rectangle narrower. If dx is negative, then the sides are moved outwards, making the rectangle wider. The same holds true for dy and the top and bottom.- Parameters:
dx- The amount to add(subtract) from the rectangle's left(right)dy- The amount to add(subtract) from the rectangle's top(bottom)
-
contains
public boolean contains(float x, float y) Returns true if (x,y) is inside the rectangle. The left and top are considered to be inside, while the right and bottom are not. This means that for a x,y to be contained: left <= x < right and top <= y < bottom. An empty rectangle never contains any point.- Parameters:
x- The X coordinate of the point being tested for containmenty- The Y coordinate of the point being tested for containment- Returns:
- true iff (x,y) are contained by the rectangle, where containment means left <= x < right and top <= y < bottom
-
contains
public boolean contains(float left, float top, float right, float bottom) Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle. i.e. is this rectangle a superset of the specified rectangle. An empty rectangle never contains another rectangle.- Parameters:
left- The left side of the rectangle being tested for containmenttop- The top of the rectangle being tested for containmentright- The right side of the rectangle being tested for containmentbottom- The bottom of the rectangle being tested for containment- Returns:
- true iff the the 4 specified sides of a rectangle are inside or equal to this rectangle
-
contains
Returns true iff the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle.- Parameters:
r- The rectangle being tested for containment.- Returns:
- true iff the specified rectangle r is inside or equal to this rectangle
-
intersect
public boolean intersect(float left, float top, float right, float bottom) If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. No check is performed to see if either rectangle is empty. Note: To just test for intersection, use intersects()- Parameters:
left- The left side of the rectangle being intersected with this rectangletop- The top of the rectangle being intersected with this rectangleright- The right side of the rectangle being intersected with this rectangle.bottom- The bottom of the rectangle being intersected with this rectangle.- Returns:
- true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle.
-
intersect
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. No check is performed to see if either rectangle is empty. To just test for intersection, use intersects()- Parameters:
r- The rectangle being intersected with this rectangle.- Returns:
- true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle.
-
setIntersect
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. No check is performed to see if either rectangle is empty. To just test for intersection, use intersects()- Parameters:
a- The first rectangle being intersected withb- The second rectangle being intersected with- Returns:
- true iff the two specified rectangles intersect. If they do, set this rectangle to that intersection. If they do not, return false and do not change this rectangle.
-
intersects
public boolean intersects(float left, float top, float right, float bottom) Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. No check is performed to see if either rectangle is empty. To record the intersection, use intersect() or setIntersect().- Parameters:
left- The left side of the rectangle being tested for intersectiontop- The top of the rectangle being tested for intersectionright- The right side of the rectangle being tested for intersectionbottom- The bottom of the rectangle being tested for intersection- Returns:
- true iff the specified rectangle intersects this rectangle. In no event is this rectangle modified.
-
intersects
Returns true iff the two specified rectangles intersect. In no event are either of the rectangles modified. To record the intersection, use intersect() or setIntersect().- Parameters:
a- The first rectangle being tested for intersectionb- The second rectangle being tested for intersection- Returns:
- true iff the two specified rectangles intersect. In no event are either of the rectangles modified.
-
union
public void union(float left, float top, float right, float bottom) Update this Rect to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.- Parameters:
left- The left edge being unioned with this rectangletop- The top edge being unioned with this rectangleright- The right edge being unioned with this rectanglebottom- The bottom edge being unioned with this rectangle
-
union
Update this Rect to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.- Parameters:
r- The rectangle being unioned with this rectangle
-
union
public void union(float x, float y) Update this Rect to enclose itself and the [x,y] coordinate. There is no check to see that this rectangle is non-empty.- Parameters:
x- The x coordinate of the point to add to the rectangley- The y coordinate of the point to add to the rectangle
-
sort
public void sort()Swap top/bottom or left/right if there are flipped (i.e. left > right and/or top > bottom). This can be called if the edges are computed separately, and may have crossed over each other. If the edges are already correct (i.e. left <= right and top <= bottom) then nothing is done. -
scale
public void scale(float scale) Scales up the rect by the given scale.
-