forked from electrious-go/cluster
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpoint.go
More file actions
59 lines (51 loc) · 1.35 KB
/
Copy pathpoint.go
File metadata and controls
59 lines (51 loc) · 1.35 KB
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
package cluster
import (
"github.com/electrious-go/kdbush"
)
// Point struct that implements clustered points
//could have only one point or set of points
type Point struct {
X, Y float64
zoom int
ID int //Index for pint, Id for cluster
NumPoints int
}
// Coordinates to be compatible with interface
func (cp *Point) Coordinates() (float64, float64) {
return cp.X, cp.Y
}
// IsCluster tells you if this point is cluster or
// rather regular point
func (cp *Point) IsCluster(c *Cluster) bool {
return cp.ID >= c.clusterIdxSeed
}
// GeoCoordinates represent position in the Earth
type GeoCoordinates struct {
Lng float64
Lat float64
}
// GeoPoint interface returning lat/lng coordinates.
// All object, that you want to cluster should implement this protocol
type GeoPoint interface {
GetCoordinates() GeoCoordinates
}
//translate geopoints to Points witrh projection coordinates
func translateGeoPointsToPoints(points []GeoPoint) []*Point {
var result = make([]*Point, len(points))
for i, p := range points {
cp := Point{}
cp.zoom = InfinityZoomLevel
cp.X, cp.Y = MercatorProjection(p.GetCoordinates())
result[i] = &cp
cp.NumPoints = 1
cp.ID = i
}
return result
}
func clustersToPoints(points []*Point) []kdbush.Point {
result := make([]kdbush.Point, len(points))
for i, v := range points {
result[i] = v
}
return result
}