Skip to content

Commit 3f9c6e2

Browse files
authored
Create 1401.Circle-and-Rectangle-Overlapping.cpp
1 parent a6617b3 commit 3f9c6e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2)
4+
{
5+
double cx = (x2+x1)*1.0/2, cy = (y2+y1)*1.0/2;
6+
double hx = (x2-x1)*1.0/2, hy = (y2-y1)*1.0/2;
7+
double px = x_center, py = y_center;
8+
9+
double vx = abs(px-cx), vy = abs(py-cy);
10+
double ux = max(vx-hx, 0.0), uy = max(vy-hy,0.0);
11+
12+
return ux*ux+uy*uy <= radius*radius;
13+
}
14+
};

0 commit comments

Comments
 (0)