forked from Ashishgup1/Competitive-Coding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry.cpp
40 lines (34 loc) · 1.06 KB
/
Geometry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
struct point
{
int x, y, idx;
};
//Finds squared euclidean distance between two points
int dist(point &a, point &b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
}
//Checks if angle ABC is a right angle
int isOrthogonal(point &a, point &b, point &c)
{
return (b.x-a.x) * (b.x-c.x) + (b.y-a.y) * (b.y-c.y) == 0;
}
//Checks if ABCD form a rectangle (in that order)
int isRectangle(point &a, point &b, point &c, point &d)
{
return isOrthogonal(a, b, c) && isOrthogonal(b, c, d) && isOrthogonal(c, d, a);
}
//Checks if ABCD form a rectangle, in any orientation
int isRectangleAnyOrder(point &a, point &b, point &c, point &d)
{
return isRectangle(a, b, c, d) || isRectangle(b, c, a, d) | isRectangle(c, a, b, d);
}
//Checks if ABCD form a square (in that order)
int isSquare(point &a, point &b, point &c, point &d)
{
return isRectangle(a, b, c, d) && dist(a, b) == dist(b, c);
}
//Checks if ABCD form a square, in any orientation
int isSquareAnyOrder(point &a, point &b, point &c, point &d)
{
return isSquare(a, b, c, d) || isSquare(b, c, a, d) | isSquare(c, a, b, d);
}