-
Notifications
You must be signed in to change notification settings - Fork 12
/
singularities.go
54 lines (50 loc) · 1.13 KB
/
singularities.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
package toolbox3d
import "github.com/unixpickle/model3d/model3d"
func singularVertexFamilies(m *model3d.Mesh, v model3d.Coord3D) [][]*model3d.Triangle {
var families [][]*model3d.Triangle
tris := m.Find(v)
for len(tris) > 0 {
var family []*model3d.Triangle
family, tris = singularVertexNextFamily(m, tris)
families = append(families, family)
}
return families
}
func singularVertexNextFamily(m *model3d.Mesh, tris []*model3d.Triangle) (family,
leftover []*model3d.Triangle) {
// See mesh.SingularVertices() for an explanation of
// this algorithm.
queue := make([]int, len(tris))
queue[0] = 1
changed := true
numVisited := 1
for changed {
changed = false
for i, status := range queue {
if status != 1 {
continue
}
t := tris[i]
for j, t1 := range tris {
if queue[j] == 0 && t.SharesEdge(t1) {
queue[j] = 1
numVisited++
changed = true
}
}
queue[i] = 2
}
}
if numVisited == len(tris) {
return tris, nil
} else {
for i, status := range queue {
if status == 0 {
leftover = append(leftover, tris[i])
} else {
family = append(family, tris[i])
}
}
return
}
}