-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert self intersection behavior: line-intersect
#2742
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,9 @@ import path from "path"; | |
import { loadJsonFileSync } from "load-json-file"; | ||
import { writeJsonFileSync } from "write-json-file"; | ||
import { truncate } from "@turf/truncate"; | ||
import { | ||
featureCollection, | ||
// geometryCollection, | ||
lineString, | ||
polygon, | ||
} from "@turf/helpers"; | ||
import { featureCollection, lineString, polygon } from "@turf/helpers"; | ||
import { lineIntersect } from "./index.js"; | ||
import { Feature, LineString, Point } from "geojson"; | ||
|
||
const directories = { | ||
in: path.join("test", "in") + path.sep, | ||
|
@@ -21,14 +17,18 @@ const fixtures = fs.readdirSync(directories.in).map((filename) => { | |
return { | ||
filename, | ||
name: path.parse(filename).name, | ||
geojson: loadJsonFileSync(directories.in + filename), | ||
geojson: loadJsonFileSync( | ||
directories.in + filename | ||
) as GeoJSON.FeatureCollection<LineString>, | ||
}; | ||
}); | ||
|
||
test("turf-line-intersect", (t) => { | ||
for (const { filename, name, geojson } of fixtures) { | ||
const [line1, line2] = geojson.features; | ||
const results = truncate(lineIntersect(line1, line2)); | ||
const results: GeoJSON.FeatureCollection<LineString | Point> = truncate( | ||
lineIntersect(line1, line2) | ||
); | ||
results.features.push(line1); | ||
results.features.push(line2); | ||
|
||
|
@@ -132,3 +132,48 @@ test("turf-line-intersect - polygon support #586", (t) => { | |
t.equal(results.features.length, 1, "should return single point"); | ||
t.end(); | ||
}); | ||
|
||
test("turf-line-intersect - self intersection behavior", (t) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there advantages to running the same features through both "in code" and as in/out fixture tests? Would you mind adding some simple tests for MultiLineString, Polygon, and MultiPolygon as well e.g. To be honest I'm not sure what the expected behaviour of those are. Should ignoreSelfIntersections apply to the entire MultiLineString, or only take effect within each individual LineString? If you're got the time let's take this opportunity to embed whatever the behaviour is into some baseline tests. |
||
const line1: Feature<LineString> = { | ||
type: "Feature", | ||
properties: {}, | ||
geometry: { | ||
type: "LineString", | ||
coordinates: [ | ||
[0, 0], | ||
[0, 2], | ||
[2, 1], | ||
[-1, 1], | ||
], | ||
}, | ||
}; | ||
const line2: Feature<LineString> = { | ||
type: "Feature", | ||
properties: {}, | ||
geometry: { | ||
type: "LineString", | ||
coordinates: [ | ||
[3, 3], | ||
[4, 4], | ||
[5, 5], | ||
], | ||
}, | ||
}; | ||
|
||
const ignored = lineIntersect(line1, line2); | ||
t.equal( | ||
ignored.features.length, | ||
0, | ||
"self intersections should be ignored by default" | ||
); | ||
|
||
const included = lineIntersect(line1, line2, { | ||
ignoreSelfIntersections: false, | ||
}); | ||
t.equal( | ||
included.features.length, | ||
1, | ||
"self intersections should be included when ignoreSelfIntersections set to false" | ||
); | ||
t.end(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[0, 0], | ||
[0, 2], | ||
[2, 1], | ||
[-1, 1] | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[3, 3], | ||
[4, 4], | ||
[5, 5] | ||
] | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[0, 0], | ||
[0, 2], | ||
[2, 1], | ||
[-1, 1] | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[3, 3], | ||
[4, 4], | ||
[5, 5] | ||
] | ||
} | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add (default
true
) - JSDoc appends that automatically. See generated README.md where it gets repeated.