1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package s2
16
17 import (
18 "testing"
19 )
20
21 func TestLaxPolylineNoVertices(t *testing.T) {
22 shape := Shape(LaxPolylineFromPoints([]Point{}))
23
24 if got, want := shape.NumEdges(), 0; got != want {
25 t.Errorf("shape.NumEdges() = %v, want %v", got, want)
26 }
27 if got, want := shape.NumChains(), 0; got != want {
28 t.Errorf("shape.NumChains() = %v, want %v", got, want)
29 }
30 if got, want := shape.Dimension(), 1; got != want {
31 t.Errorf("shape.Dimension() = %v, want %v", got, want)
32 }
33 if !shape.IsEmpty() {
34 t.Errorf("shape.IsEmpty() = false, want true")
35 }
36 if shape.IsFull() {
37 t.Errorf("shape.IsFull() = true, want false")
38 }
39 if shape.ReferencePoint().Contained {
40 t.Errorf("shape.ReferencePoint().Contained = true, want false")
41 }
42 }
43
44 func TestLaxPolylineOneVertex(t *testing.T) {
45 shape := Shape(LaxPolylineFromPoints([]Point{PointFromCoords(1, 0, 0)}))
46 if got, want := shape.NumEdges(), 0; got != want {
47 t.Errorf("shape.NumEdges() = %v, want %v", got, want)
48 }
49 if got, want := shape.NumChains(), 0; got != want {
50 t.Errorf("shape.NumChains() = %v, want %v", got, want)
51 }
52 if got, want := shape.Dimension(), 1; got != want {
53 t.Errorf("shape.Dimension() = %v, want %v", got, want)
54 }
55 if !shape.IsEmpty() {
56 t.Errorf("shape.IsEmpty() = false, want true")
57 }
58 if shape.IsFull() {
59 t.Errorf("shape.IsFull() = true, want false")
60 }
61 }
62
63 func TestLaxPolylineEdgeAccess(t *testing.T) {
64 vertices := parsePoints("0:0, 0:1, 1:1")
65 shape := Shape(LaxPolylineFromPoints(vertices))
66
67 if got, want := shape.NumEdges(), 2; got != want {
68 t.Errorf("shape.NumEdges() = %v, want %v", got, want)
69 }
70 if got, want := shape.NumChains(), 1; got != want {
71 t.Errorf("shape.NumChains() = %v, want %v", got, want)
72 }
73 if got, want := shape.Chain(0).Start, 0; got != want {
74 t.Errorf("shape.Chain(%d).Start = %d, want 0", got, want)
75 }
76 if got, want := shape.Chain(0).Length, 2; got != want {
77 t.Errorf("shape.Chain(%d).Length = %d, want 2", got, want)
78 }
79 if got, want := shape.Dimension(), 1; got != want {
80 t.Errorf("shape.Dimension() = %v, want %v", got, want)
81 }
82 if shape.IsEmpty() {
83 t.Errorf("shape.IsEmpty() = true, want false")
84 }
85 if shape.IsFull() {
86 t.Errorf("shape.IsFull() = true, want false")
87 }
88
89 edge0 := shape.Edge(0)
90 if !edge0.V0.ApproxEqual(vertices[0]) {
91 t.Errorf("shape.Edge(0).V0 = %v, want %v", edge0.V0, vertices[0])
92 }
93 if !edge0.V1.ApproxEqual(vertices[1]) {
94 t.Errorf("shape.Edge(0).V1 = %v, want %v", edge0.V1, vertices[1])
95 }
96
97 edge1 := shape.Edge(1)
98 if !edge1.V0.ApproxEqual(vertices[1]) {
99 t.Errorf("shape.Edge(1).V0 = %v, want %v", edge1.V0, vertices[1])
100 }
101 if !edge1.V1.ApproxEqual(vertices[2]) {
102 t.Errorf("shape.Edge(1).V1 = %v, want %v", edge1.V1, vertices[2])
103 }
104 }
105
106
107
108
109
110
111
View as plain text