-
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
Open
benguild
wants to merge
6
commits into
golang:master
Choose a base branch
from
benguild:fixClosestEdgeQuery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−3
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a43f7f9
Fixing `ClosestEdgeQuery` optimization (missing shapes on intermediat…
benguild a1c42ff
Removing incorrect label and redundant comment
benguild f57cef1
Reducing test code per @jmr request
benguild 8010dfb
Syncing with S2 C++ code
benguild 6a3ea40
Reintroducing more comprehensive test
benguild 42e911d
Code cleanup
benguild File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -541,3 +541,87 @@ func fractionToRadius(fraction, radiusKm float64) s1.Angle { | |
| } | ||
| return s1.Angle(fraction) * kmToAngle(radiusKm) | ||
| } | ||
|
|
||
| func TestEdgeQueryOptimized(t *testing.T) { | ||
| index := NewShapeIndex() | ||
|
|
||
| // Create polygons on different S2 faces by using points at different | ||
| // longitudes. Face assignment is roughly: | ||
| // Face 0: ~-45° to +45° longitude (Africa/Europe) | ||
| // Face 1: ~+45° to +135° longitude (Asia) | ||
| // Face 2: ~+135° to -135° longitude (Pacific, crossing dateline) | ||
| // Face 3: ~-135° to -45° longitude (North/South America) | ||
| locations := []struct { | ||
| name string | ||
| lat float64 | ||
| lng float64 | ||
| }{ | ||
| {"Face0", 20, 20}, // Africa - face 0 | ||
| {"Face1", 40, 90}, // Central Asia - face 1 | ||
| {"Face2", 0, 170}, // Pacific - face 2 | ||
| {"Face3", 40, -100}, // North America - face 3 | ||
| } | ||
|
|
||
| shapeIDToName := make(map[int32]string) | ||
| for _, loc := range locations { | ||
| center := PointFromLatLng(LatLngFromDegrees(loc.lat, loc.lng)) | ||
| cap := CapFromCenterAngle(center, s1.Degree) | ||
|
||
| loop := RegularLoop(center, cap.Radius(), 8) | ||
| polygon := PolygonFromLoops([]*Loop{loop}) | ||
| shapeID := index.Add(polygon) | ||
| shapeIDToName[shapeID] = loc.name | ||
| } | ||
|
|
||
| queryPoint := PointFromLatLng(LatLngFromDegrees(0, 10)) | ||
|
|
||
| // Run with optimized algorithm (the default) | ||
| optsOptimized := NewClosestEdgeQueryOptions() | ||
| optsOptimized = optsOptimized.IncludeInteriors(true) | ||
| resultsOptimized := NewClosestEdgeQuery(index, optsOptimized).FindEdges( | ||
| NewMinDistanceToPointTarget(queryPoint), | ||
| ) | ||
|
|
||
| seenOptimized := make(map[int32]bool) | ||
| for _, r := range resultsOptimized { | ||
| seenOptimized[r.ShapeID()] = true | ||
| } | ||
|
|
||
| // Run with brute force for comparison | ||
| optsBruteForce := NewClosestEdgeQueryOptions() | ||
| optsBruteForce = optsBruteForce.IncludeInteriors(true) | ||
| optsBruteForce = optsBruteForce.UseBruteForce(true) | ||
| resultsBruteForce := NewClosestEdgeQuery(index, optsBruteForce).FindEdges( | ||
| NewMinDistanceToPointTarget(queryPoint), | ||
| ) | ||
|
|
||
| seenBruteForce := make(map[int32]bool) | ||
| for _, r := range resultsBruteForce { | ||
| seenBruteForce[r.ShapeID()] = true | ||
| } | ||
|
|
||
| // Check if any shapes are missing from the optimized results | ||
| t.Logf("Optimized found %d shapes, brute force found %d shapes", | ||
| len(seenOptimized), len(seenBruteForce)) | ||
|
|
||
| var missing []string | ||
| for id, name := range shapeIDToName { | ||
| if !seenOptimized[id] && seenBruteForce[id] { | ||
| missing = append(missing, name) | ||
| } | ||
| } | ||
|
|
||
| if len(missing) > 0 { | ||
| t.Errorf( | ||
| "Optimized algorithm missed shapes that brute force found: %v", | ||
| missing, | ||
| ) | ||
| } | ||
|
|
||
| if len(seenOptimized) != len(seenBruteForce) { | ||
| t.Errorf( | ||
| "Optimized found %d shapes, brute force found %d shapes; should be equal", | ||
| len(seenOptimized), | ||
| len(seenBruteForce), | ||
| ) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.