Skip to content

Commit 09c1534

Browse files
committed
Switching from "radiusKm" to units
1 parent 4ad4a85 commit 09c1534

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

s2/edge_query_closest_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/golang/geo/r3"
2222
"github.com/golang/geo/s1"
23+
"github.com/google/go-units/unit"
2324
)
2425

2526
func TestClosestEdgeQueryNoEdges(t *testing.T) {
@@ -238,7 +239,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
238239
targetType: queryTypePoint,
239240
numTargetEdges: 0,
240241
chooseTargetFromIndex: false,
241-
radiusKm: 1000,
242+
radius: 1000 * unit.Kilometer,
242243
maxDistanceFraction: -1,
243244
maxErrorFraction: -1,
244245
targetRadiusFraction: 0.0,
@@ -254,7 +255,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
254255
targetType: queryTypePoint,
255256
numTargetEdges: 0,
256257
chooseTargetFromIndex: false,
257-
radiusKm: 1000,
258+
radius: 1000 * unit.Kilometer,
258259
maxDistanceFraction: -1,
259260
maxErrorFraction: -1,
260261
targetRadiusFraction: 0.0,
@@ -271,7 +272,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
271272
targetType: queryTypePoint,
272273
numTargetEdges: 0,
273274
chooseTargetFromIndex: false,
274-
radiusKm: 1000,
275+
radius: 1000 * unit.Kilometer,
275276
maxDistanceFraction: -1,
276277
maxErrorFraction: 0.1,
277278
targetRadiusFraction: 0.0,
@@ -288,7 +289,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
288289
targetType: queryTypePoint,
289290
numTargetEdges: 0,
290291
chooseTargetFromIndex: false,
291-
radiusKm: 1000,
292+
radius: 1000 * unit.Kilometer,
292293
maxDistanceFraction: -1,
293294
maxErrorFraction: 0.01,
294295
targetRadiusFraction: 0.0,
@@ -302,7 +303,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
302303
targetType: queryTypeEdge,
303304
numTargetEdges: 0,
304305
chooseTargetFromIndex: false,
305-
radiusKm: 1000,
306+
radius: 1000 * unit.Kilometer,
306307
maxDistanceFraction: -1,
307308
maxErrorFraction: -1,
308309
targetRadiusFraction: -1.0,
@@ -316,7 +317,7 @@ func BenchmarkEdgeQueryFindEdges(b *testing.B) {
316317
targetType: queryTypeCell,
317318
numTargetEdges: 0,
318319
chooseTargetFromIndex: false,
319-
radiusKm: 1000,
320+
radius: 1000 * unit.Kilometer,
320321
maxDistanceFraction: -1,
321322
maxErrorFraction: -1,
322323
targetRadiusFraction: -1.0,

s2/edge_query_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func benchmarkEdgeQueryFindClosest(b *testing.B, bmOpts *edgeQueryBenchmarkOptio
340340
index := NewShapeIndex()
341341
opts := NewClosestEdgeQueryOptions().MaxResults(1).IncludeInteriors(bmOpts.includeInteriors)
342342

343-
radius := s1.EarthAngleFromLength(unit.Length(bmOpts.radiusKm) * unit.Kilometer)
343+
radius := s1.EarthAngleFromLength(bmOpts.radius)
344344
if bmOpts.maxDistanceFraction > 0 {
345345
opts.DistanceLimit(s1.ChordAngleFromAngle(s1.Angle(bmOpts.maxDistanceFraction) * radius))
346346
}
@@ -389,7 +389,7 @@ type edgeQueryBenchmarkOptions struct {
389389
targetType queryTargetType
390390
numTargetEdges int
391391
chooseTargetFromIndex bool
392-
radiusKm float64
392+
radius unit.Length
393393
maxDistanceFraction float64
394394
maxErrorFraction float64
395395
targetRadiusFraction float64
@@ -401,8 +401,8 @@ type edgeQueryBenchmarkOptions struct {
401401
// use in an edge query.
402402
//
403403
// Approximately numIndexEdges will be generated by the requested generator and
404-
// inserted. The geometry is generated within a Cap of the radius specified
405-
// by radiusKm (the index radius). Parameters with fraction in their
404+
// inserted. The geometry is generated within a Cap of the specified radius
405+
// (the index radius). Parameters with fraction in their
406406
// names are expressed as a fraction of this radius.
407407
//
408408
// Also generates a set of target geometries for the query, based on the
@@ -438,7 +438,7 @@ func generateEdgeQueryWithTargets(opts *edgeQueryBenchmarkOptions, query *EdgeQu
438438
opts.randomSeed++
439439
indexCap := CapFromCenterAngle(
440440
randomPoint(r),
441-
s1.EarthAngleFromLength(unit.Length(opts.radiusKm)*unit.Kilometer),
441+
s1.EarthAngleFromLength(opts.radius),
442442
)
443443

444444
query.Reset()
@@ -455,10 +455,10 @@ func generateEdgeQueryWithTargets(opts *edgeQueryBenchmarkOptions, query *EdgeQu
455455
}
456456

457457
for i := 0; i < numTargets; i++ {
458-
targetDist := fractionToRadius(opts.centerSeparationFraction, opts.radiusKm)
458+
targetDist := fractionToRadius(opts.centerSeparationFraction, opts.radius)
459459
targetCap := CapFromCenterAngle(
460460
sampleBoundaryFromCap(CapFromCenterAngle(indexCap.Center(), targetDist)),
461-
fractionToRadius(opts.targetRadiusFraction, opts.radiusKm),
461+
fractionToRadius(opts.targetRadiusFraction, opts.radius),
462462
)
463463

464464
switch opts.targetType {
@@ -539,9 +539,9 @@ func sampleCellFromIndex(index *ShapeIndex) CellID {
539539
return iter.CellID()
540540
}
541541

542-
func fractionToRadius(fraction, radiusKm float64) s1.Angle {
542+
func fractionToRadius(fraction float64, radius unit.Length) s1.Angle {
543543
if fraction < 0 {
544544
fraction = -randomFloat64() * fraction
545545
}
546-
return s1.EarthAngleFromLength(unit.Length(fraction*radiusKm) * unit.Kilometer)
546+
return s1.EarthAngleFromLength(unit.Length(fraction) * radius)
547547
}

0 commit comments

Comments
 (0)