Search Unity

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

Discussion in 'Entity Component System' started by bilalakil, May 19, 2022.

  1. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    77
    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.
     
  2. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    284
    ClementSXD, bilalakil and hippocoder like this.
  3. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    77
    Nice, thanks for the prompt response!
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    that was mean but it made me laugh out loud :D
     
    ClementSXD likes this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    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.
     
    bilalakil likes this.