Class for managing a complex hierarchy of geometric shapes with intersection checking
Kotlin
Hard
classes
Task «Class for managing a complex hierarchy of geometric shapes with intersection checking»
Create classes to represent geometric shapes: Point, Circle, Rectangle. The Point class contains x and y coordinates (Double). The Circle class contains a center (Point) and a radius (Double). The Rectangle class contains the top-left corner (Point) and the bottom-right corner (Point). Implement in each class the method intersects(other: Any): Boolean, which returns true if the shape intersects with another shape (circle with circle, rectangle with rectangle, circle with rectangle). For the circle and rectangle, use a check of the distance from the circle's center to the nearest point of the rectangle. In main(), read from stdin the number of shapes N (1 ≤ N ≤ 100), then for each shape a line: type ("Point", "Circle", "Rectangle") and coordinates. For Point: x y. For Circle: x y r. For Rectangle: x1 y1 x2 y2. For each pair of shapes (i < j), output the result of the intersection check: "YES" or "NO" in ascending order of pairs.
Input Format
Integer N. Then N lines, each containing the shape type and its parameters (Double coordinates).
Output Format
For each pair (i, j) with i < j, output "YES" or "NO" in increasing order of i, then j.
Examples
Example 1
INPUT
5
1 100 100
2 200 200
3 150 300
4 300 400
5 50 1500
OUTPUT
100 400 4 750 187
1500 1500 1 50 50
Example 2
INPUT
0
OUTPUT
main.kt