mapillary-js/test/helper/TestMath.ts
2021-03-27 18:34:32 +01:00

11 lines
346 B
TypeScript

export function isClockwise(polygon: number[][]): boolean {
if (polygon.length < 3) { return false; };
let edgeSum = 0;
for (let i = 0; i < polygon.length; ++i) {
const [x1, y1] = polygon[i];
const [x2, y2] = polygon[(i + 1) % polygon.length];
edgeSum += (x2 - x1) * (y2 + y1);
}
return edgeSum > 0;
}