Skip to content

Commit 7627dc6

Browse files
authored
fix reverse of empty linestrings (#163)
Signed-off-by: Jochen.Mehlhorn <jochen.mehlhorn@mercedes-benz.com>
1 parent 1701d30 commit 7627dc6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

line_string.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ func (ls LineString) Dimensions() int {
1717
// This is done inplace, ie. it modifies the original data.
1818
func (ls LineString) Reverse() {
1919
l := len(ls) - 1
20+
21+
if l < 1 {
22+
return
23+
}
24+
2025
for i := 0; i <= l/2; i++ {
2126
ls[i], ls[l-i] = ls[l-i], ls[i]
2227
}

line_string_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ func TestLineStringReverse(t *testing.T) {
2020
input LineString
2121
output LineString
2222
}{
23+
{
24+
name: "0 point line",
25+
input: LineString{},
26+
output: LineString{},
27+
},
28+
{
29+
name: "1 point line",
30+
input: LineString{{1, 2}},
31+
output: LineString{{1, 2}},
32+
},
2333
{
2434
name: "2 point line",
2535
input: LineString{{1, 2}, {3, 4}},

0 commit comments

Comments
 (0)