Class UDim2

java.lang.Object
com.thecsdev.common.math.UDim2

public final class UDim2 extends Object
Represents a two-dimensional scalable value with independent scaling for each axis.

This structure extends UDim to two dimensions, allowing values to be defined using:

  • x - The horizontal component.
  • y - The vertical component.
Each axis is defined using a UDim, meaning it consists of both a relative scale and an absolute offset. This is useful for 2D UI layouts, positioning, or procedural generation where values need to be both scalable and adjustable.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final UDim
    The horizontal component of the scalable value.
    final UDim
    The vertical component of the scalable value.
    static final UDim2
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    UDim2(double xScale, double xOffset, double yScale, double yOffset)
     
    UDim2(UDim x, UDim y)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final UDim2
     
    final double[]
    computeD(double referenceValueX, double referenceValueY)
    Computes the final values for both components using double reference values.
    final float[]
    computeF(float referenceValueX, float referenceValueY)
    Computes the final values for both components using floating-point reference values.
    final int[]
    computeI(int referenceValueX, int referenceValueY)
    Computes the final values for both components using integer reference values.
    final boolean
     
    static final UDim2
    fromOffset(double xOffset, double yOffset)
     
    static final UDim2
    fromScale(double xScale, double yScale)
     
    final int
     
    final String
     

    Methods inherited from class Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final UDim2 ZERO
    • x

      public final UDim x
      The horizontal component of the scalable value.

      Defines how the value changes relative to a reference width, combining a proportional scale and a fixed offset.

    • y

      public final UDim y
      The vertical component of the scalable value.

      Defines how the value changes relative to a reference height, combining a proportional scale and a fixed offset.

  • Constructor Details

  • Method Details

    • fromScale

      public static final UDim2 fromScale(double xScale, double yScale)
    • fromOffset

      public static final UDim2 fromOffset(double xOffset, double yOffset)
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • clone

      public final UDim2 clone()
      Overrides:
      clone in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • computeI

      public final int[] computeI(int referenceValueX, int referenceValueY)
      Computes the final values for both components using integer reference values.

      Each axis is calculated independently using the formula:

      finalValue = (referenceValue * scale) + offset;
      The results are rounded down to the nearest integers.
      Parameters:
      referenceValueX - The reference value for the horizontal component.
      referenceValueY - The reference value for the vertical component.
      Returns:
      An array containing the computed integer values for x and y.
    • computeF

      public final float[] computeF(float referenceValueX, float referenceValueY)
      Computes the final values for both components using floating-point reference values.

      Each axis is calculated independently using the formula:

      finalValue = (referenceValue * scale) + offset;
      The results retain floating-point precision.
      Parameters:
      referenceValueX - The reference value for the horizontal component.
      referenceValueY - The reference value for the vertical component.
      Returns:
      An array containing the computed float values for x and y.
    • computeD

      public final double[] computeD(double referenceValueX, double referenceValueY)
      Computes the final values for both components using double reference values.

      Each axis is calculated independently using the formula:

      finalValue = (referenceValue * scale) + offset;
      The results retain double precision.
      Parameters:
      referenceValueX - The reference value for the horizontal component.
      referenceValueY - The reference value for the vertical component.
      Returns:
      An array containing the computed double values for x and y.