mapbox / mapbox/geojson-rewind
isRightHandRule function
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 133
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the exported rewind function and trace how it visits polygon geometries and their linear rings. Define the boolean check around the existing ring-winding behavior, then verify that it reports whether external rings are counter-clockwise and internal rings clockwise without altering the input or processing beyond the first mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100