05-06-2021, 12:56 PM
Hi
You are absolutely right about the comparison fix. I have been fixing some of those through time in different places, but I need some day to go through all float comparisons in the code base and fix them once and for all.
One thing about Mathf.Approximately to be aware of, is that Mathf.Approximately(0, someVerySmallNonZeroValue) will return false. There are cases where I would like it to return true. For thoses cases, I use the following:
You are absolutely right about the comparison fix. I have been fixing some of those through time in different places, but I need some day to go through all float comparisons in the code base and fix them once and for all.
One thing about Mathf.Approximately to be aware of, is that Mathf.Approximately(0, someVerySmallNonZeroValue) will return false. There are cases where I would like it to return true. For thoses cases, I use the following:
Code:
public static bool Approximately(this float x, float y)
{
bool result;
const float zeroComparaisonMargin = 0.000001f;
float nearlyZero = Mathf.Epsilon * 8f;
float absX = Math.Abs(x);
float absY = Math.Abs(y);
if (absY < nearlyZero)
result = absX < zeroComparaisonMargin;
else if (absX < nearlyZero)
result = absY < zeroComparaisonMargin;
else
result = Mathf.Approximately(x, y);
return result;
}
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.