2
2
* Author: Simon Lindholm
3
3
* Date: 2015-01-31
4
4
* License: CC0
5
- * Source:
5
+ * Source: me
6
6
* Description: A class for ordering angles (as represented by int points and
7
7
* a number of rotations around the origin). Useful for rotational sweeping.
8
8
* Sometimes also represents points or vectors.
@@ -19,20 +19,18 @@ struct Angle {
19
19
int t ;
20
20
Angle (int x , int y , int t = 0 ) : x (x ), y (y ), t (t ) {}
21
21
Angle operator - (Angle b ) const { return {x - b .x , y - b .y , t }; }
22
- int quad () const {
22
+ int half () const {
23
23
assert (x || y );
24
- if (y < 0 ) return (x >= 0 ) + 2 ;
25
- if (y > 0 ) return (x <= 0 );
26
- return (x <= 0 ) * 2 ;
24
+ return y < 0 || (y == 0 && x < 0 );
27
25
}
28
- Angle t90 () const { return {- y , x , t + (quad () == 3 )}; }
29
- Angle t180 () const { return {- x , - y , t + ( quad () >= 2 )}; }
26
+ Angle t90 () const { return {- y , x , t + (half () && x >= 0 )}; }
27
+ Angle t180 () const { return {- x , - y , t + half ( )}; }
30
28
Angle t360 () const { return {x , y , t + 1 }; }
31
29
};
32
30
bool operator < (Angle a , Angle b ) {
33
31
// add a.dist2() and b.dist2() to also compare distances
34
- return make_tuple (a .t , a .quad (), a .y * (ll )b .x ) <
35
- make_tuple (b .t , b .quad (), a .x * (ll )b .y );
32
+ return make_tuple (a .t , a .half (), a .y * (ll )b .x ) <
33
+ make_tuple (b .t , b .half (), a .x * (ll )b .y );
36
34
}
37
35
38
36
// Given two points, this calculates the smallest angle between
0 commit comments