-
Notifications
You must be signed in to change notification settings - Fork 55
/
path_resample_test.go
121 lines (99 loc) · 2.75 KB
/
path_resample_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package geo
import "testing"
func TestPathResample(t *testing.T) {
p := NewPath()
p.Resample(10) // should not panic
p.Push(NewPoint(0, 0)).Resample(10) // should not panic
p.Push(NewPoint(1.5, 1.5))
p.Push(NewPoint(2, 2))
// resample to 0?
result := p.Clone().Resample(0)
if result.Length() != 0 {
t.Error("path, resample down to zero should be empty line")
}
// resample to 1
result = p.Clone().Resample(1)
answer := NewPath().Push(NewPoint(0, 0))
if !result.Equals(answer) {
t.Error("path, resample down to 1 should be first point")
}
result = p.Clone().Resample(2)
answer = NewPath().Push(NewPoint(0, 0)).Push(NewPoint(2, 2))
if !result.Equals(answer) {
t.Error("path, resample downsampling")
}
result = p.Clone().Resample(5)
answer = NewPath()
answer.Push(NewPoint(0, 0)).Push(NewPoint(0.5, 0.5))
answer.Push(NewPoint(1, 1)).Push(NewPoint(1.5, 1.5))
answer.Push(NewPoint(2, 2))
if !result.Equals(answer) {
t.Error("path, resample upsampling")
t.Error(result)
t.Error(answer)
}
// round off error case, triggered on my laptop
p1 := NewPath().Push(NewPoint(-88.145243, 42.321059)).Push(NewPoint(-88.145232, 42.325902))
p1.Resample(109)
if p1.Length() != 109 {
t.Errorf("path, resample incorrect length, expected 109, got %d", p1.Length())
}
// duplicate points
p = NewPath()
p.Push(NewPoint(1, 0))
p.Push(NewPoint(1, 0))
p.Push(NewPoint(1, 0))
p.Resample(10)
if l := p.Length(); l != 10 {
t.Errorf("path, resample length incorrect, got %d", l)
}
for i := 0; i < p.Length(); i++ {
if !p.GetAt(i).Equals(NewPoint(1, 0)) {
t.Errorf("path, resample not correct point, got %v", p.GetAt(i))
}
}
}
func TestPathResampleWithInterval(t *testing.T) {
p := NewPath()
p.Push(NewPoint(0, 0))
p.Push(NewPoint(0, 10))
p.ResampleWithInterval(5.0)
if l := p.Length(); l != 3 {
t.Errorf("incorrect resample, got %v", l)
}
if v := p.GetAt(1); !v.Equals(NewPoint(0, 5.0)) {
t.Errorf("incorrect point, got %v", v)
}
}
func TestPathResampleWithGeoInterval(t *testing.T) {
p := NewPath()
p.Push(NewPoint(0, 0))
p.Push(NewPoint(0, 10))
d := p.GeoDistance() / 2
p.ResampleWithGeoInterval(d)
if l := p.Length(); l != 3 {
t.Errorf("incorrect resample, got %v", l)
}
if v := p.GetAt(1); !v.Equals(NewPoint(0, 5.0)) {
t.Errorf("incorrect point, got %v", v)
}
}
func TestPathResampleEdgeCases(t *testing.T) {
p := NewPath()
p.Push(NewPoint(0, 0))
if !p.resampleEdgeCases(10) {
t.Errorf("should return false")
}
// duplicate points
p.Push(NewPoint(0, 0))
if !p.resampleEdgeCases(10) {
t.Errorf("should return true")
}
if l := p.Length(); l != 10 {
t.Errorf("should reset to suggested points, got %v", l)
}
p.resampleEdgeCases(5)
if l := p.Length(); l != 5 {
t.Errorf("should shorten if necessary, got %v", l)
}
}