public static bool TestOverlap(LineMask lnMask, AABBMask rMask) { VectorFP p0 = (VectorFP)lnMask._pos + lnMask._p0; VectorFP p1 = new VectorFP(p0.X + lnMask._w, p0.Y + lnMask._h); return rMask.IntersectsLine(p0, p1); }
/*public override TestResult TestOverlapExt (Mask mask) { switch (mask._type) { case MaskType.Point: return CollisionTR.TestOverlap(mask as PointMask, this); case MaskType.Line: return CollisionTR.TestOverlap(this, mask as LineMask); case MaskType.Circle: return CollisionTR.TestOverlap(this, mask as CircleMask); case MaskType.AABB: return CollisionTR.TestOverlap(this, mask as AABBMask); case MaskType.Triangle: return CollisionTR.TestOverlap(this, mask as TriangleMask); } return TestResult.None; } public TestResult TestOverlapExt (PointMask mask) { return CollisionTR.TestOverlap(mask, this); } public TestResult TestOverlapExt (LineMask mask) { return CollisionTR.TestOverlap(this, mask); } public TestResult TestOverlapExt (CircleMask mask) { return CollisionTR.TestOverlap(this, mask); } public TestResult TestOverlapExt (AABBMask mask) { return CollisionTR.TestOverlap(this, mask); } public TestResult TestOverlapExt (TriangleMask mask) { return CollisionTR.TestOverlap(this, mask); } internal static FPInt Signed2DTriArea (PointFP a, PointFP b, PointFP c) { return (a.X - c.X) * (b.Y - c.Y) - (a.Y - c.Y) * (b.X - c.X); } internal TestResult LineIntersect (PointFP a, PointFP b) { VectorFP c = (VectorFP)_pos + _p0; VectorFP d = c + new VectorFP(_w, _h); return LineIntersect(a, b, c, d); } internal static TestResult LineIntersect (PointFP a, PointFP b, PointFP c, PointFP d) { FPInt a1 = Signed2DTriArea(a, b, d); FPInt a2 = Signed2DTriArea(a, b, c); FPInt t1 = a1 * a2; // Deal with colinear lines if (a1 == 0 && a2 == 0) { if (a.X == c.X && !RangesOverlap(a.Y, b.Y, c.Y, d.Y)) { return TestResult.None; } else if (!RangesOverlap(a.X, b.X, c.X, d.X)) { return TestResult.None; } return TestResult.Overlapping | TestResult.Edge; } // Now deal with normal intersections else if (t1 <= 0) { FPInt a3 = Signed2DTriArea(c, d, a); FPInt a4 = a3 + a2 - a1; FPInt t2 = a3 * a4; if (t2 <= 0) { if (t1 * t2 == 0) { return TestResult.Overlapping | TestResult.Edge; } else { return TestResult.Overlapping; } } } return TestResult.None; }*/ internal PointFP ClosestPoint(PointFP p) { VectorFP a = (VectorFP)_pos + _p0; VectorFP ab = new VectorFP(_w, _h); FPInt t = VectorFP.Dot(p - a, ab); if (t <= 0) { return a; } else { FPInt d = VectorFP.Dot(ab, ab); if (t >= d) { return a + ab; } else { t = t / d; return a + (t * ab); } } }