1 | export function ccw(polygon) {
|
2 |
|
3 | var _p = polygon.slice(0), sum = 0;
|
4 |
|
5 | _p.push(_p[0]);
|
6 |
|
7 | for (var i = 0; i <= polygon.length - 1; i++) {
|
8 |
|
9 | var j = i + 1;
|
10 | var p1 = _p[i].rotated;
|
11 | var p2 = _p[j].rotated;
|
12 |
|
13 | sum += (p2.x - p1.x) * (p2.y + p1.y);
|
14 | }
|
15 | // if the area is positive
|
16 | // the curve is counter-clockwise
|
17 | // because of the flipped y-Axis in the browser
|
18 | return sum > 0 ? true : false;
|
19 | }
|