// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts,
// for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies.
// EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.TriangleUtil
using UnityEngine;

public class TriangleUtil
{
    public Vector3 ClosestPointOnTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
    {
        Vector3 vector = b - a;
        Vector3 vector2 = c - a;
        Vector3 rhs = p - a;
        float num = Vector3.Dot(vector, rhs);
        float num2 = Vector3.Dot(vector2, rhs);
        if (num <= 0f && num2 <= 0f)
        {
            return a;
        }
        Vector3 rhs2 = p - b;
        float num3 = Vector3.Dot(vector, rhs2);
        float num4 = Vector3.Dot(vector2, rhs2);
        if (num3 >= 0f && num4 <= num3)
        {
            return b;
        }
        float num5 = num * num4 - num3 * num2;
        if (num5 <= 0f && num >= 0f && num3 <= 0f)
        {
            float num6 = num / (num - num3);
            return a + num6 * vector;
        }
        Vector3 rhs3 = p - c;
        float num7 = Vector3.Dot(vector, rhs3);
        float num8 = Vector3.Dot(vector2, rhs3);
        if (num8 >= 0f && num7 <= num8)
        {
            return c;
        }
        float num9 = num7 * num2 - num * num8;
        if (num9 <= 0f && num2 >= 0f && num8 <= 0f)
        {
            float num10 = num2 / (num2 - num8);
            return a + num10 * vector2;
        }
        float num11 = num3 * num8 - num7 * num4;
        if (num11 <= 0f && num4 - num3 >= 0f && num7 - num8 >= 0f)
        {
            float num12 = (num4 - num3) / (num4 - num3 + (num7 - num8));
            return b + num12 * (c - b);
        }
        float num13 = 1f / (num11 + num9 + num5);
        float num14 = num9 * num13;
        float num15 = num5 * num13;
        return a + vector * num14 + vector2 * num15;
    }
}
