-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.go
79 lines (60 loc) · 1.4 KB
/
point.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
78
79
package common
import (
"github.com/bozso/emath/geometry"
"github.com/bozso/gotoolbox/errors"
"github.com/bozso/gomma/utils/params"
)
type AOI [4]geometry.LatLon
type MinOrMax int
const (
Min MinOrMax = iota
Max
)
type LatLonRegion struct {
Max geometry.LatLon `json:"max"`
Min geometry.LatLon `json:"min"`
}
func (ll LatLonRegion) Contains(l geometry.LatLon) (b bool) {
return ll.ToRegion().Contains(l.ToPoint())
}
func (ll LatLonRegion) ToRegion() (r geometry.Region) {
r.Max, r.Min = ll.Max.ToPoint(), ll.Min.ToPoint()
return
}
func ParseRegion(info params.Parser) (r LatLonRegion, err error) {
r.Max, err = Max.Parse(info)
if err != nil {
return
}
r.Min, err = Min.Parse(info)
return
}
func (mode MinOrMax) Parse(info params.Parser) (p geometry.LatLon, err error) {
var tpl_lon, tpl_lat string
switch mode {
case Max:
tpl_lon, tpl_lat = "Max_Lon", "Max_Lat"
case Min:
tpl_lon, tpl_lat = "Min_Lon", "Min_Lat"
}
if p.Lon, err = info.Float(tpl_lon, 0); err != nil {
err = ParseError{"longitude", err}
return
}
if p.Lat, err = info.Float(tpl_lat, 0); err != nil {
err = ParseError{"latitude", err}
return
}
return
}
type ParseError struct {
coordinate string
err error
}
func (e ParseError) Error() string {
const msg errors.String = "failed to retreive %s value"
return msg.WrapFmt(e.err, e.coordinate).Error()
}
func (e ParseError) Unwrap() error {
return e.err
}