// Test if 2D point P lies inside 2D triangle ABC
        public static bool  TestPointTriangle2D(Point2D p, Point2D a, Point2D b, Point2D c)
        {
            LFloat pab = Cross2D(p - a, b - a);
            LFloat pbc = Cross2D(p - b, c - b);

            // If P left of one of AB and BC and right of the other, not inside triangle
            if (!SameSign(pab, pbc))
            {
                return(false);
            }
            LFloat pca = Cross2D(p - c, a - c);

            // If P left of one of AB and CA and right of the other, not inside triangle
            if (!SameSign(pab, pca))
            {
                return(false);
            }
            // P left or right of all edges, so must be in (or on) the triangle
            return(true);
        }
Пример #2
0
 public static Vector2Int Floor(this LVector2 vec)
 {
     return(new Vector2Int(
                LMath.FloorToInt(vec.x),
                LMath.FloorToInt(vec.y)));
 }
Пример #3
0
 public static Vector3 ToVector3(this LVector2 vec)
 {
     return(new Vector3(vec.x.ToFloat(), vec.y.ToFloat(), 0));
 }
Пример #4
0
 public static Vector2 ToVector2(this LVector2 vec)
 {
     return(new Vector2(vec.x.ToFloat(), vec.y.ToFloat()));
 }
Пример #5
0
 public static Vector2Int ToVector2Int(this LVector2 vec)
 {
     return(new Vector2Int(vec.x.ToInt(), vec.y.ToInt()));
 }
Пример #6
0
 public static Vector3 ToVector3XZ(this LVector2 vec, LFloat y)
 {
     return(new Vector3(vec.x.ToFloat(), y.ToFloat(), vec.y.ToFloat()));
 }
Пример #7
0
 public static LVector2 Min(LVector2 a, LVector2 b)
 {
     return(new LVector2(true, LMath.Min(a._x, b._x), LMath.Min(a._y, b._y)));
 }
Пример #8
0
 public static LVector2 Lerp(LVector2 a, LVector2 b, LFloat f)
 {
     return(new LVector2(true,
                         (int)(((long)(b._x - a._x) * f._val) / LFloat.Precision) + a._x,
                         (int)(((long)(b._y - a._y) * f._val) / LFloat.Precision) + a._y));
 }
Пример #9
0
 public static LFloat Cross(LVector2 a, LVector2 b)
 {
     return(new LFloat(true, ((long)a._x * (long)b._y - (long)a._y * (long)b._x) / LFloat.Precision));
 }
Пример #10
0
 public static LFloat Dot(LVector2 u, LVector2 v)
 {
     return(new LFloat(true, ((long)u._x * v._x + (long)u._y * v._y) / LFloat.Precision));
 }
Пример #11
0
 public void Max(ref LVector2 r)
 {
     this._x = LMath.Max(this._x, r._x);
     this._y = LMath.Max(this._y, r._y);
 }