//public static readonly RangeDouble Zero1 = new RangeDouble(0, 1);

    private Vector3 CalculateCornerAndLine(Vector3 p, double uab, double uca, ref bool isInPlane)
    {
        if (uca > 1 && uab < 0)
        {
            isInPlane = false;
            return(A);
        }
        var ubc = EdgeBc.Project(p);

        if (uab > 1 && ubc < 0)
        {
            isInPlane = false;
            return(B);
        }
        if (ubc > 1 && uca < 0)
        {
            isInPlane = false;
            return(C);
        }

        //line
        if (uab >= 0 && uab <= 1 && !PlaneAb.IsAbove(p))
        {
            isInPlane = false;
            return(EdgeAb.PointAt(uab));
        }
        if (ubc >= 0 && ubc <= 1 && !PlaneBc.IsAbove(p))
        {
            isInPlane = false;
            return(EdgeBc.PointAt(ubc));
        }
        if (uca >= 0 && uca <= 1 && !PlaneCa.IsAbove(p))
        {
            isInPlane = false;
            return(EdgeCa.PointAt(uca));
        }
        isInPlane = true;
        return(Vector3.zero);
    }
    public Vector3 ClosestPointTo(Vector3 p)
    {
        // Find the projection of the point onto the edge

        var  uab       = EdgeAb.Project(p);
        var  uca       = EdgeCa.Project(p);
        bool isInPlane = false;

        Vector3 rightPositionIfOutsidePlane = CalculateCornerAndLine(p, uab, uca, ref isInPlane);

        if (!infinitePlane)
        {
            //ici on est dans un plan fini, si on dis de ne pas prendre
            //en compte les borders, juste tomber !
            if (noGravityBorders && !isInPlane)
            {
                //Debug.Log("ici on est PAS dans le plane, juste tomber !");
                return(ExtVector3.GetNullVector());
            }
            else if (noGravityBorders && isInPlane)
            {
                //Debug.Log("ici on est DANS le plane, ET en noGravityBorder: tester la normal ensuite !");
                if (unidirectionnal)
                {
                    return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)));  //get the good point (or null) in a plane unidirectionnal
                }
                else
                {
                    //ici en gravityBorder, et on est dans le plan, et c'esst multi directionnel, alors OK dac !
                    return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p));
                }
            }
            else if (!noGravityBorders && unidirectionnal)
            {
                //here not infinite, and WITH borders AND unidirectionnal
                if (isInPlane)
                {
                    return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)));  //get the good point (or null) in a plane unidirectionnal
                }
                else
                {
                    return(GetGoodPointUnidirectionnal(p, rightPositionIfOutsidePlane));
                }
            }
            else
            {
                //here Not infinite, WITH borders, NO unidirectionnal
                if (isInPlane)
                {
                    return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p));
                }
                else
                {
                    return(rightPositionIfOutsidePlane);
                }
            }
        }
        else
        {
            if (unidirectionnal)
            {
                return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)));  //get the good point (or null) in a plane unidirectionnal
            }
        }



        //ici le plan est infini, OU fini mais on est dedant


        // The closest point is in the triangle so
        // project to the plane to find it
        //Vector3 projectedPoint = TriPlane.Project(EdgeAb.A, TriNorm.normalized, p);
        return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p));
    }