Record Class Rect
java.lang.Object
java.lang.Record
org.inspirenxe.strata.api.geometry.Rect
- Record Components:
x- the left edgey- the top edgewidth- the width; zero if negative or NaNheight- the height; zero if negative or NaN
An axis-aligned rectangle in UI units.
Width and height are never negative: the constructor clamps a negative size to zero, so shrinking a rectangle
by more than its size yields an empty rectangle at the shrunk position instead of an inverted one. A rectangle
covers the half-open range [x, x + width) by [y, y + height).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRect(float x, float y, float width, float height) Creates a rectangle, making a negative or NaN width or height zero. -
Method Summary
Modifier and TypeMethodDescriptionfloatbottom()Returns the bottom edge,y + height.booleancontains(float px, float py) Returns whether a point lies inside the rectangle.final booleanIndicates whether some other object is "equal to" this one.Moves each edge outward by the matching inset.final inthashCode()Returns a hash code value for this object.floatheight()Returns the value of theheightrecord component.Returns the overlap of two rectangles.booleanintersects(Rect other) Returns whether two rectangles overlap.booleanisEmpty()Returns whether the rectangle covers no area.static RectofEdges(float left, float top, float right, float bottom) Creates a rectangle from its edges.floatright()Returns the right edge,x + width.Moves each edge inward by the matching inset.final StringtoString()Returns a string representation of this record class.translate(float dx, float dy) Returns the same rectangle moved by an offset.floatwidth()Returns the value of thewidthrecord component.floatx()Returns the value of thexrecord component.floaty()Returns the value of theyrecord component.
-
Field Details
-
ZERO
The empty rectangle at the origin.
-
-
Constructor Details
-
Rect
public Rect(float x, float y, float width, float height) Creates a rectangle, making a negative or NaN width or height zero.
-
-
Method Details
-
ofEdges
Creates a rectangle from its edges.- Parameters:
left- the left edgetop- the top edgeright- the right edge; a value left ofleftgives zero widthbottom- the bottom edge; a value abovetopgives zero height- Returns:
- the rectangle between the edges
-
right
public float right()Returns the right edge,x + width. The edge itself is outside the rectangle.- Returns:
- the right edge
-
bottom
public float bottom()Returns the bottom edge,y + height. The edge itself is outside the rectangle.- Returns:
- the bottom edge
-
isEmpty
public boolean isEmpty()Returns whether the rectangle covers no area.- Returns:
- true if the width or the height is zero
-
contains
public boolean contains(float px, float py) Returns whether a point lies inside the rectangle. The left and top edges are inside; the right and bottom edges are outside, so two rectangles that share an edge never both contain a point on it.- Parameters:
px- the point's xpy- the point's y- Returns:
- true if the point is inside
-
shrink
-
grow
Moves each edge outward by the matching inset. The inverse ofshrink(Insets)for rectangles large enough not to be clamped.- Parameters:
insets- how far to move each edge- Returns:
- the larger rectangle
-
translate
Returns the same rectangle moved by an offset.- Parameters:
dx- the horizontal offsetdy- the vertical offset- Returns:
- the moved rectangle
-
intersect
-
intersects
Returns whether two rectangles overlap. Rectangles that only share an edge do not, and an empty rectangle overlaps nothing, since it has no area.- Parameters:
other- the other rectangle- Returns:
- true if some area lies inside both
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
x
-
y
-
width
-
height
-