-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbbox.go
More file actions
69 lines (50 loc) · 1.18 KB
/
bbox.go
File metadata and controls
69 lines (50 loc) · 1.18 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
60
61
62
63
64
65
66
67
68
69
package geov
import geo "github.com/kellydunn/golang-geo"
type boundingBox struct {
minLat *float64
minLon *float64
maxLat *float64
maxLon *float64
}
func (bb *boundingBox) UpperPoint() (float64, float64, error) {
if bb.maxLat == nil || bb.maxLon == nil {
return 0, 0, ErrInvalidBoundingBox
}
return *bb.maxLat, *bb.maxLon, nil
}
func (bb *boundingBox) LowerPoint() (float64, float64, error) {
if bb.minLat == nil || bb.minLon == nil {
return 0, 0, ErrInvalidBoundingBox
}
return *bb.minLat, *bb.minLon, nil
}
func (bb *boundingBox) Expand(p *geo.Point) {
if bb.minLat == nil || p.Lat() < *bb.minLat {
tmp := p.Lat()
bb.minLat = &tmp
}
if bb.maxLat == nil || p.Lat() > *bb.maxLat {
tmp := p.Lat()
bb.maxLat = &tmp
}
if bb.minLon == nil || p.Lng() < *bb.minLon {
tmp := p.Lng()
bb.minLon = &tmp
}
if bb.maxLon == nil || p.Lng() > *bb.maxLon {
tmp := p.Lng()
bb.maxLon = &tmp
}
}
func (bb *boundingBox) LatRange() float64 {
if bb.maxLat == nil || bb.minLat == nil {
return 0
}
return *bb.maxLat - *bb.minLat
}
func (bb *boundingBox) LonRange() float64 {
if bb.maxLon == nil || bb.minLon == nil {
return 0
}
return *bb.maxLon - *bb.minLon
}