Skip to content

Commit ed0c783

Browse files
committed
Simplify Angle slightly
Using the half() method from https://vlecomte.github.io/cp-geo.pdf.
1 parent 494904d commit ed0c783

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

content/geometry/Angle.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Author: Simon Lindholm
33
* Date: 2015-01-31
44
* License: CC0
5-
* Source:
5+
* Source: me
66
* Description: A class for ordering angles (as represented by int points and
77
* a number of rotations around the origin). Useful for rotational sweeping.
88
* Sometimes also represents points or vectors.
@@ -19,20 +19,18 @@ struct Angle {
1919
int t;
2020
Angle(int x, int y, int t=0) : x(x), y(y), t(t) {}
2121
Angle operator-(Angle b) const { return {x-b.x, y-b.y, t}; }
22-
int quad() const {
22+
int half() const {
2323
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);
2725
}
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()}; }
3028
Angle t360() const { return {x, y, t + 1}; }
3129
};
3230
bool operator<(Angle a, Angle b) {
3331
// 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);
3634
}
3735

3836
// Given two points, this calculates the smallest angle between

0 commit comments

Comments
 (0)