mirror of https://github.com/tidwall/tile38.git
Add tests for the new CIRCLE subcommand.
This commit is contained in:
parent
c4d9ba26d9
commit
a01281a526
|
@ -0,0 +1,42 @@
|
||||||
|
package geojson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSegmentIntersectsCirclePointsInside(t *testing.T) {
|
||||||
|
// either start or end is within the circle
|
||||||
|
start := Position{X: -122.4408378, Y: 37.7341129, Z: 0}
|
||||||
|
end := Position{X: -122.4408378, Y: 37.733, Z: 0}
|
||||||
|
center := Position{X: -122.4409, Y: 37.734, Z: 0}
|
||||||
|
meters := 30.0
|
||||||
|
if !SegmentIntersectsCircle(start, end, center, meters) {
|
||||||
|
t.Fatal("!")
|
||||||
|
}
|
||||||
|
center = Position{X: -122.4409, Y: 37.733, Z: 0}
|
||||||
|
if !SegmentIntersectsCircle(start, end, center, meters) {
|
||||||
|
t.Fatal("!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSegmentIntersectsCirclePointsOutside(t *testing.T) {
|
||||||
|
// neither start nor end are within the circle, but the segment intersects it
|
||||||
|
start := Position{X: -122.4408378, Y: 37.7341129, Z: 0}
|
||||||
|
end := Position{X: -122.4408378, Y: 37.733, Z: 0}
|
||||||
|
center := Position{X: -122.4412, Y: 37.7335, Z: 0}
|
||||||
|
meters := 70.0
|
||||||
|
if !SegmentIntersectsCircle(start, end, center, meters) {
|
||||||
|
t.Fatal("!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSegmentIntersectsCircleLineButNotSegment(t *testing.T) {
|
||||||
|
// the line of the segment intersects the circle, but the segment does not
|
||||||
|
start := Position{X: -122.4408378, Y: 37.7341129, Z: 0}
|
||||||
|
end := Position{X: -122.4408378, Y: 37.733, Z: 0}
|
||||||
|
center := Position{X: -122.4412, Y: 37.737, Z: 0}
|
||||||
|
meters := 70.0
|
||||||
|
if SegmentIntersectsCircle(start, end, center, meters) {
|
||||||
|
t.Fatal("!")
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ import "testing"
|
||||||
|
|
||||||
func subTestSearch(t *testing.T, mc *mockServer) {
|
func subTestSearch(t *testing.T, mc *mockServer) {
|
||||||
runStep(t, mc, "KNN", keys_KNN_test)
|
runStep(t, mc, "KNN", keys_KNN_test)
|
||||||
|
runStep(t, mc, "WITHIN_CIRCLE", keys_WITHIN_CIRCLE_test)
|
||||||
|
runStep(t, mc, "INTERSECTS_CIRCLE", keys_INTERSECTS_CIRCLEtest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func keys_KNN_test(mc *mockServer) error {
|
func keys_KNN_test(mc *mockServer) error {
|
||||||
|
@ -23,3 +25,36 @@ func keys_KNN_test(mc *mockServer) error {
|
||||||
"]]"},
|
"]]"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func keys_WITHIN_CIRCLE_test(mc *mockServer) error {
|
||||||
|
return mc.DoBatch([][]interface{}{
|
||||||
|
{"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"},
|
||||||
|
{"SET", "mykey", "2", "POINT", 37.7335, -122.44121}, {"OK"},
|
||||||
|
{"SET", "mykey", "3", "OBJECT", `{"type":"LineString","coordinates":[[-122.4408378,37.7341129],[-122.4408378,37.733]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "4", "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "5", "OBJECT", `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "6", "POINT", -5, 5}, {"OK"},
|
||||||
|
{"SET", "mykey", "7", "POINT", 33, 21}, {"OK"},
|
||||||
|
{"WITHIN", "mykey", "IDS", "CIRCLE", 37.7335, -122.4412, 1000}, {
|
||||||
|
"[0 [1 2 3 4 5]]"},
|
||||||
|
{"WITHIN", "mykey", "IDS", "CIRCLE", 37.7335, -122.4412, 10}, {
|
||||||
|
"[0 [1 2]]"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func keys_INTERSECTS_CIRCLEtest(mc *mockServer) error {
|
||||||
|
return mc.DoBatch([][]interface{}{
|
||||||
|
{"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"},
|
||||||
|
{"SET", "mykey", "2", "POINT", 37.7335, -122.44121}, {"OK"},
|
||||||
|
{"SET", "mykey", "3", "OBJECT", `{"type":"LineString","coordinates":[[-122.4408378,37.7341129],[-122.4408378,37.733]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "4", "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "5", "OBJECT", `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]]}`}, {"OK"},
|
||||||
|
{"SET", "mykey", "6", "POINT", -5, 5}, {"OK"},
|
||||||
|
{"SET", "mykey", "7", "POINT", 33, 21}, {"OK"},
|
||||||
|
{"INTERSECTS", "mykey", "IDS", "CIRCLE", 37.7335, -122.4412, 70}, {
|
||||||
|
"[0 [1 2 3 4 5]]"},
|
||||||
|
{"INTERSECTS", "mykey", "IDS", "CIRCLE", 37.7335, -122.4412, 10}, {
|
||||||
|
"[0 [1 2]]"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue