Unity.Mathematics equivalent to Mathf.Approximately for float2/float3..?

I’m having trouble doing simple float2 or float3 equality comparisons. Using a.Equals(b) gave better results than a == b but I’m looking for a Unity.Mathematics equivalent to Mathf.Approximately(a.x, b.x) && Mathf.Approximately(a.y, b.y) and am not finding anything in the docs.

Am I missing something, or is the Mathf workaround just normal? I was hoping I could avoid using the UnityEngine assembly at all in my pure ECS stuff.

I don’t think there’s a built-in function, but here’s the Mathf implementation (along with an uncharacteristically helpful comment) in case you want to roll your own helper function:

3 Likes

Nice, thanks for the prompt response!

that was mean but it made me laugh out loud :smile:

1 Like

Try math. lengthsqrt(a - b)!= 0.00001f for example. You need take into consideration potential floating point errors.

You could also try using mat.distsqrt, I think.

1 Like