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)

public record Dimension2f(float width, float height) extends Record
An immutable 2-dimensional dimension using float coordinates.
  • Constructor Details

    • Dimension2f

      public Dimension2f(float width, float height)
      Constructor.
      Parameters:
      width - the width (>= 0)
      height - the height (>= 0)
  • Method Details

    • of

      public static Dimension2f of(float w, float h)
      Get instance.
      Parameters:
      w - the width
      h - the height
      Returns:
      instance with given width and height
    • scaled

      public Dimension2f scaled(Scale2f s)
      Scales the current Dimension2f object by the specified Scale2f object.
      Parameters:
      s - the Scale2f object representing the scaling factors for the x-axis and y-axis
      Returns:
      a new Dimension2f object with the scaled width and height
    • scaled

      public Dimension2f scaled(float s)
      Scales the dimension by a given factor.
      Parameters:
      s - the scaling factor.
      Returns:
      a new Dimension2f object with the scaled width and height.
    • addMargin

      public Dimension2f addMargin(float m)
      Returns a new Dimension2f 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

      public Dimension2f addMargin(float mx, float my)
      Adds a margin to the current width and height with separate margins for each direction.
      Parameters:
      mx - the margin to be added to the width
      my - the margin to be added to the height
      Returns:
      a new Dimension2f object with the adjusted width and height
    • max

      public static Dimension2f max(Dimension2f a, Dimension2f b)
      Computes the maximum of two Dimension2f objects based on their width and height.
      Parameters:
      a - the first Dimension2f object
      b - the second Dimension2f object
      Returns:
      a new Dimension2f object with the maximum width and height values from the two input dimensions
    • min

      public static Dimension2f min(Dimension2f a, Dimension2f b)
      Computes the minimum of two Dimension2f objects based on their dimensions. The resulting Dimension2f has the lesser width of the two input dimensions and the greater height of the two input dimensions.
      Parameters:
      a - the first Dimension2f object
      b - the second Dimension2f object
      Returns:
      a new Dimension2f object with the minimum width and maximum height from the two input dimensions
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • width

      public float width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public float height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component