-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindexable.go
74 lines (61 loc) · 1.43 KB
/
indexable.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
package spatial
import "github.com/dhconnelly/rtreego"
// IndexableType is a type for enums describing types of objects in index tree.
// Negative numbers are reserved for internal use
type IndexableType int
const (
itBoundingBox IndexableType = -1
)
// Indexable interface
type Indexable interface {
rtreego.Spatial
ID() string
Ref() interface{}
Type() IndexableType
}
// Object is an Indexable implementation helper type
type Object struct {
id string
ref interface{}
bounds *rtreego.Rect
meta map[string]string
objType IndexableType
}
// ID implements Indexable
func (o *Object) ID() string {
return o.id
}
// Bounds implements Indexable
func (o *Object) Bounds() *rtreego.Rect {
return o.bounds
}
// Ref implements Indexable
func (o *Object) Ref() interface{} {
return o.ref
}
// Type implements Indexable
func (o *Object) Type() IndexableType {
return o.objType
}
// Meta is Object meta getter
func (o *Object) Meta(key string) string {
return o.meta[key]
}
// HasMetaKey is Object meta key checker
func (o *Object) HasMetaKey(key string) bool {
_, found := o.meta[key]
return found
}
// NewObject creates a new instance of Object
func NewObject(id string, objType IndexableType, bounds *rtreego.Rect, ref interface{}, meta map[string]string) *Object {
if meta == nil {
meta = make(map[string]string)
}
return &Object{
id: id,
objType: objType,
bounds: bounds,
ref: ref,
meta: meta,
}
}