Skip to content

Commit f17fc88

Browse files
Add fix for short linestrings (#2432)
Co-authored-by: James Beard <james@smallsaucepan.com>
1 parent a8de40d commit f17fc88

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

packages/turf-clean-coords/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ function cleanLine(line: Position[], type: string) {
142142
throw new Error("invalid polygon");
143143
}
144144

145+
if (type === "LineString" && newPointsLength < 3) {
146+
return newPoints;
147+
}
148+
145149
if (
146150
isPointOnLineSegment(
147151
newPoints[newPointsLength - 3],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "Feature",
3+
"properties": {},
4+
"geometry": {
5+
"type": "LineString",
6+
"coordinates": [
7+
[0, 0],
8+
[0, 0],
9+
[0, 2]
10+
]
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "Feature",
3+
"properties": {},
4+
"geometry": {
5+
"type": "LineString",
6+
"coordinates": [
7+
[0, 0],
8+
[0, 2]
9+
]
10+
}
11+
}

0 commit comments

Comments
 (0)