/// <summary> /// Draw an outlined box on the screen. /// </summary> /// <param name="rect">The RotRect of the box.</param> /// <param name="bordersize">The border size.</param> /// <param name="col">The color.</param> public void DrawOutlinedBox(RotRect rect, float bordersize, Color col) { if (bordersize == 0) { return; } bordersize *= Camera.Scale; Vector2[] avec = rect.GetRotatedPosArray(); // [topLeft, topRight, botRight, botLeft] DrawLine(avec[0], avec[1], bordersize, col); // top left to top right DrawLine(avec[1], avec[2], bordersize, col); // top right to bottom right DrawLine(avec[0], avec[3], bordersize, col); // top left to bottom left DrawLine(avec[2], avec[3], bordersize, col); // bottom left to bottom right }
/// <summary> /// Test if the RotRect intersects with another RotRect. /// </summary> /// <param name="other">The other RotRect to test.</param> /// <returns>True if they intersect, false if they don't.</returns> public bool Intersects(RotRect other) { Vector2[] points = GetRotatedPosArray(); Vector2[] otherPoints = other.GetRotatedPosArray(); if (PointInPolygon(points[0], otherPoints) || PointInPolygon(points[1], otherPoints) || PointInPolygon(points[2], otherPoints) || PointInPolygon(points[3], otherPoints) || PointInPolygon(otherPoints[0], points) || PointInPolygon(otherPoints[1], points) || PointInPolygon(otherPoints[2], points) || PointInPolygon(otherPoints[3], points) ) { return(true); } if (SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[0], otherPoints[1]) || SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[0], otherPoints[1]) || SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[0], otherPoints[1]) || SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[0], otherPoints[1]) || SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[1], otherPoints[2]) || SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[1], otherPoints[2]) || SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[1], otherPoints[2]) || SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[1], otherPoints[2]) || SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[2], otherPoints[3]) || SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[2], otherPoints[3]) || SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[2], otherPoints[3]) || SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[2], otherPoints[3]) || SpecialMath.LineSegmentsIntersect(points[0], points[1], otherPoints[3], otherPoints[0]) || SpecialMath.LineSegmentsIntersect(points[1], points[2], otherPoints[3], otherPoints[0]) || SpecialMath.LineSegmentsIntersect(points[2], points[3], otherPoints[3], otherPoints[0]) || SpecialMath.LineSegmentsIntersect(points[3], points[0], otherPoints[3], otherPoints[0]) ) { return(true); } return(false); }