It looks like the current implementation only exports a rewind function that returns (and sometimes mutates) a geojson object.
I need a function that will check for the "Right Hand Rule" - ensure polygon geoms have counter-clockwise external rings, clockwise internal rings. I don't have any need for the altered geometry, just the boolean.
The best I've got so far:
var rewind = require("geojson-rewind");
function isRightHandRule(geom) {
// Hack to deepcopy geom and avoid mutation
geomstring = JSON.stringify(geom);
geomcopy = JSON.parse(geomstring);
// Does the original geometry match the clockwise-wound geometry
return geomstring === JSON.stringify(rewind(geomcopy, true));
}
But this has some major flaws: it needs to deepcopy the geom via JSON strings, it relies on string comparison and it needs to rewind the entire geometry rather than failing fast on the first linear ring that doesn't match.
Any ideas on a better way to implement this?
It looks like the current implementation only exports a
rewindfunction that returns (and sometimes mutates) a geojson object.I need a function that will check for the "Right Hand Rule" - ensure polygon geoms have counter-clockwise external rings, clockwise internal rings. I don't have any need for the altered geometry, just the boolean.
The best I've got so far:
But this has some major flaws: it needs to deepcopy the geom via JSON strings, it relies on string comparison and it needs to rewind the entire geometry rather than failing fast on the first linear ring that doesn't match.
Any ideas on a better way to implement this?