public override bool Overlaps(RectangleShape rect, PointF offset) { // Two rectangles, A and B, overlap iff one of the corners of B is contained in A or if A is completely contained within B. PointF a1 = new PointF(-rect.Width / 2 + offset.X, -rect.Height / 2 + offset.Y); bool overlaps = (a1.X >= -width / 2) && (a1.X <= width / 2) && (a1.Y >= -height / 2) && (a1.Y <= height / 2); if (!overlaps) { PointF a2 = new PointF(rect.Width / 2 + offset.X, -rect.Height / 2 + offset.Y); overlaps = (a2.X >= -width / 2) && (a2.X <= width / 2) && (a2.Y >= -height / 2) && (a2.Y <= height / 2); if (!overlaps) { PointF a3 = new PointF(rect.Width / 2 + offset.X, rect.Height / 2 + offset.Y); overlaps = (a3.X >= -width / 2) && (a3.X <= width / 2) && (a3.Y >= -height / 2) && (a3.Y <= height / 2); if (!overlaps) { PointF a4 = new PointF(-rect.Width / 2 + offset.X, rect.Height / 2 + offset.Y); overlaps = (a4.X >= -width / 2) && (a4.X <= width / 2) && (a4.Y >= -height / 2) && (a4.Y <= height / 2); if (!overlaps) { overlaps = (-width / 2 >= a1.X) && (-width / 2 <= a2.X) && (-height / 2 >= a1.Y) && (-height / 2 <= a3.Y); } } } } return overlaps; }
/// <summary> /// Calculates if the other rectangle, with a center offset given, intersects with the given shape. /// </summary> /// <param name="rect"></param> /// <param name="offset"></param> /// <returns></returns> public abstract bool Overlaps(RectangleShape rect, PointF offset);
public override bool Overlaps(RectangleShape rect, PointF offset) { throw new NotImplementedException(); }