Ensure Points are Longitude/Latitude
This commit is contained in:
parent
27b80ceb8e
commit
f5bb7ad255
3 changed files with 19 additions and 19 deletions
|
@ -712,11 +712,11 @@ type Points []*Point
|
||||||
|
|
||||||
// Point comment
|
// Point comment
|
||||||
type Point struct {
|
type Point struct {
|
||||||
LA float64
|
|
||||||
LO float64
|
LO float64
|
||||||
|
LA float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoint(LA, LO float64) *Point {
|
func NewPoint(LO, LA float64) *Point {
|
||||||
return &Point{LA: LA, LO: LO}
|
return &Point{LA: LA, LO: LO}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ func geoPoint(ctx context.Context, args ...interface{}) (interface{}, error) {
|
||||||
return sql.NewPoint(p[0], p[1]), nil
|
return sql.NewPoint(p[0], p[1]), nil
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if lat, ok := ensureFloat(args[0]); ok {
|
if lng, ok := ensureFloat(args[0]); ok {
|
||||||
if lng, ok := ensureFloat(args[1]); ok {
|
if lat, ok := ensureFloat(args[1]); ok {
|
||||||
return sql.NewPoint(lat, lng), nil
|
return sql.NewPoint(lng, lat), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,21 +30,21 @@ func TestGeo(t *testing.T) {
|
||||||
Convey("geo.point(a, b) works properly", t, func() {
|
Convey("geo.point(a, b) works properly", t, func() {
|
||||||
res, _ = Run(context.Background(), "geo.point", "test", "test")
|
res, _ = Run(context.Background(), "geo.point", "test", "test")
|
||||||
So(res, ShouldEqual, nil)
|
So(res, ShouldEqual, nil)
|
||||||
res, _ = Run(context.Background(), "geo.point", &sql.Point{38.898556, -77.037852})
|
res, _ = Run(context.Background(), "geo.point", &sql.Point{-77.037852, 38.898556})
|
||||||
So(res, ShouldResemble, &sql.Point{38.898556, -77.037852})
|
So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556})
|
||||||
res, _ = Run(context.Background(), "geo.point", []interface{}{38.898556, -77.037852})
|
res, _ = Run(context.Background(), "geo.point", []interface{}{-77.037852, 38.898556})
|
||||||
So(res, ShouldResemble, &sql.Point{38.898556, -77.037852})
|
So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556})
|
||||||
res, _ = Run(context.Background(), "geo.point", 38.898556, -77.037852)
|
res, _ = Run(context.Background(), "geo.point", -77.037852, 38.898556)
|
||||||
So(res, ShouldResemble, &sql.Point{38.898556, -77.037852})
|
So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("geo.circle(a, b) works properly", t, func() {
|
Convey("geo.circle(a, b) works properly", t, func() {
|
||||||
res, _ = Run(context.Background(), "geo.circle", "test", "test")
|
res, _ = Run(context.Background(), "geo.circle", "test", "test")
|
||||||
So(res, ShouldEqual, nil)
|
So(res, ShouldEqual, nil)
|
||||||
res, _ = Run(context.Background(), "geo.circle", &sql.Point{38.898556, -77.037852}, 100)
|
res, _ = Run(context.Background(), "geo.circle", &sql.Point{-77.037852, 38.898556}, 100)
|
||||||
So(res, ShouldResemble, &sql.Circle{&sql.Point{38.898556, -77.037852}, 100})
|
So(res, ShouldResemble, &sql.Circle{&sql.Point{-77.037852, 38.898556}, 100})
|
||||||
res, _ = Run(context.Background(), "geo.circle", []interface{}{38.898556, -77.037852}, 100)
|
res, _ = Run(context.Background(), "geo.circle", []interface{}{-77.037852, 38.898556}, 100)
|
||||||
So(res, ShouldResemble, &sql.Circle{&sql.Point{38.898556, -77.037852}, 100})
|
So(res, ShouldResemble, &sql.Circle{&sql.Point{-77.037852, 38.898556}, 100})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("geo.polygon(a, b) works properly", t, func() {
|
Convey("geo.polygon(a, b) works properly", t, func() {
|
||||||
|
@ -59,12 +59,12 @@ func TestGeo(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("geo.distance(a, b, c, d) works properly", t, func() {
|
Convey("geo.distance(a, b, c, d) works properly", t, func() {
|
||||||
res, _ = Run(context.Background(), "geo.distance", &sql.Point{38.898556, -77.037852}, &sql.Point{38.897147, -77.043934})
|
res, _ = Run(context.Background(), "geo.distance", &sql.Point{-77.037852, 38.898556}, &sql.Point{-77.043934, 38.897147})
|
||||||
So(res, ShouldEqual, 549.1557912042738)
|
So(res, ShouldEqual, 549.1557912042738)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("geo.distance(a, b, c, d) errors properly", t, func() {
|
Convey("geo.distance(a, b, c, d) errors properly", t, func() {
|
||||||
res, _ = Run(context.Background(), "geo.distance", &sql.Point{38.898556, -77.037852}, "null")
|
res, _ = Run(context.Background(), "geo.distance", &sql.Point{-77.037852, 38.898556}, "null")
|
||||||
So(res, ShouldEqual, -1)
|
So(res, ShouldEqual, -1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -76,9 +76,9 @@ func TestGeo(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("geo.hash.encode(a, b, c) works properly", t, func() {
|
Convey("geo.hash.encode(a, b, c) works properly", t, func() {
|
||||||
res, _ = Run(context.Background(), "geo.hash.encode", &sql.Point{38.898556, -77.037852}, 5)
|
res, _ = Run(context.Background(), "geo.hash.encode", &sql.Point{-77.037852, 38.898556}, 5)
|
||||||
So(res, ShouldEqual, "dqcjq")
|
So(res, ShouldEqual, "dqcjq")
|
||||||
res, _ = Run(context.Background(), "geo.hash.encode", &sql.Point{38.898556, -77.037852}, 9)
|
res, _ = Run(context.Background(), "geo.hash.encode", &sql.Point{-77.037852, 38.898556}, 9)
|
||||||
So(res, ShouldEqual, "dqcjqcq8x")
|
So(res, ShouldEqual, "dqcjqcq8x")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue