Skip to content

Commit

Permalink
Create 1401.Circle-and-Rectangle-Overlapping.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Apr 6, 2020
1 parent a6617b3 commit 3f9c6e2
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2)
{
double cx = (x2+x1)*1.0/2, cy = (y2+y1)*1.0/2;
double hx = (x2-x1)*1.0/2, hy = (y2-y1)*1.0/2;
double px = x_center, py = y_center;

double vx = abs(px-cx), vy = abs(py-cy);
double ux = max(vx-hx, 0.0), uy = max(vy-hy,0.0);

return ux*ux+uy*uy <= radius*radius;
}
};

0 comments on commit 3f9c6e2

Please sign in to comment.