-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkobj.go
More file actions
37 lines (32 loc) · 671 Bytes
/
kobj.go
File metadata and controls
37 lines (32 loc) · 671 Bytes
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
package rtree
import (
"fmt"
"github.com/intdxdt/math"
"github.com/intdxdt/mbr"
)
// KObj instance struct
type KObj struct {
node *node
MBR *mbr.MBR[float64]
IsItem bool
Dist float64
}
func (kobj *KObj) GetItem() BoxObject {
return kobj.node.item
}
// String representation of knn object
func (kobj *KObj) String() string {
return fmt.Sprintf("%v -> %v", kobj.node.bbox.String(), kobj.Dist)
}
// Compare - cmp interface
func kobjCmp(a interface{}, b interface{}) int {
var self, other = a.(*KObj), b.(*KObj)
var dx = self.Dist - other.Dist
var r = 1
if dx == 0 || math.Abs(dx) < math.EPSILON {
r = 0
} else if dx < 0 {
r = -1
}
return r
}