-
Notifications
You must be signed in to change notification settings - Fork 33
/
spatialIndex.go
77 lines (58 loc) · 1.54 KB
/
spatialIndex.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
package chipmunk
import (
"github.com/vova616/chipmunk/vect"
"time"
)
type SpatialIndexQueryFunc func(a, b Indexable)
type ReindexShapesFunc func(a, b *Shape, space *Space)
type HashSetIterator func(node *Node)
type TreeType byte
type SpatialIndex struct {
SpatialIndexClass
staticIndex, dynamicIndex SpatialIndexClass
}
func SpatialIndexCollideStatic(dynamicIndex, staticIndex *SpatialIndex, fnc SpatialIndexQueryFunc) {
if staticIndex.Count() > 0 {
dynamicIndex.Each(func(node *Node) {
staticIndex.Query(node.obj, node.obj.AABB(), fnc)
})
}
}
func NewSpartialIndex(class SpatialIndexClass, staticIndex *SpatialIndex) (index *SpatialIndex) {
if staticIndex != nil {
index = &SpatialIndex{class, staticIndex.SpatialIndexClass, nil}
} else {
index = &SpatialIndex{class, nil, nil}
}
if staticIndex != nil {
if staticIndex.dynamicIndex != nil {
panic("This static index is already associated with a dynamic index.")
}
staticIndex.dynamicIndex = index
}
return
}
type Indexable interface {
Hashable
AABB() AABB
Shape() *Shape
Velocity() (vect.Vect, bool)
}
type Data interface{}
type Hashable interface {
Hash() HashValue
}
type SpatialIndexClass interface {
Destroy()
Count() int
Each(fnc HashSetIterator)
Contains(obj Indexable) bool
Insert(obj Indexable)
Remove(obj Indexable)
Reindex()
ReindexObject(obj Indexable)
ReindexQuery(fnc SpatialIndexQueryFunc)
Stamp() time.Duration
Query(obj Indexable, aabb AABB, fnc SpatialIndexQueryFunc)
SegmentQuery(obj Indexable, a, b vect.Vect, t_exit vect.Float, fnc func())
}