-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.go
49 lines (38 loc) · 903 Bytes
/
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
package pgeo
import (
"database/sql/driver"
"github.com/volatiletech/sqlboiler/randomize"
)
// Points are the fundamental two-dimensional building block for geometric types.
// Lat and Lng are the respective coordinates, as floating-point numbers
type Point struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}
func (p Point) Value() (driver.Value, error) {
return valuePoint(p)
}
func (p *Point) Scan(src interface{}) error {
return scanPoint(p, src)
}
func valuePoint(p Point) (driver.Value, error) {
return formatPoint(p), nil
}
func scanPoint(p *Point, src interface{}) error {
if src == nil {
*p = NewPoint(0, 0)
return nil
}
val, err := iToS(src)
if err != nil {
return err
}
*p, err = parsePoint(val)
if err != nil {
return err
}
return nil
}
func (o *Point) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
*o = NewRandPoint()
}