mirror of https://github.com/tidwall/tile38.git
Changed clip errors and json result type
This commit is contained in:
parent
62f44ed055
commit
fb7259b10b
|
@ -1,6 +1,7 @@
|
||||||
// TEST command: spatial tests without walking the tree.
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
// TEST command: spatial tests without walking the tree.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
"github.com/tidwall/tile38/internal/clip"
|
"github.com/tidwall/tile38/internal/clip"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Object, err error) {
|
func (s *Server) parseArea(ovs []string, doClip bool) (vs []string, o geojson.Object, err error) {
|
||||||
var ok bool
|
var ok bool
|
||||||
var typ string
|
var typ string
|
||||||
vs = ovs[:]
|
vs = ovs[:]
|
||||||
|
@ -48,7 +49,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
|
||||||
o = geojson.NewPoint(geometry.Point{X: lon, Y: lat})
|
o = geojson.NewPoint(geometry.Point{X: lon, Y: lat})
|
||||||
case "circle":
|
case "circle":
|
||||||
if doClip {
|
if doClip {
|
||||||
err = errInvalidArgument("cannot clip with " + ltyp)
|
err = fmt.Errorf("invalid clip type '%s'", typ)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var slat, slon, smeters string
|
var slat, slon, smeters string
|
||||||
|
@ -84,7 +85,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
|
||||||
o = geojson.NewCircle(geometry.Point{X: lon, Y: lat}, meters, defaultCircleSteps)
|
o = geojson.NewCircle(geometry.Point{X: lon, Y: lat}, meters, defaultCircleSteps)
|
||||||
case "object":
|
case "object":
|
||||||
if doClip {
|
if doClip {
|
||||||
err = errInvalidArgument("cannot clip with " + ltyp)
|
err = fmt.Errorf("invalid clip type '%s'", typ)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var obj string
|
var obj string
|
||||||
|
@ -198,7 +199,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
|
||||||
})
|
})
|
||||||
case "get":
|
case "get":
|
||||||
if doClip {
|
if doClip {
|
||||||
err = errInvalidArgument("cannot clip with " + ltyp)
|
err = fmt.Errorf("invalid clip type '%s'", typ)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var key, id string
|
var key, id string
|
||||||
|
@ -224,7 +225,7 @@ func (s * Server) parseArea(ovs[]string, doClip bool) (vs []string, o geojson.Ob
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
|
func (s *Server) cmdTest(msg *Message) (res resp.Value, err error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
vs := msg.Args[1:]
|
vs := msg.Args[1:]
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
|
||||||
case "clip":
|
case "clip":
|
||||||
vs = nvs
|
vs = nvs
|
||||||
if lTest != "intersects" {
|
if lTest != "intersects" {
|
||||||
err = errInvalidArgument("cannot clip with" + wtok)
|
err = errInvalidArgument(wtok)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
doClip = true
|
doClip = true
|
||||||
|
@ -282,7 +283,11 @@ func (s *Server) cmdTest (msg *Message) (res resp.Value, err error) {
|
||||||
case JSON:
|
case JSON:
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString(`{"ok":true`)
|
buf.WriteString(`{"ok":true`)
|
||||||
buf.WriteString(fmt.Sprintf(`,"result":%d`, result))
|
if result != 0 {
|
||||||
|
buf.WriteString(`,"result":true`)
|
||||||
|
} else {
|
||||||
|
buf.WriteString(`,"result":false`)
|
||||||
|
}
|
||||||
if clipped != nil {
|
if clipped != nil {
|
||||||
buf.WriteString(`,"object":` + clipped.JSON())
|
buf.WriteString(`,"object":` + clipped.JSON())
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,10 @@ func testcmd_INTERSECTS_CLIP_test(mc *mockServer) error {
|
||||||
return mc.DoBatch([][]interface{}{
|
return mc.DoBatch([][]interface{}{
|
||||||
{"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"},
|
{"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"},
|
||||||
|
|
||||||
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "OBJECT", "{}"}, {"ERR invalid argument 'cannot clip with object'"},
|
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "OBJECT", "{}"}, {"ERR invalid clip type 'OBJECT'"},
|
||||||
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "CIRCLE", "1", "2", "3"}, {"ERR invalid argument 'cannot clip with circle'"},
|
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "CIRCLE", "1", "2", "3"}, {"ERR invalid clip type 'CIRCLE'"},
|
||||||
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "GET", "mykey", "point1"}, {"ERR invalid argument 'cannot clip with get'"},
|
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "GET", "mykey", "point1"}, {"ERR invalid clip type 'GET'"},
|
||||||
|
{"TEST", "OBJECT", poly9, "WITHIN", "CLIP", "BOUNDS", 10, 10, 20, 20}, {"ERR invalid argument 'CLIP'"},
|
||||||
|
|
||||||
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "BOUNDS", 37.732906137107, -122.44126439094543, 37.73421283683962, -122.43980526924135}, {"[1 " + poly9 + "]"},
|
{"TEST", "OBJECT", poly9, "INTERSECTS", "CLIP", "BOUNDS", 37.732906137107, -122.44126439094543, 37.73421283683962, -122.43980526924135}, {"[1 " + poly9 + "]"},
|
||||||
{"TEST", "OBJECT", poly8, "INTERSECTS", "CLIP", "BOUNDS", 37.733, -122.4408378, 37.7341129, -122.44}, {"[1 " + poly8 + "]"},
|
{"TEST", "OBJECT", poly8, "INTERSECTS", "CLIP", "BOUNDS", 37.733, -122.4408378, 37.7341129, -122.44}, {"[1 " + poly8 + "]"},
|
||||||
|
|
Loading…
Reference in New Issue