// 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); }
public static Vector2Int Floor(this LVector2 vec) { return(new Vector2Int( LMath.FloorToInt(vec.x), LMath.FloorToInt(vec.y))); }
public static Vector3 ToVector3(this LVector2 vec) { return(new Vector3(vec.x.ToFloat(), vec.y.ToFloat(), 0)); }
public static Vector2 ToVector2(this LVector2 vec) { return(new Vector2(vec.x.ToFloat(), vec.y.ToFloat())); }
public static Vector2Int ToVector2Int(this LVector2 vec) { return(new Vector2Int(vec.x.ToInt(), vec.y.ToInt())); }
public static Vector3 ToVector3XZ(this LVector2 vec, LFloat y) { return(new Vector3(vec.x.ToFloat(), y.ToFloat(), vec.y.ToFloat())); }
public static LVector2 Min(LVector2 a, LVector2 b) { return(new LVector2(true, LMath.Min(a._x, b._x), LMath.Min(a._y, b._y))); }
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)); }
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)); }
public static LFloat Dot(LVector2 u, LVector2 v) { return(new LFloat(true, ((long)u._x * v._x + (long)u._y * v._y) / LFloat.Precision)); }
public void Max(ref LVector2 r) { this._x = LMath.Max(this._x, r._x); this._y = LMath.Max(this._y, r._y); }