Package nl.colorize.multimedialib.math
Record Class Rect
java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Rect
- All Implemented Interfaces:
Shape
Two-dimensional rectangle with coordinates defined with float precision.
Rectangles are specified using their top-left coordinate, width, and
height. Methods are provided for obtaining the rectangle's X1 and Y1
coordinates and its center.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRect
(float x, float y, float width, float height) Creates an instance of aRect
record class. -
Method Summary
Modifier and TypeMethodDescriptionstatic Rect
around
(float x, float y, float width, float height) Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.static Rect
Returns a rectangle that has X and Y coordinates so that the specified point becomes its center.boolean
contains
(float px, float py) boolean
Returns whether this shape contains the specified point.boolean
final boolean
Indicates whether some other object is "equal to" this one.static Rect
fromPoints
(float x0, float y0, float x1, float y1) Created a rectangle from 4 points (x0, y0, x1, y1) instead of requiring its width and height.Returns the smallest possible rectangular bounding box that can fit this shape.float
float
float
getEndX()
float
getEndY()
final int
hashCode()
Returns a hash code value for this object.float
height()
Returns the value of theheight
record component.boolean
intersects
(Rect r) reposition
(Point2D offset) Returns a newShape
instance that is repositioned by the specified X and Y offset.toString()
Returns a string representation of this record class.float
width()
Returns the value of thewidth
record component.float
x()
Returns the value of thex
record component.float
y()
Returns the value of they
record component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface nl.colorize.multimedialib.math.Shape
reposition
-
Constructor Details
-
Rect
public Rect(float x, float y, float width, float height) Creates an instance of aRect
record class.- Parameters:
x
- the value for thex
record componenty
- the value for they
record componentwidth
- the value for thewidth
record componentheight
- the value for theheight
record component
-
-
Method Details
-
getEndX
public float getEndX() -
getEndY
public float getEndY() -
getCenterX
public float getCenterX() -
getCenterY
public float getCenterY() -
getCenter
-
contains
Description copied from interface:Shape
Returns whether this shape contains the specified point. -
contains
public boolean contains(float px, float py) -
contains
-
intersects
-
getBoundingBox
Description copied from interface:Shape
Returns the smallest possible rectangular bounding box that can fit this shape.- Specified by:
getBoundingBox
in interfaceShape
-
reposition
Description copied from interface:Shape
Returns a newShape
instance that is repositioned by the specified X and Y offset.- Specified by:
reposition
in interfaceShape
-
toPolygon
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
fromPoints
Created a rectangle from 4 points (x0, y0, x1, y1) instead of requiring its width and height. -
around
Returns a rectangle that has X and Y coordinates so that the specified point becomes its center. -
around
Returns a rectangle that has X and Y coordinates so that the specified point becomes its center. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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 '=='. -
x
public float x()Returns the value of thex
record component.- Returns:
- the value of the
x
record component
-
y
public float y()Returns the value of they
record component.- Returns:
- the value of the
y
record component
-
width
public float width()Returns the value of thewidth
record component.- Returns:
- the value of the
width
record component
-
height
public float height()Returns the value of theheight
record component.- Returns:
- the value of the
height
record component
-