Skip to content

GEOSEARCH bybox bug fixes and new fuzzy tester#8375

Closed
yangbodong22011 wants to merge 8 commits intoredis:unstablefrom
yangbodong22011:feature-geosearch-fuzzy-test
Closed

GEOSEARCH bybox bug fixes and new fuzzy tester#8375
yangbodong22011 wants to merge 8 commits intoredis:unstablefrom
yangbodong22011:feature-geosearch-fuzzy-test

Conversation

@yangbodong22011
Copy link
Contributor

@yangbodong22011 yangbodong22011 commented Jan 21, 2021

[Edit]

  • Fix GEOSEARCH bybox width and height mismatch
  • Fix errors of GEOSEARCH bybox search due to projection of the box to a
    trapezoid (when the meter box is converted to long / lat it's no longer a box).
  • 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

This PR add fuzzy test for GEOSEARCH command and fix the wrong order of widht and height parameters. As shown in the document, width is before height.

@oranagra oranagra changed the title Add fuzzy test for GEOSEARCH and fix the order of widht and height argument Fix GEOSEARCH box width and height mismatch and add fuzzy tester Jan 21, 2021
@oranagra
Copy link
Member

@yangbodong22011 thank you for this PR.

this is not exactly the test i wanted, but maybe its is enough.
correct me if i'm wrong, this test just checks that the same calculations performed by redis and by the tcl code reach the same conclusion (and it does so with random coordinates.

what i was looking is more of a specific test that tests edge cases in the box code.
IIRC our implementation does something like this (converting a box into a circle):
image
i would like to test the 4 (or maybe just 2) green dots, and maybe the orange ones too, to see that they are handled correctly.

and i would like to do that on various different box shapes (horizontally wide, and horizontally narrow).
and i would like to places these boxes in various places on the globe (i.e. since our search grid is in a fixed positions, some bugs can reproduce on a certain long/lat position and not on another)

i didn't dig too much into the current test, if you can convince me that it covers the above concern, that would be great.
thank you.

@yangbodong22011
Copy link
Contributor Author

yangbodong22011 commented Jan 27, 2021

Updated:

  • Fixed the error in latitude and introduced a trapezoid. To determine whether a point is in the trapezoid, use the ray-crossing Algorithm, reference: geohashGetDistanceIfInTrapezoid()

  • Add tcl test, in tcl, to judge whether a point is in the trapezoid, use another area Algorithm, reference: pointInBox(), it's different from c code.

  • Added a test that the point is very close to the box

NOTICE:

  • shape->bounds now are the 4 coordinates of the trapezoid.
  • use sqrt((width/2)^2 + (height/2)^2) for radius_meters, because in some case, max(height/2, widht/2) is not enough.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangbodong22011 thank you!
i assume the improved tests failed quite consistently on the old implementation, right?

considering the equator problem i mentioned and maybe the bent edges, they should still fail from time to time, and we can improve both tests and the code.

@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Jan 28, 2021
@yangbodong22011 yangbodong22011 force-pushed the feature-geosearch-fuzzy-test branch from 070c045 to 56e9dd7 Compare February 2, 2021 17:18
@yangbodong22011
Copy link
Contributor Author

Updated:

  • Fixed the error in latitude and introduced a trapezoid. To determine whether a point is in the trapezoid, use the ray-crossing Algorithm, reference: geohashGetDistanceIfInTrapezoid()
  • Add tcl test, in tcl, to judge whether a point is in the trapezoid, use another area Algorithm, reference: pointInBox(), it's different from c code.
  • Added a test that the point is very close to the box

NOTICE:

  • shape->bounds now are the 4 coordinates of the trapezoid.
  • use sqrt((width/2)^2 + (height/2)^2) for radius_meters, because in some case, max(height/2, widht/2) is not enough.
  • tcl test also use ray-crossing Algorithm, because the area algorithm is not suitable for concave polygons.
  • update fuzzy test, now 8 points are randomly generated.
  • When the trapezoid crosses the equator, the equator is selected as the narrowest.
  • When the box spans -180° or 180°, the searched point + or-360° is required, because 180° + 1° = -179°

@oranagra please have a look when you have time.

Comment on lines 65 to 76
set bounds(0) [expr {$search_lon-$long_delta_top}]
set bounds(1) [expr {$search_lat+$lat_delta}]
set bounds(2) [expr {$search_lon+$long_delta_top}]
set bounds(3) [expr {$search_lat+$lat_delta}]
set bounds(4) [expr {$search_lon+$long_delta_middle}]
set bounds(5) $search_lat
set bounds(6) [expr {$search_lon+$long_delta_bottom}]
set bounds(7) [expr {$search_lat-$lat_delta}]
set bounds(8) [expr {$search_lon-$long_delta_bottom}]
set bounds(9) [expr {$search_lat-$lat_delta}]
set bounds(10) [expr {$search_lon-$long_delta_middle}]
set bounds(11) $search_lat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is a bit weak since it uses the same approach as the code it tests.
luckily we have the other new test (one that shifts the box by 1m) that covers for this.
but maybe we can improve this function too.

some wild idea is to try to convert the point that we're matching to the coordinate system of the box (km) rather than converting the box to long/lat.
consider:

  • the search box center being: lon1,lat1 (search_lon and search_lat right?)
  • the the point we're to match to the box: lon2,lat2 (lon and lat, right?)

we can create two new points, and measure the horizontal and vertical distance from the box center and match them to width and height.

# on one longitude (the one of the point being searched),
# measure the distance between two lats (the lat of the point being search and the one of the center of the box)
distance between lon2/lat1 and lon2,lat2 < height/2 ?

# on one latitude (the one of the point being searched),
# measure the distance between two lons (the lon of the point being search and the one of the center of the box)
distance between lon1,lat2 and lon2,lat2 < width/2 ?

is this silly? (it's very late at night here), or could that work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangbodong22011 what do you think of this?
if that algorithm indeed works, maybe instead of using it in the tests we should use it in redis itself?
i initially suggested it just so that we don't use the same algo in the tests as the one in redis (weak test), but if we prove that it's a valid algo, it might be more accurate than the polygon one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra Thank you very much for your algorithm, i finished it at: #8445

@yangbodong22011 yangbodong22011 force-pushed the feature-geosearch-fuzzy-test branch from 18529c9 to 702f3c1 Compare February 3, 2021 02:59
@yangbodong22011
Copy link
Contributor Author

@oranagra Thank you very much for your detailed reply. I have updated the code, please have a look when you have time.

@oranagra oranagra changed the title Fix GEOSEARCH box width and height mismatch and add fuzzy tester GEOSEARCH bybox bug fixes and new fuzzy tester Feb 3, 2021
@oranagra oranagra removed the release-notes indication that this issue needs to be mentioned in the release notes label Feb 4, 2021
@oranagra
Copy link
Member

oranagra commented Feb 4, 2021

closed in favor of #8445

@oranagra oranagra closed this Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants