Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func (ls LineString) Dimensions() int {
// This is done inplace, ie. it modifies the original data.
func (ls LineString) Reverse() {
l := len(ls) - 1

if l < 1 {
return
}

for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
Expand Down
10 changes: 10 additions & 0 deletions line_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func TestLineStringReverse(t *testing.T) {
input LineString
output LineString
}{
{
name: "0 point line",
input: LineString{},
output: LineString{},
},
{
name: "1 point line",
input: LineString{{1, 2}},
output: LineString{{1, 2}},
},
{
name: "2 point line",
input: LineString{{1, 2}, {3, 4}},
Expand Down