forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring_test.go
87 lines (81 loc) · 1.64 KB
/
ring_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package orb
import (
"testing"
)
func TestRing_Closed(t *testing.T) {
cases := []struct {
name string
ring Ring
closed bool
}{
{
name: "first must equal last",
ring: Ring{{0, 0}, {3, 0}, {3, 4}, {0, 0}},
closed: true,
},
{
name: "not closed if last point does not match",
ring: Ring{{0, 0}, {3, 0}, {3, 3}, {3, 4}},
closed: false,
},
{
name: "empty ring",
ring: Ring{},
closed: false,
},
{
name: "one vertex ring",
ring: Ring{{3, 0}},
closed: false,
},
{
name: "two vertex ring",
ring: Ring{{3, 0}, {3, 0}},
closed: false,
},
{
name: "three vertex ring",
ring: Ring{{3, 0}, {0, 0}, {3, 0}},
closed: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if v := tc.ring.Closed(); v != tc.closed {
t.Errorf("incorrect: %v != %v", v, tc.closed)
}
})
}
}
func TestRing_Orientation(t *testing.T) {
cases := []struct {
name string
ring Ring
result Orientation
}{
{
name: "simple box, ccw",
ring: Ring{{0, 0}, {0.001, 0}, {0.001, 0.001}, {0, 0.001}, {0, 0}},
result: CCW,
},
{
name: "simple box, cw",
ring: Ring{{0, 0}, {0, 0.001}, {0.001, 0.001}, {0.001, 0}, {0, 0}},
result: CW,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
val := tc.ring.Orientation()
if val != tc.result {
t.Errorf("wrong orientation: %v != %v", val, tc.result)
}
// should work without redudant last point.
ring := tc.ring[:len(tc.ring)-1]
val = ring.Orientation()
if val != tc.result {
t.Errorf("wrong orientation: %v != %v", val, tc.result)
}
})
}
}