Ninja owns a garden which is in a rectangular shape on a planet named βAsgardβ. He somehow manages to get information that his garden is the target of the coming meteor which is in a circular shape and ninja knows the radius and the coordinates of the center of the circle so he wants to know whether the meteor will overlap with his garden or not.
So your task is to check whether the meteor will overlap with the garden or not. You were provided with the coordinates of the bottom left corner and top right corner of the garden which is rectangular in shape and the center coordinates and radius of a meteor which is circular in shape.
Note :
If any point of the circle lies on the rectangle or inside the rectangle we say the circle is overlapping the rectangle.
Input Format :
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains seven space-separated integers βxCβ, βyCβ, βRADβ, βX1β, βY1β, βX2β, βY2β where βxCβ and βyCβ represents the center coordinates of a circle and βRADβ represents the radius of the circle and βX1β, βY1β represents the coordinates of the bottom left corner and βX2β, βY2β represents the coordinates of the top right corner of the rectangle respectively.
Output Format :
For each test case, print a single line containing βTrueβ if the meteor overlaps with the garden else, print βFalseβ.
The output of each test case will be printed in a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 5
1 <= RAD <= 2000
-10^4 <= xC, yC, X1, Y1, X2, Y2 <= 10^4
X1 < X2, Y1 < Y2
Where βTβ is the number of test cases, βxCβ and βyCβ represents the center coordinates of a circle and βRADβ represents the radius of the circle and βX1β, βY1β represents the coordinates of the bottom left corner and βX2β, βY2β represents the coordinates of the top right corner of the rectangle.
Time Limit: 1 sec
2
0 0 2 1 0 3 2
0 0 1 1 -1 3 1
True
True
Test Case 1 :
As you can observe the radius of the circle is β2β and according to their coordinates, we can say they will collapse so we return βTrueβ as the answer.
Test Case 2 :
As you can see in the picture there is a common point (1, 0) that lies both on the circle and rectangle so we return βTrueβ for this case.
1
0 0 1 3 2 6 4
False
Test Case 1:
As you can observe, rectangles and circles have no common points so we can say they will not collapse so we return βFalseβ as the answer.
Can you find the nearest point on the rectangle from the circle?
The idea here is to find the nearest point on a rectangle from the circle for this we can use suppose circle lies to the left side of the rectangle so in this case βxC < X1β and if suppose circle lies on the right side βxC < X2β and if it lies inside the rectangle βxC > X1β and βxC < x2β and same goes for βYβ coordinate so we can say the point of intersecting only depends on (X1, Y1) and (X2, Y2) then after finding the nearest point we can simply compare the distance between nearest point and center coordinate and then we can compare it with radius. If radius distance is greater or equal to the distance we can say it is overlapping else we can say they are not.
O(1).
As we are using a formula that takes constant time.
O(1).
As we are using constant space.