Skip to content

Commit

Permalink
fix rhr (#81)
Browse files Browse the repository at this point in the history
* fix rhr: no angles, just the cross-product

the old isRingClockwise as too fragile and came with too many
false negatives. use the established isRingClockwise algorithm.
bump version, fork to @rurban

* Updated CHANGELOG for 3.0.1
  • Loading branch information
rurban committed May 11, 2021
1 parent aa27be6 commit d1f7373
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 3.0.1

* Fixed the rhr check (forked to @rurban)

## 3.0.0

* Bump tested node versions to 8 & 10
Expand Down
10 changes: 3 additions & 7 deletions lib/rhr.js
@@ -1,19 +1,15 @@
function rad(x) {
return x * Math.PI / 180;
}

function isRingClockwise (coords) {
var area = 0;
var sum = 0;
if (coords.length > 2) {
var p1, p2;
for (var i = 0; i < coords.length - 1; i++) {
p1 = coords[i];
p2 = coords[i + 1];
area += rad(p2[0] - p1[0]) * (2 + Math.sin(rad(p1[1])) + Math.sin(rad(p2[1])));
sum += (p2[0] - p1[0]) * (p2[1] + p1[1]);
}
}

return area >= 0;
return sum >= 0;
}

function isPolyRHR (coords) {
Expand Down
10 changes: 5 additions & 5 deletions package.json
@@ -1,13 +1,13 @@
{
"name": "@mapbox/geojsonhint",
"name": "@rurban/geojsonhint",
"description": "validate and sanity-check geojson files",
"version": "3.0.0",
"author": "Tom MacWright",
"version": "3.0.1",
"author": "Reini Urban",
"bin": {
"geojsonhint": "./bin/geojsonhint"
},
"bugs": {
"url": "https://github.com/mapbox/geojsonhint/issues"
"url": "https://github.com/rurban/geojsonhint/issues"
},
"files": [
"geojsonhint.js",
Expand Down Expand Up @@ -40,7 +40,7 @@
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git://github.com/mapbox/geojsonhint.git"
"url": "git://github.com/rurban/geojsonhint.git"
},
"scripts": {
"test": "eslint . && tap test/*.js --coverage",
Expand Down

0 comments on commit d1f7373

Please sign in to comment.