-
Notifications
You must be signed in to change notification settings - Fork 189
EdgeQuery.initCovering: Fix bug causing skipped faces #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| level++ | ||
| } | ||
|
|
||
| // Visit each potential top-level cell except the last (handled below). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this correctly… the loop condition id != lastID correctly excludes the last face (which is handled by addInitialRange(next, last) after the loop). However, the break inside the loop contradicts this intent by exiting after only the first face instead of visiting each face?
|
It's hard for me to understand what's wrong. What test case was failing before? Can you minimize the test case to just that? Then it's easier to analyze. I also don't get much out of the PR description other than "something's broken". https://google.github.io/eng-practices/review/developer/cl-descriptions.html Did you look at the C++ implementation / try the test cases there? |
If you read the comments in the test, it very clearly explains that it's verifying that the results from the "optimized" approach are the same as the "brute force" one. What's wrong is in the first sentence of the PR:
I'm about to commit a resolution for the TODO that was in the code there as well, so I'm keeping these commits separate, but both pass the test where the current code does not… and unless skipping faces is intended functionality or I'm missing something here, this may be breaking other cross-face implementations. |
|
s2/edge_query_test.go
Outdated
| shapeIDToName := make(map[int32]string) | ||
| for _, loc := range locations { | ||
| center := PointFromLatLng(LatLngFromDegrees(loc.lat, loc.lng)) | ||
| cap := CapFromCenterAngle(center, s1.Degree) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this cap is only used for its radius.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is not in C++, it doesn't have the |
Which face(s) are missing? |
I think I answered that here: #247 (comment) |
No. Maybe it's simpler if you just paste the test output with the break. |
Noticed this while working on golang/geo#247
8010dfb updates this to be the same as the C++ version, the test passes as do the others. I went ahead and removed the test since mirroring it upstream to C++ which doesn't have the bug wouldn't add any value, but we can add it back in if you want. https://github.com/google/s2geometry/blob/master/src/s2/s2closest_edge_query_base.h#L926-L950 I also fixed the comment typo on the C++ repo: google/s2geometry#490 |
bdefefe to
8010dfb
Compare
ClosestEdgeQuery optimization (missing shapes on intermediate faces)
Please add the test back. The test clearly adds value to the Go library. Adding the test to C++ would improve test coverage there. C++ tests fail in debug mode when adding the break, but not in opt mode, so we're missing something. |
|
When you add the test back, can you use two shapes? Can you make the old code fail with just one? |
Hmm, I think the minimum is 4 shapes across 4 faces (finds 1/4) or 5 shapes as 3+1+1 for example across 3 faces (finds 3/5) …? I turned this into a table and tried to come up with some other combinations in 6a3ea40. Some fail pre-fix, some don't. Before removing
After removing
@jmr Are you perhaps able to draft a similar test for C++? I don't have the env setup right now to really dive into C++ on this machine so I'd have to get back to it later. |
|
I don't recall why the break was added there when I wrote it 5 years ago. Looking at the C++ from approximately the same time there wasn't a break there either. I think removing the break is reasonable especially if it also helps resolve some broken tests. |
|
Thanks @rsned. If someone approves the changes, we could merge. |
018a111 to
fd34a86
Compare
fd34a86 to
42e911d
Compare
I was doing some benchmarking and testing with this and found that seemingly due to a
breakstatement it's skipping entire faces.Pretty bad bug. Added a test that fails and is now fixed by removing the
break.I'm taking a look at the TODO right now that's there but wanted to post the simplest change and test first.