Class UDim2
java.lang.Object
com.thecsdev.common.math.UDim2
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.
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal UDim2clone()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 booleanstatic final UDim2fromOffset(double xOffset, double yOffset) static final UDim2fromScale(double xScale, double yScale) final inthashCode()final StringtoString()
-
Field Details
-
ZERO
-
x
The horizontal component of the scalable value.Defines how the value changes relative to a reference width, combining a proportional
scaleand a fixedoffset. -
y
The vertical component of the scalable value.Defines how the value changes relative to a reference height, combining a proportional
scaleand a fixedoffset.
-
-
Constructor Details
-
UDim2
public UDim2() -
UDim2
public UDim2(double xScale, double xOffset, double yScale, double yOffset) -
UDim2
- Throws:
NullPointerException
-
-
Method Details
-
fromScale
-
fromOffset
-
hashCode
-
equals
-
clone
-
toString
-
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:
The results are rounded down to the nearest integers.finalValue = (referenceValue * scale) + offset;- 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
xandy.
-
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:
The results retain floating-point precision.finalValue = (referenceValue * scale) + offset;- 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
xandy.
-
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:
The results retain double precision.finalValue = (referenceValue * scale) + offset;- 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
xandy.
-