forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaths_windingorder_test.go
52 lines (45 loc) · 1.37 KB
/
maths_windingorder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package maths_test
import (
"testing"
"github.com/gdey/tbltest"
"github.com/go-spatial/tegola/basic"
"github.com/go-spatial/tegola/maths"
)
func invertPoints(pts []float64) (rpts []float64) {
rpts = append(rpts, pts[0], pts[1])
for x, y := len(pts)-2, len(pts)-1; x > 0; x, y = x-2, y-2 {
rpts = append(rpts, pts[x], pts[y])
}
return rpts
}
func TestWindingOrderOf(t *testing.T) {
type testcase struct {
points []float64
expected maths.WindingOrder
}
tests := tbltest.Cases(
testcase{
points: []float64{4, 2, 2, 4, 2, 6, 3, 7, 5, 8, 7, 7, 8, 5, 8, 3, 6, 2},
expected: maths.CounterClockwise,
},
)
tests.Run(func(idx int, test testcase) {
got := maths.WindingOrderOf(test.points)
if got != test.expected {
t.Errorf("Test %v: Failed expected %v got %v", idx, test.expected, got)
}
got = maths.WindingOrderOfLine(basic.NewLine(test.points...))
if got != test.expected {
t.Errorf("Test %v: Failed for Line expected %v got %v", idx, test.expected, got)
}
ipts := invertPoints(test.points)
got = maths.WindingOrderOf(ipts)
if got != test.expected.Not() {
t.Errorf("Test %v Inverted: Failed expected %v got %v", idx, test.expected.Not(), got)
}
got = maths.WindingOrderOfLine(basic.NewLine(ipts...))
if got != test.expected.Not() {
t.Errorf("Test %v Inverted: Failed for Line expected %v got %v", idx, test.expected.Not(), got)
}
})
}