Class UDim

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

public final class UDim extends Object
Represents a scalable dimension with both a proportional and absolute component.

This structure allows UI elements to be sized or positioned using a combination of:

  • A relative scale factor (as a fraction of a reference size).
  • An absolute offset value (fixed pixel units).
The final computed value is determined by:
finalValue = (referenceValue * scale) + offset;
This is useful for UI layouts that need to be responsive while maintaining fixed adjustments.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double
    The absolute offset (in pixels) added to the scaled value.
    final double
    The proportional scale factor (relative to a reference size).
    static final UDim
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    UDim(double scale, double offset)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final UDim
     
    final double
    computeD(double referenceValue)
    Computes the final value using a double reference value.
    final float
    computeF(float referenceValue)
    Computes the final value using a floating-point reference value.
    final int
    computeI(int referenceValue)
    Computes the final value using an integer reference value.
    final boolean
     
    final int
     
    final String
     

    Methods inherited from class Object

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

    • ZERO

      public static final UDim ZERO
    • scale

      public final double scale
      The proportional scale factor (relative to a reference size).

      A value of 1.0 means the result is equal to the reference size, while 0.5 makes it half of the reference size. Negative values are valid and will scale in the opposite direction.

    • offset

      public final double offset
      The absolute offset (in pixels) added to the scaled value.

      This provides a fixed adjustment regardless of the reference size. A positive value shifts the result forward, while a negative value shifts it backward.

  • Constructor Details

    • UDim

      public UDim()
    • UDim

      public UDim(double scale, double offset)
  • Method Details

    • 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 UDim clone()
      Overrides:
      clone in class Object
    • toString

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

      public final int computeI(int referenceValue)
      Computes the final value using an integer reference value.

      The formula used is:

      finalValue = (referenceValue * scale) + offset;
      The result is rounded down to the nearest integer.
      Parameters:
      referenceValue - The reference size to apply scaling to.
      Returns:
      The computed final value as an integer.
    • computeF

      public final float computeF(float referenceValue)
      Computes the final value using a floating-point reference value.

      The formula used is:

      finalValue = (referenceValue * scale) + offset;
      The result retains floating-point precision.
      Parameters:
      referenceValue - The reference size to apply scaling to.
      Returns:
      The computed final value as a float.
    • computeD

      public final double computeD(double referenceValue)
      Computes the final value using a double reference value.

      The formula used is:

      finalValue = (referenceValue * scale) + offset;
      The result retains double precision.
      Parameters:
      referenceValue - The reference size to apply scaling to.
      Returns:
      The computed final value as a float.