-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpointcloud.go
76 lines (66 loc) · 1.26 KB
/
pointcloud.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
package main
import (
"github.com/seqsense/pcgol/mat"
"github.com/seqsense/pcgol/pc"
)
type transformedVec3RandomAccessor struct {
pc.Vec3RandomAccessor
trans mat.Mat4
}
func (a *transformedVec3RandomAccessor) Vec3At(i int) mat.Vec3 {
return a.trans.TransformAffine(a.Vec3RandomAccessor.Vec3At(i))
}
func vec3Min(a, b mat.Vec3) mat.Vec3 {
var out mat.Vec3
for i := range out {
if a[i] < b[i] {
out[i] = a[i]
} else {
out[i] = b[i]
}
}
return out
}
func float32Min(a, b float32) float32 {
if a < b {
return a
}
return b
}
func float32Max(a, b float32) float32 {
if a > b {
return a
}
return b
}
type rect struct {
min, max mat.Vec3
}
func rectIntersection(a, b rect) rect {
r := rect{
min: mat.Vec3{
float32Max(a.min[0], b.min[0]),
float32Max(a.min[1], b.min[1]),
float32Max(a.min[2], b.min[2]),
},
max: mat.Vec3{
float32Min(a.max[0], b.max[0]),
float32Min(a.max[1], b.max[1]),
float32Min(a.max[2], b.max[2]),
},
}
return r
}
func (r *rect) IsValid() bool {
return !(r.min[0] > r.max[0] ||
r.min[1] > r.max[1] ||
r.min[2] > r.max[2])
}
func (r *rect) IsInside(v mat.Vec3) bool {
return !(v[0] < r.min[0] ||
v[1] < r.min[1] ||
v[2] < r.min[2] ||
r.max[0] < v[0] ||
r.max[1] < v[1] ||
r.max[2] < v[2])
}