Package com.dua3.utility.math.geometry
Record Class Dimension2f
java.lang.Object
java.lang.Record
com.dua3.utility.math.geometry.Dimension2f
- Record Components:
width- the width (>= 0)height- the height (>= 0)
An immutable 2-dimensional dimension using float coordinates.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddMargin(float m) Returns a newDimension2fobject with a margin added to both width and height.addMargin(float mx, float my) Adds a margin to the current width and height with separate margins for each direction.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.floatheight()Returns the value of theheightrecord component.static Dimension2fmax(Dimension2f a, Dimension2f b) Computes the maximum of twoDimension2fobjects based on their width and height.static Dimension2fmin(Dimension2f a, Dimension2f b) Computes the minimum of twoDimension2fobjects based on their dimensions.static Dimension2fof(float w, float h) Get instance.scaled(float s) Scales the dimension by a given factor.Scales the currentDimension2fobject by the specifiedScale2fobject.final StringtoString()Returns a string representation of this record class.floatwidth()Returns the value of thewidthrecord component.
-
Constructor Details
-
Dimension2f
public Dimension2f(float width, float height) Constructor.- Parameters:
width- the width (>= 0)height- the height (>= 0)
-
-
Method Details
-
of
Get instance.- Parameters:
w- the widthh- the height- Returns:
- instance with given width and height
-
scaled
Scales the currentDimension2fobject by the specifiedScale2fobject.- Parameters:
s- theScale2fobject representing the scaling factors for the x-axis and y-axis- Returns:
- a new
Dimension2fobject with the scaled width and height
-
scaled
Scales the dimension by a given factor.- Parameters:
s- the scaling factor.- Returns:
- a new
Dimension2fobject with the scaled width and height.
-
addMargin
Returns a newDimension2fobject with a margin added to both width and height. The margin is added equally on both sides, effectively increasing the width and height by double the provided margin value.- Parameters:
m- the margin to be added to the width and height- Returns:
- a new
Dimension2fobject with updated dimensions
-
addMargin
Adds a margin to the current width and height with separate margins for each direction.- Parameters:
mx- the margin to be added to the widthmy- the margin to be added to the height- Returns:
- a new
Dimension2fobject with the adjusted width and height
-
max
Computes the maximum of twoDimension2fobjects based on their width and height.- Parameters:
a- the firstDimension2fobjectb- the secondDimension2fobject- Returns:
- a new
Dimension2fobject with the maximum width and height values from the two input dimensions
-
min
Computes the minimum of twoDimension2fobjects based on their dimensions. The resultingDimension2fhas the lesser width of the two input dimensions and the greater height of the two input dimensions.- Parameters:
a- the firstDimension2fobjectb- the secondDimension2fobject- Returns:
- a new
Dimension2fobject with the minimum width and maximum height from the two input dimensions
-
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. -
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 '=='. -
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
-