-
Notifications
You must be signed in to change notification settings - Fork 3
/
geom.go
84 lines (70 loc) · 1.35 KB
/
geom.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
package htm
import (
"github.com/azul3d/engine/lmath"
)
type Sign int
const (
Negative Sign = iota
Zero
Positive
Mixed
)
type Coverage int
const (
Inside Coverage = iota
Partial
Outside
)
type Tester interface {
Test(v0, v1, v2 lmath.Vec3) Coverage
}
// Constraint is a circular area, given by the plane slicing it off the sphere.
type Constraint struct {
P lmath.Vec3
D float64
}
func (c *Constraint) Test(v0, v1, v2 lmath.Vec3) Coverage {
a0 := c.P.Dot(v0) > c.D
a1 := c.P.Dot(v1) > c.D
a2 := c.P.Dot(v2) > c.D
if a0 && a1 && a2 {
return Inside
} else if a0 || a1 || a2 {
return Partial
} else {
// TODO(d) finish test as this is not definitive.
return Outside
}
}
// Convex is a combination of constraints (logical AND of constraints).
type Convex []*Constraint
func (c Convex) Test(v0, v1, v2 lmath.Vec3) Coverage {
r := Inside
for _, cn := range c {
cv := cn.Test(v0, v1, v2)
if cv == Outside {
return Outside
} else if cv == Partial {
r = Partial
}
}
return r
}
func (c Convex) Sign() Sign {
// TODO(d) ...
return Zero
}
// Domain is several convexes (logical OR of convexes).
type Domain []*Convex
func (d Domain) Test(v0, v1, v2 lmath.Vec3) Coverage {
r := Outside
for _, cv := range d {
t := cv.Test(v0, v1, v2)
if t == Inside {
return Inside
} else if t == Partial {
r = Partial
}
}
return r
}