Skip to content

Commit

Permalink
Lines with a 180 degree angle between them should be considered paral…
Browse files Browse the repository at this point in the history
…lel (`turf-boolean-parallel`) (#2475)

* Lines with a 180 degree angle between them are considered parallel

* Add simple verticals test

* Add failing test case for 3d lines

* Fix verticals 3d test
  • Loading branch information
mracette authored Sep 19, 2023
1 parent cf7a0c5 commit cc6689a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/turf-boolean-parallel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function booleanParallel(
function isParallel(segment1: Position[], segment2: Position[]) {
var slope1 = bearingToAzimuth(rhumbBearing(segment1[0], segment1[1]));
var slope2 = bearingToAzimuth(rhumbBearing(segment2[0], segment2[1]));
return slope1 === slope2;
return slope1 === slope2 || (slope2 - slope1) % 180 === 0;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/turf-boolean-parallel/test/true/opposites.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[0, 0],
[1, 0]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[1, 0],
[0, 0]
]
}
}
]
}
27 changes: 27 additions & 0 deletions packages/turf-boolean-parallel/test/true/verticals.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[0, 0],
[0, 1]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[1, 0],
[1, 1]
]
}
}
]
}
27 changes: 27 additions & 0 deletions packages/turf-boolean-parallel/test/true/verticals3d.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-10, 20, 0],
[-10, 10, 0]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-20, 20, 0],
[-20, 10, 0]
]
}
}
]
}

0 comments on commit cc6689a

Please sign in to comment.