Implement UDim::Equals and UDim::Lerp

This commit is contained in:
2025-02-10 16:41:44 -05:00
parent bd19b29a27
commit 030da85166
2 changed files with 19 additions and 0 deletions

View File

@@ -11,6 +11,8 @@
#pragma once
#include "J3ML/J3ML.hpp"
namespace JUI
{
/// A coordinate system data type for user interfaces specifically.
@@ -32,6 +34,10 @@ namespace JUI
UDim operator * (float rhs) const;
UDim operator / (float rhs) const;
bool Equals(const UDim& rhs, float epsilon = 1e-3f);
UDim Lerp(const UDim& goal, float t);
};
namespace UDimLiterals {

View File

@@ -31,3 +31,16 @@ JUI::UDim JUI::UDim::operator*(float rhs) const {
JUI::UDim JUI::UDim::operator/(float rhs) const {
return {static_cast<int>(Pixels / rhs), Scale/rhs};
}
JUI::UDim JUI::UDim::Lerp(const JUI::UDim &goal, float t) {
float scale = J3ML::Math::Lerp(Scale, goal.Scale, t);
float pixels = J3ML::Math::Lerp(Pixels, goal.Pixels, t);
return UDim(pixels, scale);
}
bool JUI::UDim::Equals(const JUI::UDim &rhs, float epsilon) {
return J3ML::Math::Equal((float)Pixels, rhs.Pixels, epsilon)
&& J3ML::Math::Equal(Scale, rhs.Scale, epsilon);
}