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 newDimension2f
object 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 boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.float
height()
Returns the value of theheight
record component.static Dimension2f
max
(Dimension2f a, Dimension2f b) Computes the maximum of twoDimension2f
objects based on their width and height.static Dimension2f
min
(Dimension2f a, Dimension2f b) Computes the minimum of twoDimension2f
objects based on their dimensions.static Dimension2f
of
(float w, float h) Get instance.scaled
(float s) Scales the dimension by a given factor.Scales the currentDimension2f
object by the specifiedScale2f
object.final String
toString()
Returns a string representation of this record class.float
width()
Returns the value of thewidth
record 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 currentDimension2f
object by the specifiedScale2f
object.- Parameters:
s
- theScale2f
object representing the scaling factors for the x-axis and y-axis- Returns:
- a new
Dimension2f
object with the scaled width and height
-
scaled
Scales the dimension by a given factor.- Parameters:
s
- the scaling factor.- Returns:
- a new
Dimension2f
object with the scaled width and height.
-
addMargin
Returns a newDimension2f
object 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
Dimension2f
object 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
Dimension2f
object with the adjusted width and height
-
max
Computes the maximum of twoDimension2f
objects based on their width and height.- Parameters:
a
- the firstDimension2f
objectb
- the secondDimension2f
object- Returns:
- a new
Dimension2f
object with the maximum width and height values from the two input dimensions
-
min
Computes the minimum of twoDimension2f
objects based on their dimensions. The resultingDimension2f
has the lesser width of the two input dimensions and the greater height of the two input dimensions.- Parameters:
a
- the firstDimension2f
objectb
- the secondDimension2f
object- Returns:
- a new
Dimension2f
object 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 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
-