James Beard e7227f51b7
Preliminary improvements to documentation, esp internal types e.g. Units (#2727)
* Added JSDoc for internal types and constants e.g. Unts and earthRadius. Minimal other changes to bring JSDoc types into line with code types. Added GeoJsonProperties to documentation.yml for type linking.

* Generated README.md files based on updated source that now includes JSDoc for internal types and constants e.g. Units. Also synced up some out of data JSDoc types with what is in the code.

* Switched the structure of documentation.yml to be more traditionally nested. We'll use this new structure from the turf-www repo to generate the website documentation in a more robust manner.

* For some reason leaving this function documented as the default (geojsonRbush) causes @turf/turf last-checks to fail. Specifically defining it as rbush like it used to be, except with the @function tag rather than @name.
2024-10-11 12:56:42 +11:00

39 lines
1011 B
TypeScript

import { Feature, LineString, Position } from "geojson";
import { getCoords } from "@turf/invariant";
/**
* Takes a ring and return true or false whether or not the ring is clockwise or counter-clockwise.
*
* @function
* @param {Feature<LineString>|LineString|Array<Array<number>>} line to be evaluated
* @returns {boolean} true/false
* @example
* var clockwiseRing = turf.lineString([[0,0],[1,1],[1,0],[0,0]]);
* var counterClockwiseRing = turf.lineString([[0,0],[1,0],[1,1],[0,0]]);
*
* turf.booleanClockwise(clockwiseRing)
* //=true
* turf.booleanClockwise(counterClockwiseRing)
* //=false
*/
function booleanClockwise(
line: Feature<LineString> | LineString | Position[]
): boolean {
const ring = getCoords(line);
let sum = 0;
let i = 1;
let prev;
let cur;
while (i < ring.length) {
prev = cur || ring[0];
cur = ring[i];
sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
i++;
}
return sum > 0;
}
export { booleanClockwise };
export default booleanClockwise;