Skip to content

Commit 8010dfb

Browse files
committed
Syncing with S2 C++ code
1 parent f57cef1 commit 8010dfb

File tree

2 files changed

+1
-81
lines changed

2 files changed

+1
-81
lines changed

s2/edge_query.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ func (e *EdgeQuery) initCovering() {
697697
if next.CellID() != last.CellID() {
698698
// The index has at least two cells. Choose a level such that the entire
699699
// index can be spanned with at most 6 cells (if the index spans multiple
700-
// faces) or 4 cells (it the index spans a single face).
700+
// faces) or 4 cells (if the index spans a single face).
701701
level, ok := next.CellID().CommonAncestorLevel(last.CellID())
702702
if !ok {
703703
level = 0
@@ -721,7 +721,6 @@ func (e *EdgeQuery) initCovering() {
721721
cellLast.Prev()
722722
e.addInitialRange(cellFirst, cellLast)
723723
}
724-
725724
}
726725
e.addInitialRange(next, last)
727726
}

s2/edge_query_test.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -541,82 +541,3 @@ func fractionToRadius(fraction, radiusKm float64) s1.Angle {
541541
}
542542
return s1.Angle(fraction) * kmToAngle(radiusKm)
543543
}
544-
545-
func TestEdgeQueryOptimized(t *testing.T) {
546-
index := NewShapeIndex()
547-
548-
locations := []struct {
549-
name string
550-
lat float64
551-
lng float64
552-
}{
553-
{"Face0", 20, 20}, // Africa - face 0
554-
{"Face1", 40, 90}, // Central Asia - face 1
555-
{"Face3", 0, 170}, // Pacific - face 3
556-
{"Face4", 40, -100}, // North America - face 4
557-
}
558-
559-
shapeIDToName := make(map[int32]string)
560-
for _, loc := range locations {
561-
center := PointFromLatLng(LatLngFromDegrees(loc.lat, loc.lng))
562-
shapeID := index.Add(PolygonFromLoops([]*Loop{RegularLoop(
563-
center,
564-
CapFromCenterAngle(center, s1.Degree).Radius(),
565-
8,
566-
)}))
567-
shapeIDToName[shapeID] = loc.name
568-
}
569-
570-
queryPoint := PointFromLatLng(LatLngFromDegrees(0, 10))
571-
572-
// Run with optimized algorithm (the default)
573-
optsOptimized := NewClosestEdgeQueryOptions()
574-
optsOptimized = optsOptimized.IncludeInteriors(true)
575-
resultsOptimized := NewClosestEdgeQuery(index, optsOptimized).FindEdges(
576-
NewMinDistanceToPointTarget(queryPoint),
577-
)
578-
579-
seenOptimized := make(map[int32]bool)
580-
for _, r := range resultsOptimized {
581-
seenOptimized[r.ShapeID()] = true
582-
}
583-
584-
// Run with brute force for comparison
585-
optsBruteForce := NewClosestEdgeQueryOptions()
586-
optsBruteForce = optsBruteForce.IncludeInteriors(true)
587-
optsBruteForce = optsBruteForce.UseBruteForce(true)
588-
resultsBruteForce := NewClosestEdgeQuery(index, optsBruteForce).FindEdges(
589-
NewMinDistanceToPointTarget(queryPoint),
590-
)
591-
592-
seenBruteForce := make(map[int32]bool)
593-
for _, r := range resultsBruteForce {
594-
seenBruteForce[r.ShapeID()] = true
595-
}
596-
597-
// Check if any shapes are missing from the optimized results
598-
t.Logf("Optimized found %d shapes, brute force found %d shapes",
599-
len(seenOptimized), len(seenBruteForce))
600-
601-
var missing []string
602-
for id, name := range shapeIDToName {
603-
if !seenOptimized[id] && seenBruteForce[id] {
604-
missing = append(missing, name)
605-
}
606-
}
607-
608-
if len(missing) > 0 {
609-
t.Errorf(
610-
"Optimized algorithm missed shapes that brute force found: %v",
611-
missing,
612-
)
613-
}
614-
615-
if len(seenOptimized) != len(seenBruteForce) {
616-
t.Errorf(
617-
"Optimized found %d shapes, brute force found %d shapes; should be equal",
618-
len(seenOptimized),
619-
len(seenBruteForce),
620-
)
621-
}
622-
}

0 commit comments

Comments
 (0)