Package nl.colorize.multimedialib.math
Record Class Rect
java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Rect
- All Implemented Interfaces:
Shape
Immutable two-dimensional rectangle with float precision. Rectangles are
specified using their top-left coordinate, width, and height. The
rectangle's location permits negative coordinates, but its width
and height cannot be negative.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRect(float x, float y, float width, float height) Creates an instance of aRectrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic Rectaround(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 RectReturns a rectangle that has X and Y coordinates so that the specified point becomes its center.static RectaroundOrigin(float width, float height) Returns a rectangle that has the specified width and height, with its X and Y coordinates positioned so that the origin(0, 0)ends up as the center of the rectangle.Returns a new rectangle that encompasses both this rectangle and the specified other rectangle.booleancontains(float px, float py) Returns true if the specified point is located within this rectangle.booleanReturns true if the specified point is located within this rectangle.booleanReturns true if the specified other rectangle is entirely or partially located within this rectangle.final booleanIndicates whether some other object is "equal to" this one.expand(float amount) Expands this rectangle by the specified amount, and returns the resulting new rectangle.static RectfromPoints(float x0, float y0, float x1, float y1) Factory method that creates a rectangle based on the points (x0, y0) and (x1, y1).Returns the smallest possible rectangular bounding box that can fit this shape.floatfloatfloatgetEndX()floatgetEndY()final inthashCode()Returns a hash code value for this object.floatheight()Returns the value of theheightrecord component.booleanintersects(Rect other) Returns true if the specified other retangle intersects with this rectangle.reposition(Point2D offset) Returns a newShapeinstance that is repositioned by the specified offset.toString()Returns a string representation of this record class.floatwidth()Returns the value of thewidthrecord component.floatx()Returns the value of thexrecord component.floaty()Returns the value of theyrecord component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 aRectrecord class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord componentwidth- the value for thewidthrecord componentheight- the value for theheightrecord component
-
-
Method Details
-
getEndX
public float getEndX() -
getEndY
public float getEndY() -
getCenterX
public float getCenterX() -
getCenterY
public float getCenterY() -
getCenter
-
contains
Returns true if the specified point is located within this rectangle. -
contains
public boolean contains(float px, float py) Returns true if the specified point is located within this rectangle. -
contains
Returns true if the specified other rectangle is entirely or partially located within this rectangle. -
intersects
Returns true if the specified other retangle intersects with this rectangle. -
combine
Returns a new rectangle that encompasses both this rectangle and the specified other rectangle. -
getBoundingBox
Description copied from interface:ShapeReturns the smallest possible rectangular bounding box that can fit this shape.- Specified by:
getBoundingBoxin interfaceShape
-
reposition
Description copied from interface:ShapeReturns a newShapeinstance that is repositioned by the specified offset.- Specified by:
repositionin interfaceShape
-
expand
Expands this rectangle by the specified amount, and returns the resulting new rectangle. The rectangle is expanded around its center, i.e.r.getCenter().equals(r.expand(...).getCenter()). Using a negative value foramountis possible and will result in a rectangle that is smaller than the original. -
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
Factory method that creates a rectangle based on the points (x0, y0) and (x1, y1). -
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. -
aroundOrigin
Returns a rectangle that has the specified width and height, with its X and Y coordinates positioned so that the origin(0, 0)ends up as the center of the rectangle. -
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 thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public float y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-
width
public float width()Returns the value of thewidthrecord component.- Returns:
- the value of the
widthrecord component
-
height
public float height()Returns the value of theheightrecord component.- Returns:
- the value of the
heightrecord component
-