static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; int testCases = int.Parse(Console.ReadLine()); for (int testCase = 0; testCase < testCases; testCase++) { ReadFigures(); bool topLeftInsideCircle = circle.IsInsideCircle(rectangle.TopLeft); bool topRightInsideCircle = circle.IsInsideCircle(rectangle.TopRight); bool bottomLeftInsideCircle = circle.IsInsideCircle(rectangle.BottomLeft); bool bottomRightInsideCircle = circle.IsInsideCircle(rectangle.BottomRight); bool topInsideRectangle = rectangle.IsInsideRectangle(circle.Top); bool rightInsideRectangle = rectangle.IsInsideRectangle(circle.Right); bool bottomInsideRectangle = rectangle.IsInsideRectangle(circle.Bottom); bool leftInsideRectangle = rectangle.IsInsideRectangle(circle.Left); if (topLeftInsideCircle && topRightInsideCircle && bottomLeftInsideCircle && bottomRightInsideCircle) { Console.WriteLine("Rectangle inside circle"); } else if (topInsideRectangle && rightInsideRectangle && bottomInsideRectangle && leftInsideRectangle) { Console.WriteLine("Circle inside rectangle"); } else { // None is inside the other. Check boundary conditions var centerDistance = new Point(Math.Abs(circle.Center.X - rectangle.Center.X), Math.Abs(circle.Center.Y - rectangle.Center.Y)); var width = rectangle.TopRight.X - rectangle.TopLeft.X; var height = rectangle.TopLeft.Y - rectangle.BottomLeft.Y; if (centerDistance.X > width / 2 + circle.Radius || centerDistance.Y > height / 2 + circle.Radius) { Console.WriteLine("Rectangle and circle do not cross"); } else if (centerDistance.X <= width / 2 || centerDistance.Y <= height / 2) { Console.WriteLine("Rectangle and circle cross"); } else { var cornerDistance = (centerDistance.X - width / 2) * (centerDistance.X - width / 2) + (centerDistance.Y - height / 2) * (centerDistance.Y - height / 2); if (cornerDistance - circle.Radius * circle.Radius <= Epsilon) { Console.WriteLine("Rectangle and circle cross"); } else { Console.WriteLine("Rectangle and circle do not cross"); } } } } }