-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.go
45 lines (38 loc) · 996 Bytes
/
space.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
package mesh
import (
"math"
"github.com/ungerik/go3d/float64/vec3"
)
type Box struct {
LowerBound, UpperBound vec3.T
}
func (this Box) BoundTriangle(tri Triangle) {
this.LowerBound = vec3.T{
math.Min(tri[0][0], math.Min(tri[0][1], tri[0][2])),
math.Min(tri[1][0], math.Min(tri[1][1], tri[1][2])),
math.Min(tri[2][0], math.Min(tri[2][1], tri[2][2])),
}
this.UpperBound = vec3.T{
math.Max(tri[0][0], math.Max(tri[0][1], tri[0][2])),
math.Max(tri[1][0], math.Max(tri[1][1], tri[1][2])),
math.Max(tri[2][0], math.Max(tri[2][1], tri[2][2])),
}
}
func (this Box) BoundTriangles(tris ...Triangle) {
if len(tris) == 0 {
return
}
this.BoundTriangle(tris[0])
for _, tri := range tris[1:] {
for vert := 0; vert < 3; vert++ {
for compon := 0; compon < 3; compon++ {
val := tri[vert][compon]
if val < this.LowerBound[compon] {
this.LowerBound[compon] = val
} else if val > this.UpperBound[compon] {
this.UpperBound[compon] = val
}
}
}
}
}