@@ -177,97 +177,102 @@ func TestEdgeQuerySortAndUnique(t *testing.T) {
177177 }
178178}
179179
180- func TestEdgeQueryOptimized (t * testing.T ) {
180+ func TestEdgeQueryMultiFace (t * testing.T ) {
181+ // Avoid LatLngFromDegrees repetition.
182+ type loc struct {
183+ lat , lng float64
184+ }
181185 tests := []struct {
182186 name string
183- locs []struct { latitude , longitude float64 }
187+ locs []loc
184188 }{
185189 {
186190 // 0 intermediate faces: first and last handled directly
187191 "faces 0,4" ,
188- []struct { latitude , longitude float64 } {{20 , 20 }, {40 , - 100 }},
192+ []loc {{20 , 20 }, {40 , - 100 }},
189193 },
190194
191195 {
192196 "faces 0,4 (3+1 shapes)" ,
193- []struct { latitude , longitude float64 } {{20 , 20 }, {25 , 25 }, {15 , 15 }, {40 , - 100 }},
197+ []loc {{20 , 20 }, {25 , 25 }, {15 , 15 }, {40 , - 100 }},
194198 },
195199
196200 {
197201 // 1 intermediate face with 1 shape each
198202 "faces 0,1,4" ,
199- []struct { latitude , longitude float64 } {{20 , 20 }, {40 , 90 }, {40 , - 100 }},
203+ []loc {{20 , 20 }, {40 , 90 }, {40 , - 100 }},
200204 },
201205
202206 {
203207 // 1 intermediate face but multiple shapes on first face
204208 "faces 0,1,4 (3+1+1 shapes)" ,
205- []struct { latitude , longitude float64 } {{20 , 20 }, {25 , 25 }, {15 , 15 }, {40 , 90 }, {40 , - 100 }},
209+ []loc {{20 , 20 }, {25 , 25 }, {15 , 15 }, {40 , 90 }, {40 , - 100 }},
206210 },
207211
208212 {
209213 // 2 intermediate faces
210214 "faces 0,1,3,4" ,
211- []struct { latitude , longitude float64 } {{20 , 20 }, {40 , 90 }, {0 , 170 }, {40 , - 100 }},
215+ []loc {{20 , 20 }, {40 , 90 }, {0 , 170 }, {40 , - 100 }},
212216 },
213217
214218 {
215219 // All 6 faces: extreme case with 4 intermediate faces
216220 "all 6 faces" ,
217- []struct { latitude , longitude float64 } {
221+ []loc {
218222 {20 , 20 }, {40 , 90 }, {90 , 0 }, {0 , 170 }, {40 , - 100 }, {- 90 , 0 },
219223 },
220224 },
221225
222226 {
223227 // Non-zero starting face with 1 intermediate
224228 "faces 1,3,4" ,
225- []struct { latitude , longitude float64 } {{40 , 90 }, {0 , 170 }, {40 , - 100 }},
229+ []loc {{40 , 90 }, {0 , 170 }, {40 , - 100 }},
226230 },
227231
228232 {
229233 // Non-zero starting face with 2 intermediate faces
230234 "faces 1,2,3,4" ,
231- []struct { latitude , longitude float64 } {{40 , 90 }, {90 , 0 }, {0 , 170 }, {40 , - 100 }},
235+ []loc {{40 , 90 }, {90 , 0 }, {0 , 170 }, {40 , - 100 }},
232236 },
233237 }
234238
235239 for _ , test := range tests {
236240 t .Run (test .name , func (t * testing.T ) {
237241 index := NewShapeIndex ()
238- for _ , location := range test .locs {
239- center := PointFromLatLng (LatLngFromDegrees (location . latitude , location . longitude ))
242+ for _ , loc := range test .locs {
243+ center := PointFromLatLng (LatLngFromDegrees (loc . lat , loc . lng ))
240244 loop := RegularLoop (center , s1 .Degree , 8 )
241245 index .Add (PolygonFromLoops ([]* Loop {loop }))
242246 }
243247
244248 queryPoint := PointFromLatLng (LatLngFromDegrees (0 , 10 ))
245-
246- optimized := NewClosestEdgeQueryOptions ().IncludeInteriors (true )
247- got := NewClosestEdgeQuery (index , optimized ).FindEdges (
248- NewMinDistanceToPointTarget (queryPoint ),
249- )
250-
251- bruteForce := NewClosestEdgeQueryOptions ().IncludeInteriors (true ).UseBruteForce (true )
252- want := NewClosestEdgeQuery (index , bruteForce ).FindEdges (
249+ opts := NewClosestEdgeQueryOptions ()
250+ edges := NewClosestEdgeQuery (index , opts ).FindEdges (
253251 NewMinDistanceToPointTarget (queryPoint ),
254252 )
255253
256- shapesGot , shapesWant := make (map [int32 ]bool ), make (map [int32 ]bool )
257- for _ , r := range got {
258- shapesGot [r .ShapeID ()] = true
259- }
260- for _ , r := range want {
261- shapesWant [r .ShapeID ()] = true
254+ ids := make (map [int32 ]bool )
255+ for _ , r := range edges {
256+ ids [r .ShapeID ()] = true
262257 }
263258
264- if len (shapesGot ) != len (shapesWant ) {
259+ // We should always find all points.
260+ if len (ids ) != len (test .locs ) {
265261 t .Errorf (
266- "%s: optimized found %d shapes, brute force found %d" ,
262+ "%s: got %d shapes, wanted %d" ,
267263 test .name ,
268- len (shapesGot ),
269- len (shapesWant ),
264+ len (ids ),
265+ len (test . locs ),
270266 )
267+ for i := range int32 (len (test .locs )) {
268+ if ! ids [i ] {
269+ t .Errorf ("missing %d" , i )
270+ }
271+ delete (ids , i )
272+ }
273+ for i , _ := range ids {
274+ t .Errorf ("extra %d" , i )
275+ }
271276 }
272277 })
273278 }
0 commit comments