diff --git a/sql/ast.go b/sql/ast.go index 009ddca1..22935ebb 100644 --- a/sql/ast.go +++ b/sql/ast.go @@ -712,11 +712,11 @@ type Points []*Point // Point comment type Point struct { - LA float64 LO float64 + LA float64 } -func NewPoint(LA, LO float64) *Point { +func NewPoint(LO, LA float64) *Point { return &Point{LA: LA, LO: LO} } diff --git a/util/fncs/geo.go b/util/fncs/geo.go index 5b0132b7..321f015f 100644 --- a/util/fncs/geo.go +++ b/util/fncs/geo.go @@ -32,9 +32,9 @@ func geoPoint(ctx context.Context, args ...interface{}) (interface{}, error) { return sql.NewPoint(p[0], p[1]), nil } case 2: - if lat, ok := ensureFloat(args[0]); ok { - if lng, ok := ensureFloat(args[1]); ok { - return sql.NewPoint(lat, lng), nil + if lng, ok := ensureFloat(args[0]); ok { + if lat, ok := ensureFloat(args[1]); ok { + return sql.NewPoint(lng, lat), nil } } } diff --git a/util/fncs/geo_test.go b/util/fncs/geo_test.go index c32997d1..1f15bda2 100644 --- a/util/fncs/geo_test.go +++ b/util/fncs/geo_test.go @@ -30,21 +30,21 @@ func TestGeo(t *testing.T) { Convey("geo.point(a, b) works properly", t, func() { res, _ = Run(context.Background(), "geo.point", "test", "test") So(res, ShouldEqual, nil) - res, _ = Run(context.Background(), "geo.point", &sql.Point{38.898556, -77.037852}) - So(res, ShouldResemble, &sql.Point{38.898556, -77.037852}) - res, _ = Run(context.Background(), "geo.point", []interface{}{38.898556, -77.037852}) - So(res, ShouldResemble, &sql.Point{38.898556, -77.037852}) - res, _ = Run(context.Background(), "geo.point", 38.898556, -77.037852) - So(res, ShouldResemble, &sql.Point{38.898556, -77.037852}) + res, _ = Run(context.Background(), "geo.point", &sql.Point{-77.037852, 38.898556}) + So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556}) + res, _ = Run(context.Background(), "geo.point", []interface{}{-77.037852, 38.898556}) + So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556}) + res, _ = Run(context.Background(), "geo.point", -77.037852, 38.898556) + So(res, ShouldResemble, &sql.Point{-77.037852, 38.898556}) }) Convey("geo.circle(a, b) works properly", t, func() { res, _ = Run(context.Background(), "geo.circle", "test", "test") So(res, ShouldEqual, nil) - res, _ = Run(context.Background(), "geo.circle", &sql.Point{38.898556, -77.037852}, 100) - So(res, ShouldResemble, &sql.Circle{&sql.Point{38.898556, -77.037852}, 100}) - res, _ = Run(context.Background(), "geo.circle", []interface{}{38.898556, -77.037852}, 100) - So(res, ShouldResemble, &sql.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{-77.037852, 38.898556}, 100}) + res, _ = Run(context.Background(), "geo.circle", []interface{}{-77.037852, 38.898556}, 100) + So(res, ShouldResemble, &sql.Circle{&sql.Point{-77.037852, 38.898556}, 100}) }) 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() { - 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) }) 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) }) @@ -76,9 +76,9 @@ func TestGeo(t *testing.T) { }) 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") - 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") })