-
Notifications
You must be signed in to change notification settings - Fork 2
/
domain.go
65 lines (54 loc) · 1.36 KB
/
domain.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
package cirno
// domain contains all the
// quad tree nodes the shape
// belongs to.
type domain struct {
treeNodes []*quadTreeNode
}
// nodes returns all the quad tree nodes the shape
// belongs to.
func (d *domain) nodes() []*quadTreeNode {
nodes := make([]*quadTreeNode, len(d.treeNodes))
copy(nodes, d.treeNodes)
return nodes
}
// addNodes adds new nodes in the list of the nodes
// the shape belongs to.
func (d *domain) addNodes(nodes ...*quadTreeNode) {
d.treeNodes = append(d.treeNodes, nodes...)
}
// containsNode returns true if the node is included
// in the shape's domain, and false otherwise.
func (d *domain) containsNode(node *quadTreeNode) bool {
for _, treeNode := range d.treeNodes {
if treeNode == node {
return true
}
}
return false
}
// removeNodes removes the quad tree nodes from
// the list of the nodes the shape belongs to.
//
// This method does nothing if the node
// is not included in the shape's domain.
func (d *domain) removeNodes(nodes ...*quadTreeNode) {
for _, node := range nodes {
index := -1
for i, treeNode := range d.treeNodes {
if treeNode == node {
index = i
break
}
}
if index >= 0 {
d.treeNodes = append(d.treeNodes[:index],
d.treeNodes[index+1:]...)
}
}
}
// clearNodes removes all the nodes
// from the shape's domain.
func (d *domain) clearNodes() {
d.treeNodes = []*quadTreeNode{}
}