diff options
author | Yang Bodong <bodong.ybd@alibaba-inc.com> | 2021-02-05 00:08:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 18:08:35 +0200 |
commit | ded1655d49950afd02bb3c5199bd33caac995e7c (patch) | |
tree | 6661160574eba8502afaf79e741865c08f292785 /src/geo.c | |
parent | 52fb3065357afcf14f38a12760eb4edd75158ad9 (diff) | |
download | redis-ded1655d49950afd02bb3c5199bd33caac995e7c.tar.gz |
GEOSEARCH bybox bug fixes and new fuzzy tester (#8445)
Fix errors of GEOSEARCH bybox search due to:
1. projection of the box to a trapezoid (when the meter box is converted to long / lat it's no longer a box).
2. width and height mismatch
Changes:
- New GEOSEARCH point in rectangle algorithm
- Fix GEOSEARCH bybox width and height mismatch bug
- Add GEOSEARCH bybox testing to the existing "GEOADD + GEORANGE randomized test"
- Add new fuzzy test to stress test the bybox corners and edges
- Add some tests for edge cases of the bybox algorithm
Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/geo.c')
-rw-r--r-- | src/geo.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -175,10 +175,10 @@ int extractDistanceOrReply(client *c, robj **argv, * that should be in the form: <number> <number> <unit>, and return C_OK or C_ERR means success or failure * *conversions is populated with the coefficient to use in order to convert meters to the unit.*/ int extractBoxOrReply(client *c, robj **argv, double *conversion, - double *height, double *width) { + double *width, double *height) { double h, w; - if ((getDoubleFromObjectOrReply(c, argv[0], &h, "need numeric height") != C_OK) || - (getDoubleFromObjectOrReply(c, argv[1], &w, "need numeric width") != C_OK)) { + if ((getDoubleFromObjectOrReply(c, argv[0], &w, "need numeric width") != C_OK) || + (getDoubleFromObjectOrReply(c, argv[1], &h, "need numeric height") != C_OK)) { return C_ERR; } @@ -224,8 +224,10 @@ int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds memb if (!geohashGetDistanceIfInRadiusWGS84(shape->xy[0], shape->xy[1], xy[0], xy[1], shape->t.radius*shape->conversion, &distance)) return C_ERR; } else if (shape->type == RECTANGLE_TYPE) { - if (!geohashGetDistanceIfInRectangle(shape->bounds, shape->xy[0], shape->xy[1], - xy[0], xy[1], &distance)) return C_ERR; + if (!geohashGetDistanceIfInRectangle(shape->t.r.width * shape->conversion, + shape->t.r.height * shape->conversion, + shape->xy[0], shape->xy[1], xy[0], xy[1], &distance)) + return C_ERR; } /* Append the new element. */ @@ -635,8 +637,8 @@ void georadiusGeneric(client *c, int srcKeyIndex, int flags) { flags & GEOSEARCH && !byradius) { - if (extractBoxOrReply(c, c->argv+base_args+i+1, &shape.conversion, &shape.t.r.height, - &shape.t.r.width) != C_OK) return; + if (extractBoxOrReply(c, c->argv+base_args+i+1, &shape.conversion, &shape.t.r.width, + &shape.t.r.height) != C_OK) return; shape.type = RECTANGLE_TYPE; bybox = 1; i += 3; |