Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

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 authored 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.