-
Notifications
You must be signed in to change notification settings - Fork 4
/
pointcloud_test.go
159 lines (149 loc) · 3.42 KB
/
pointcloud_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package main
import (
"reflect"
"testing"
"github.com/seqsense/pcgol/mat"
"github.com/seqsense/pcgol/pc"
)
func TestTransformedVec3RandomAccessor(t *testing.T) {
in := pc.Vec3Slice{
{1, 2, 3},
{2, 3, 4},
{3, 4, 5},
}
ra := &transformedVec3RandomAccessor{
Vec3RandomAccessor: in,
trans: mat.Translate(1, -2, -4),
}
expected := pc.Vec3Slice{
{2, 0, -1},
{3, 1, 0},
{4, 2, 1},
}
if ra.Len() != in.Len() {
t.Fatalf("Input and output length must be same, in: %d, out: %d", in.Len(), ra.Len())
}
for i, e := range expected {
v := ra.Vec3At(i)
if !e.Equal(v) {
t.Errorf("Expected Vec3At(%d): %v, got: %v", i, e, v)
}
}
}
func TestRectIntersection(t *testing.T) {
testCases := map[string]struct {
a, b rect
expected rect
}{
"ABottomRight": {
a: rect{mat.Vec3{1, 2, 3}, mat.Vec3{5, 6, 7}},
b: rect{mat.Vec3{4, 5, 6}, mat.Vec3{7, 8, 9}},
expected: rect{mat.Vec3{4, 5, 6}, mat.Vec3{5, 6, 7}},
},
"Mixed": {
a: rect{mat.Vec3{1, 2, 3}, mat.Vec3{5, 6, 7}},
b: rect{mat.Vec3{4, 3, 2}, mat.Vec3{6, 4, 10}},
expected: rect{mat.Vec3{4, 3, 3}, mat.Vec3{5, 4, 7}},
},
"NoOverlap": {
a: rect{mat.Vec3{1, 2, 3}, mat.Vec3{3, 4, 5}},
b: rect{mat.Vec3{6, 7, 8}, mat.Vec3{9, 10, 11}},
expected: rect{mat.Vec3{6, 7, 8}, mat.Vec3{3, 4, 5}},
},
}
for name, tt := range testCases {
tt := tt
t.Run(name, func(t *testing.T) {
t.Run("Forward", func(t *testing.T) {
out := rectIntersection(tt.a, tt.b)
if !reflect.DeepEqual(tt.expected, out) {
t.Errorf("Expected rect: %v, got: %v", tt.expected, out)
}
})
t.Run("Reverse", func(t *testing.T) {
out := rectIntersection(tt.b, tt.a)
if !reflect.DeepEqual(tt.expected, out) {
t.Errorf("Expected rect: %v, got: %v", tt.expected, out)
}
})
})
}
}
func TestRect(t *testing.T) {
type insideCheck struct {
p mat.Vec3
inside bool
}
testCases := map[string]struct {
r rect
valid bool
insideCheck map[string]insideCheck
}{
"Valid": {
r: rect{mat.Vec3{4, 5, 6}, mat.Vec3{5, 6, 7}},
valid: true,
insideCheck: map[string]insideCheck{
"Inside": {
p: mat.Vec3{4.5, 5.6, 6.7},
inside: true,
},
"Outside1": {
p: mat.Vec3{3.5, 5.6, 6.7},
inside: false,
},
"Outside2": {
p: mat.Vec3{5.5, 5.6, 6.7},
inside: false,
},
"Outside3": {
p: mat.Vec3{4.5, 6.6, 6.7},
inside: false,
},
"Outside4": {
p: mat.Vec3{4.5, 5.6, 7.7},
inside: false,
},
},
},
"InValid": {
r: rect{mat.Vec3{6, 7, 8}, mat.Vec3{3, 4, 5}},
valid: false,
insideCheck: map[string]insideCheck{
"BetweenRects": {
p: mat.Vec3{4, 5, 6},
inside: false,
},
"Outside": {
p: mat.Vec3{10, 10, 10},
inside: false,
},
},
},
}
for name, tt := range testCases {
tt := tt
t.Run(name, func(t *testing.T) {
ok := tt.r.IsValid()
if ok != tt.valid {
if tt.valid {
t.Error("Expected to be valid")
} else {
t.Error("Expected to be invalid")
}
}
for name, ic := range tt.insideCheck {
ic := ic
t.Run(name, func(t *testing.T) {
inside := tt.r.IsInside(ic.p)
if inside != ic.inside {
if ic.inside {
t.Errorf("%v is expected to be inside", ic.p)
} else {
t.Errorf("%v is expected to be outside", ic.p)
}
}
})
}
})
}
}