Skip to content

Commit

Permalink
Use robust-predicates in signed area (#111)
Browse files Browse the repository at this point in the history
* Use robust-predicates in signed area

* Add issue 102 fixture

* add more fixtures and update package-lock.json
  • Loading branch information
rowanwins authored and w8r committed Jan 7, 2020
1 parent 7256049 commit 245c8d4
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 4 deletions.
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"uglify-js": "^3.3.21"
},
"dependencies": {
"robust-predicates": "^2.0.4",
"splaytree": "^0.1.4",
"tinyqueue": "^1.2.0"
}
Expand Down
7 changes: 6 additions & 1 deletion src/signed_area.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {orient2d} from 'robust-predicates';

/**
* Signed area of the triangle (p0, p1, p2)
* @param {Array.<Number>} p0
Expand All @@ -6,5 +8,8 @@
* @return {Number}
*/
export default function signedArea(p0, p1, p2) {
return (p0[0] - p2[0]) * (p1[1] - p2[1]) - (p1[0] - p2[0]) * (p0[1] - p2[1]);
const res = orient2d(p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]);
if (res > 0) return -1;
if (res < 0) return 1;
return 0;
}
74 changes: 74 additions & 0 deletions test/fixtures/issue100.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-12.5,0,0],[-12.259880065917969,-2.438620090484619,0],[-11.548500061035156,-4.7835001945495605,0],[-12.5,0,0]]]
}
},{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-11.548500061035156,4.7835001945495605,0],[-12.259880065917969,2.438620090484619,0],[-12.5,0,0],[-11.548500061035156,4.7835001945495605,0]],
[[-12.5,0,0],[-11.548500061035156,-4.7835001945495605,0],[12.259880065917969,-2.438620090484619,0],[-12.5,0,0]],
[[-11.548500061035156,4.7835001945495605,0],[-12.5,0,0],[12.259880065917969,-2.438620090484619,0],[-11.548500061035156,4.7835001945495605,0]],
[[11.548199653625488,-4.784060001373291,0],[11.548500061035156,-4.7835001945495605,0],[12.259880065917969,-2.438620090484619,0],[12.25918960571289,-2.440279960632324,0],[11.548199653625488,-4.784060001373291,0]],
[[12.25918960571289,-2.440279960632324,0],[12.259880065917969,-2.438620090484619,0],[12.259539604187012,-2.4391300678253174,0],[12.25918960571289,-2.440279960632324,0]],
[[12.259539604187012,-2.4391300678253174,0],[12.259880065917969,-2.438620090484619,0],[12.259650230407715,-2.438770055770874,0],[12.259539604187012,-2.4391300678253174,0]],
[[12.259650230407715,-2.438770055770874,0],[12.259880065917969,-2.438620090484619,0],[12.259679794311523,-2.438659906387329,0],[12.259650230407715,-2.438770055770874,0]],
[[12.259969711303711,2.4377200603485107,0],[12.259880065917969,2.438620090484619,0],[12.259679794311523,2.438659906387329,0],[12.259969711303711,2.4377200603485107,0]],
[[12.259880065917969,2.438620090484619,0],[11.548500061035156,4.7835001945495605,0],[11.548199653625488,4.784060001373291,0],[12.25918960571289,2.440279960632324,0],[12.259880065917969,2.438620090484619,0]],
[[12.259880065917969,2.438620090484619,0],[12.25918960571289,2.440279960632324,0],[12.259539604187012,2.4391300678253174,0],[12.259880065917969,2.438620090484619,0]],
[[12.259679794311523,2.438659906387329,0],[12.259880065917969,2.438620090484619,0],[12.259539604187012,2.4391300678253174,0],[12.259679794311523,2.438659906387329,0]],
[[12.259880065917969,-2.438620090484619,0],[12.259969711303711,-2.4377200603485107,0],[12.259719848632812,-2.4385499954223633,0],[12.259880065917969,-2.438620090484619,0]],
[[-11.548500061035156,-4.7835001945495605,0],[-11.548199653625488,-4.784060001373291,0],[-11.548370361328125,-4.783490180969238,0],[-11.548500061035156,-4.7835001945495605,0]],
[[-11.548500061035156,4.7835001945495605,0],[-11.548379898071289,4.7834601402282715,0],[-11.548199653625488,4.784060001373291,0],[-11.548500061035156,4.7835001945495605,0]],
[[10.83080005645752,-6.12624979019165,0],[11.548199653625488,-4.784060001373291,0],[11.548370361328125,-4.783490180969238,0],[10.830659866333008,-6.12624979019165,0],[10.83080005645752,-6.12624979019165,0]],
[[11.889439582824707,-3.659140110015869,0],[12.25918960571289,-2.440279960632324,0],[11.889439582824707,-3.332900047302246,0],[11.889439582824707,-3.659140110015869,0]],
[[12.5,0,0],[12.259969711303711,2.4377200603485107,0],[12.259679794311523,2.438659906387329,0],[11.141039848327637,2.66117000579834,0],[11.141039848327637,0.4122300148010254,0],[12.5,0,0]],
[[11.548199653625488,4.784060001373291,0],[11.141039848327637,5.545810222625732,0],[11.141039848327637,5.545559883117676,0],[11.548370361328125,4.783490180969238,0],[11.548199653625488,4.784060001373291,0]],
[[11.141039848327637,5.139659881591797,0],[12.25918960571289,2.440279960632324,0],[11.548370361328125,4.783490180969238,0],[11.141039848327637,5.545559883117676,0],[11.141039848327637,5.139659881591797,0]],
[[12.259969711303711,-2.4377200603485107,0],[12.5,0,0],[11.141039848327637,0.4122300148010254,0],[11.141039848327637,-1.9751800298690796,0],[12.259719848632812,-2.4385499954223633,0],[12.259969711303711,-2.4377200603485107,0]],
[[11.548370361328125,-4.783490180969238,0],[11.889439582824707,-3.659140110015869,0],[11.889439582824707,-3.332900047302246,0],[10.732370376586914,-6.12624979019165,0],[10.830659866333008,-6.12624979019165,0],[11.548370361328125,-4.783490180969238,0]],
[[11.141039848327637,-5.139659881591797,0],[12.25918960571289,-2.440279960632324,0],[12.259539604187012,-2.4391300678253174,0],[11.141039848327637,-4.113059997558594,0],[11.141039848327637,-5.139659881591797,0]],
[[11.141039848327637,-4.113059997558594,0],[12.259539604187012,-2.4391300678253174,0],[12.259650230407715,-2.438770055770874,0],[11.141039848327637,-3.186199903488159,0],[11.141039848327637,-4.113059997558594,0]],
[[11.141039848327637,-3.186199903488159,0],[12.259650230407715,-2.438770055770874,0],[12.259679794311523,-2.438659906387329,0],[11.141039848327637,-2.66117000579834,0],[11.141039848327637,-3.186199903488159,0]],
[[-11.548199653625488,-4.784060001373291,0],[-11.141039848327637,-5.545810222625732,0],[-11.141039848327637,-5.545559883117676,0],[-11.548370361328125,-4.7835001945495605,0],[-11.548199653625488,-4.784060001373291,0]],
[[11.141039848327637,-2.66117000579834,0],[12.259679794311523,-2.438659906387329,0],[11.141039848327637,-2.548830032348633,0],[11.141039848327637,-2.66117000579834,0]],
[[11.141039848327637,2.66117000579834,0],[10.830659866333008,2.722909927368164,0],[10.830659866333008,0.506380021572113,0],[11.141039848327637,0.4122300148010254,0],[11.141039848327637,2.66117000579834,0]],
[[-11.141039848327637,5.545810222625732,0],[-11.548199653625488,4.784060001373291,0],[-11.548370361328125,4.7835001945495605,0],[-11.141039848327637,5.545559883117676,0],[-11.141039848327637,5.545810222625732,0]],
[[12.259710311889648,-2.438570022583008,0],[11.141039848327637,-1.9752000570297241,0],[11.141039848327637,-2.0992300510406494,0],[12.259710311889648,-2.438570022583008,0]],
[[10.830659866333008,5.888959884643555,0],[11.141039848327637,5.139659881591797,0],[11.141039848327637,5.545559883117676,0],[10.830659866333008,6.12624979019165,0],[10.830659866333008,5.888959884643555,0]],
[[12.25918960571289,2.440279960632324,0],[11.141039848327637,5.139659881591797,0],[11.141039848327637,4.113059997558594,0],[12.259539604187012,2.4391300678253174,0],[12.25918960571289,2.440279960632324,0]],
[[12.259679794311523,2.438659906387329,0],[12.259539604187012,2.4391300678253174,0],[11.141039848327637,4.113059997558594,0],[11.141039848327637,2.66117000579834,0],[12.259679794311523,2.438659906387329,0]],
[[11.141039848327637,0.4122300148010254,0],[10.830659866333008,0.506380021572113,0],[10.830659866333008,-1.846619963645935,0],[11.141039848327637,-1.9751800298690796,0],[11.141039848327637,0.4122300148010254,0]],
[[10.830659866333008,-5.888959884643555,0],[11.141039848327637,-5.139659881591797,0],[11.141039848327637,-4.113059997558594,0],[10.830659866333008,-4.577569961547852,0],[10.830659866333008,-5.888959884643555,0]],
[[10.830659866333008,-4.577569961547852,0],[11.141039848327637,-4.113059997558594,0],[11.141039848327637,-3.186199903488159,0],[10.830659866333008,-3.393589973449707,0],[10.830659866333008,-4.577569961547852,0]],
[[10.830659866333008,-3.393589973449707,0],[11.141039848327637,-3.186199903488159,0],[11.141039848327637,-2.66117000579834,0],[10.830659866333008,-2.722909927368164,0],[10.830659866333008,-3.393589973449707,0]],
[[-11.141039848327637,-4.743370056152344,0],[-11.548370361328125,-4.783490180969238,0],[-11.141039848327637,-5.5455498695373535,0],[-11.141039848327637,-4.743370056152344,0]],
[[10.830659866333008,2.722909927368164,0],[-6.279160022735596,6.12624979019165,0],[-7.695549964904785,6.12624979019165,0],[10.830659866333008,0.506380021572113,0],[10.830659866333008,2.722909927368164,0]],
[[-10.83080005645752,6.12624979019165,0],[-11.141039848327637,5.545810222625732,0],[-11.141039848327637,5.545559883117676,0],[-10.830659866333008,6.12624979019165,0],[-10.83080005645752,6.12624979019165,0]],
[[-11.141039848327637,5.545559883117676,0],[-11.548370361328125,4.7835001945495605,0],[-11.141039848327637,4.659939765930176,0],[-11.141039848327637,5.545559883117676,0]],
[[11.141039848327637,5.545810222625732,0],[11.078660011291504,5.662519931793213,0],[11.078660011291504,5.6622700691223145,0],[11.141039848327637,5.545559883117676,0],[11.141039848327637,5.545810222625732,0]],
[[10.732370376586914,6.12624979019165,0],[10.830659866333008,5.888959884643555,0],[10.830659866333008,6.12624979019165,0],[10.732370376586914,6.12624979019165,0]],
[[11.141039848327637,5.139659881591797,0],[10.830659866333008,5.888959884643555,0],[10.830659866333008,4.577569961547852,0],[11.141039848327637,4.113059997558594,0],[11.141039848327637,5.139659881591797,0]],
[[11.141039848327637,4.113059997558594,0],[10.830659866333008,4.577569961547852,0],[10.830659866333008,2.722909927368164,0],[11.141039848327637,2.66117000579834,0],[11.141039848327637,4.113059997558594,0]],
[[10.830659866333008,0.506380021572113,0],[-7.695580005645752,6.12624979019165,0],[-8.417630195617676,6.12624979019165,0],[10.830659866333008,-1.846619963645935,0],[10.830659866333008,0.506380021572113,0]],
[[9.795860290527344,-6.12624979019165,0],[10.830659866333008,-4.577569961547852,0],[10.830659866333008,-3.393589973449707,0],[6.740960121154785,-6.12624979019165,0],[9.795860290527344,-6.12624979019165,0]],
[[6.740960121154785,-6.12624979019165,0],[10.830659866333008,-3.393589973449707,0],[10.830659866333008,-2.722909927368164,0],[-6.279160022735596,-6.12624979019165,0],[6.740960121154785,-6.12624979019165,0]],
[[-11.141039848327637,-5.545810222625732,0],[-11.078660011291504,-5.662519931793213,0],[-11.078660011291504,-5.6622700691223145,0],[-11.141039848327637,-5.545559883117676,0],[-11.141039848327637,-5.545810222625732,0]],
[[10.830659866333008,-2.722909927368164,0],[11.141039848327637,-2.66117000579834,0],[11.141039848327637,-2.548830032348633,0],[10.830659866333008,-2.579400062561035,0],[10.830659866333008,-2.722909927368164,0]],
[[11.141039848327637,-1.9752000570297241,0],[10.830659866333008,-1.8466399908065796,0],[10.830659866333008,-2.005079984664917,0],[11.141039848327637,-2.0992300510406494,0],[11.141039848327637,-1.9752000570297241,0]],
[[11.078660011291504,5.662519931793213,0],[10.830789566040039,6.12624979019165,0],[10.830659866333008,6.12624979019165,0],[11.078660011291504,5.6622700691223145,0],[11.078660011291504,5.662519931793213,0]],
[[10.830659866333008,5.888959884643555,0],[10.732370376586914,6.12624979019165,0],[9.795860290527344,6.12624979019165,0],[10.830659866333008,4.577569961547852,0],[10.830659866333008,5.888959884643555,0]],
[[10.830659866333008,4.577569961547852,0],[9.795860290527344,6.12624979019165,0],[-6.278890132904053,6.12624979019165,0],[10.830659866333008,2.722909927368164,0],[10.830659866333008,4.577569961547852,0]],
[[-11.078660011291504,-5.662519931793213,0],[-10.830789566040039,-6.12624979019165,0],[-10.830659866333008,-6.12624979019165,0],[-11.078660011291504,-5.6622700691223145,0],[-11.078660011291504,-5.662519931793213,0]],
[[-10.830659866333008,-4.712800025939941,0],[-11.141039848327637,-4.743370056152344,0],[-11.141039848327637,-5.5455498695373535,0],[-10.830659866333008,-6.126239776611328,0],[-10.830659866333008,-4.712800025939941,0]],
[[10.830659866333008,-1.8466399908065796,0],[-8.41765022277832,6.12624979019165,0],[-10.830659866333008,6.12624979019165,0],[-11.141039848327637,5.545559883117676,0],[-11.141039848327637,4.659939765930176,0],[10.830659866333008,-2.005079984664917,0],[10.830659866333008,-1.8466399908065796,0]],
[[-6.279160022735596,-6.12624979019165,0],[10.830659866333008,-2.722909927368164,0],[10.830659866333008,-2.579400062561035,0],[-10.830659866333008,-4.712800025939941,0],[-10.830659866333008,-6.126239776611328,0],[-6.279160022735596,-6.12624979019165,0]]]
}
}]
}
29 changes: 29 additions & 0 deletions test/fixtures/issue102.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[[34, 119],
[20, 20],
[132, 141],
[34, 119]]
]
}
},{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[[27.681744389656238, 74.32090675542626],
[25.1362898442017, 56.3209067554263],
[35.67034343592924, 56.32090675542627],
[35.67034343592924, 74.32090675542624],
[27.681744389656238, 74.32090675542626]]
]
}
}]
}
18 changes: 18 additions & 0 deletions test/fixtures/issue103.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-24.820450799231946, 81.60424965743837],[-66.98439939287994, 65.9251157774066],[-67.17837257682962, 65.5743714314538],[-23.564139586577383, 84.46172863817043],[-35.3782801119441, 162.91715665949576],[-37.42674770001716, 159.79423125392117], [-24.820450799231946, 81.60424965743837]]]
}
},{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-23.564139586577383, 84.46172863817043],[-67.17837257682962, 65.5743714314538],[-24.85941638876879, 26.87535085545798],[-23.564139586577383, 84.46172863817043]]]
}
}]
}
18 changes: 18 additions & 0 deletions test/fixtures/issue110.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[115,96], [140,206], [120,210], [125,250], [80,300]]]
}
},{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[111,228], [129,192], [309,282]]]
}
}]
}
18 changes: 18 additions & 0 deletions test/fixtures/issue90.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[ [0,0],[10,0],[10,10],[0,10] ]]
}
},{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[ [9,10],[21,9],[21,21],[9,21] ]]
}
}]
}
12 changes: 12 additions & 0 deletions test/fixtures/issue99.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": { "type": "Polygon", "coordinates": [[[ -530, -530], [-530, 530], [530, 530], [530, -530], [ -530, -530]]] }
},{
"type": "Feature",
"properties": {},
"geometry": { "type": "Polygon", "coordinates": [[[1.2500125250252, -531],[-98, -531],[-98, 531],[1.250012525025, 531],[1.2500125250252, -531]]] }
}]
}

0 comments on commit 245c8d4

Please sign in to comment.