Skip to content

Commit a06e4b3

Browse files
committed
Go 1.21 added builtin min and max methods meaning we no longer need to make our own.
1 parent 394b634 commit a06e4b3

21 files changed

+61
-61
lines changed

s2/builder_snapper.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ func (sf CellIDSnapper) MinVertexSeparation() s1.Angle {
264264
// 0.5 * MaxDiagMetric.Value(level) when snapped.
265265
minEdge := s1.Angle(MinEdgeMetric.Value(sf.level))
266266
maxDiag := s1.Angle(MaxDiagMetric.Value(sf.level))
267-
return maxAngle(minEdge,
267+
return max(minEdge,
268268
// per 2 above, a little less than 2 / sqrt(13)
269-
maxAngle(0.548*sf.snapRadius,
269+
max(0.548*sf.snapRadius,
270270
sf.snapRadius-0.5*maxDiag))
271271
}
272272

@@ -317,8 +317,8 @@ func (sf CellIDSnapper) MinEdgeVertexSeparation() s1.Angle {
317317

318318
// Otherwise, these bounds hold for any snapRadius.
319319
vertexSep := sf.MinVertexSeparation()
320-
return maxAngle(0.397*minDiag, // sqrt(3/19) in the plane
321-
maxAngle(0.219*sf.snapRadius, // 2*sqrt(3/247) in the plane
320+
return max(0.397*minDiag, // sqrt(3/19) in the plane
321+
max(0.219*sf.snapRadius, // 2*sqrt(3/247) in the plane
322322
0.5*(vertexSep/sf.snapRadius)*vertexSep))
323323
}
324324

@@ -429,14 +429,14 @@ func (sf IntLatLngSnapper) exponentForMaxSnapRadius(snapRadius s1.Angle) int {
429429
// When choosing an exponent, we need to account for the error bound of
430430
// (9 * sqrt(2) + 1.5) * dblEpsilon added by minSnapRadiusForExponent.
431431
snapRadius -= (9*math.Sqrt2 + 1.5) * dblEpsilon
432-
snapRadius = maxAngle(snapRadius, 1e-30)
432+
snapRadius = max(snapRadius, 1e-30)
433433
exponent := math.Log10((1 / math.Sqrt2) / snapRadius.Degrees())
434434

435435
// There can be small errors in the calculation above, so to ensure that
436436
// this function is the inverse of minSnapRadiusForExponent we subtract a
437437
// small error tolerance.
438-
return maxInt(minIntSnappingExponent,
439-
minInt(maxIntSnappingExponent, int(math.Ceil(exponent-2*dblEpsilon))))
438+
return max(minIntSnappingExponent,
439+
min(maxIntSnappingExponent, int(math.Ceil(exponent-2*dblEpsilon))))
440440
}
441441

442442
// MinVertexSeparation reports the minimum separation between vertices depending on
@@ -457,7 +457,7 @@ func (sf IntLatLngSnapper) MinVertexSeparation() s1.Angle {
457457
// only select a new site when it is at least snapRadius away from all
458458
// existing sites, and snapping a vertex can move it by up to
459459
// ((1 / sqrt(2)) * sf.to) degrees.
460-
return maxAngle(0.471*sf.snapRadius, // sqrt(2)/3 in the plane
460+
return max(0.471*sf.snapRadius, // sqrt(2)/3 in the plane
461461
sf.snapRadius-s1.Degree*s1.Angle(1/math.Sqrt2)*sf.to)
462462
}
463463

@@ -489,8 +489,8 @@ func (sf IntLatLngSnapper) MinEdgeVertexSeparation() s1.Angle {
489489
// bound approaches 0.5 * snapRadius as the snap radius becomes large
490490
// relative to the grid spacing.
491491
vertexSep := sf.MinVertexSeparation()
492-
return maxAngle(0.277*s1.Degree*sf.to, // 1/sqrt(13) in the plane
493-
maxAngle(0.222*sf.snapRadius, // 2/9 in the plane
492+
return max(0.277*s1.Degree*sf.to, // 1/sqrt(13) in the plane
493+
max(0.222*sf.snapRadius, // 2/9 in the plane
494494
0.5*(vertexSep/sf.snapRadius)*vertexSep))
495495
}
496496

s2/builder_snapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestCellIDSnapperLevelToFromSnapRadius(t *testing.T) {
5050
if got := f.levelForMaxSnapRadius(radius); got != level {
5151
t.Errorf("levelForMaxSnapRadius(%v) = %v, want %v", radius, got, level)
5252
}
53-
if got, want := f.levelForMaxSnapRadius(0.999*radius), minInt(level+1, MaxLevel); got != want {
53+
if got, want := f.levelForMaxSnapRadius(0.999*radius), min(level+1, MaxLevel); got != want {
5454
t.Errorf("levelForMaxSnapRadius(0.999*%v) = %v, want %v (level %d)", radius, got, want, level)
5555
}
5656
}
@@ -84,7 +84,7 @@ func TestIntLatLngSnapperExponentToFromSnapRadius(t *testing.T) {
8484
if got := sf.exponentForMaxSnapRadius(radius); got != exp {
8585
t.Errorf("exponentForMaxSnapRadius(%v) = %v, want %v", radius, got, exp)
8686
}
87-
if got, want := sf.exponentForMaxSnapRadius(0.999*radius), minInt(exp+1, maxIntSnappingExponent); got != want {
87+
if got, want := sf.exponentForMaxSnapRadius(0.999*radius), min(exp+1, maxIntSnappingExponent); got != want {
8888
t.Errorf("exponentForMaxSnapRadius(%v) = %v, want %v", 0.999*radius, got, want)
8989
}
9090
}

s2/cell.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func (c Cell) distanceInternal(targetXYZ Point, toInterior bool) s1.ChordAngle {
622622
// arbitrary quadrilaterals after they are projected onto the sphere.
623623
// Therefore the simplest approach is just to find the minimum distance to
624624
// any of the four edges.
625-
return minChordAngle(edgeDistance(-dir00, c.uv.X.Lo),
625+
return min(edgeDistance(-dir00, c.uv.X.Lo),
626626
edgeDistance(dir01, c.uv.X.Hi),
627627
edgeDistance(-dir10, c.uv.Y.Lo),
628628
edgeDistance(dir11, c.uv.Y.Hi))
@@ -633,7 +633,7 @@ func (c Cell) distanceInternal(targetXYZ Point, toInterior bool) s1.ChordAngle {
633633
// tests above, because (1) the edges don't meet at right angles and (2)
634634
// there are points on the far side of the sphere that are both above *and*
635635
// below the cell, etc.
636-
return minChordAngle(c.vertexChordDist2(target, false, false),
636+
return min(c.vertexChordDist2(target, false, false),
637637
c.vertexChordDist2(target, true, false),
638638
c.vertexChordDist2(target, false, true),
639639
c.vertexChordDist2(target, true, true))
@@ -651,7 +651,7 @@ func (c Cell) MaxDistance(target Point) s1.ChordAngle {
651651
// First check the 4 cell vertices. If all are within the hemisphere
652652
// centered around target, the max distance will be to one of these vertices.
653653
targetUVW := faceXYZtoUVW(int(c.face), target)
654-
maxDist := maxChordAngle(c.vertexChordDist2(targetUVW, false, false),
654+
maxDist := max(c.vertexChordDist2(targetUVW, false, false),
655655
c.vertexChordDist2(targetUVW, true, false),
656656
c.vertexChordDist2(targetUVW, false, true),
657657
c.vertexChordDist2(targetUVW, true, true))
@@ -685,7 +685,7 @@ func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle {
685685

686686
// First, check the minimum distance to the edge endpoints A and B.
687687
// (This also detects whether either endpoint is inside the cell.)
688-
minDist := minChordAngle(c.Distance(a), c.Distance(b))
688+
minDist := min(c.Distance(a), c.Distance(b))
689689
if minDist == 0 {
690690
return minDist
691691
}
@@ -717,7 +717,7 @@ func (c Cell) MaxDistanceToEdge(a, b Point) s1.ChordAngle {
717717
// If the maximum distance from both endpoints to the cell is less than π/2
718718
// then the maximum distance from the edge to the cell is the maximum of the
719719
// two endpoint distances.
720-
maxDist := maxChordAngle(c.MaxDistance(a), c.MaxDistance(b))
720+
maxDist := max(c.MaxDistance(a), c.MaxDistance(b))
721721
if maxDist <= s1.RightChordAngle {
722722
return maxDist
723723
}

s2/cellid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestCellIDAllNeighbors(t *testing.T) {
296296

297297
// testAllNeighbors computes approximately 2**(2*(diff+1)) cell ids,
298298
// so it's not reasonable to use large values of diff.
299-
maxDiff := minInt(6, MaxLevel-id.Level()-1)
299+
maxDiff := min(6, MaxLevel-id.Level()-1)
300300
level := id.Level() + randomUniformInt(maxDiff)
301301

302302
// We compute AllNeighbors, and then add in all the children of id

s2/cellunion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func (cu *CellUnion) ExpandAtLevel(level int) {
491491
func (cu *CellUnion) ExpandByRadius(minRadius s1.Angle, maxLevelDiff int) {
492492
minLevel := MaxLevel
493493
for _, cid := range *cu {
494-
minLevel = minInt(minLevel, cid.Level())
494+
minLevel = min(minLevel, cid.Level())
495495
}
496496

497497
// Find the maximum level such that all cells are at least "minRadius" wide.
@@ -501,7 +501,7 @@ func (cu *CellUnion) ExpandByRadius(minRadius s1.Angle, maxLevelDiff int) {
501501
// The easiest way to handle this is to expand twice.
502502
cu.ExpandAtLevel(0)
503503
}
504-
cu.ExpandAtLevel(minInt(minLevel+maxLevelDiff, radiusLevel))
504+
cu.ExpandAtLevel(min(minLevel+maxLevelDiff, radiusLevel))
505505
}
506506

507507
// Equal reports whether the two CellUnions are equal.

s2/cellunion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,9 +933,9 @@ func TestCellUnionExpand(t *testing.T) {
933933
// that figures out an appropriate cell level to use for the expansion.
934934
minLevel := MaxLevel
935935
for _, cid := range covering {
936-
minLevel = minInt(minLevel, cid.Level())
936+
minLevel = min(minLevel, cid.Level())
937937
}
938-
expandLevel := minInt(minLevel+maxLevelDiff, MinWidthMetric.MaxLevel(radius))
938+
expandLevel := min(minLevel+maxLevelDiff, MinWidthMetric.MaxLevel(radius))
939939

940940
// Generate a covering for the expanded cap, and measure the new maximum
941941
// distance from the cap center to any point in the covering.

s2/edge_crossings_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func TestEdgeutilIntersectionError(t *testing.T) {
120120
if got, want := pointDist, intersectionError; got > want {
121121
t.Errorf("%v.Distance(%v) = %v want <= %v", expected, actual, got, want)
122122
}
123-
maxEdgeDist = maxAngle(maxEdgeDist, maxAngle(distAB, distCD))
124-
maxPointDist = maxAngle(maxPointDist, pointDist)
123+
maxEdgeDist = max(maxEdgeDist, max(distAB, distCD))
124+
maxPointDist = max(maxPointDist, pointDist)
125125
}
126126
}
127127

s2/edge_distances.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func UpdateMinDistance(x, a, b Point, minDist s1.ChordAngle) (s1.ChordAngle, boo
6060
// than maxDist, and if so, returns the updated value and true.
6161
// Otherwise it returns false. The case A == B is handled correctly.
6262
func UpdateMaxDistance(x, a, b Point, maxDist s1.ChordAngle) (s1.ChordAngle, bool) {
63-
dist := maxChordAngle(ChordAngleBetweenPoints(x, a), ChordAngleBetweenPoints(x, b))
63+
dist := max(ChordAngleBetweenPoints(x, a), ChordAngleBetweenPoints(x, b))
6464
if dist > s1.RightChordAngle {
6565
dist, _ = updateMinDistance(Point{x.Mul(-1)}, a, b, dist, true)
6666
dist = s1.StraightChordAngle - dist

s2/edge_query_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func generateEdgeQueryWithTargets(opts *edgeQueryBenchmarkOptions, query *EdgeQu
448448
numTargets := maxTargetsPerIndex
449449
if opts.targetType == queryTypeIndex {
450450
// Limit the total number of target edges to reduce the benchmark running times.
451-
numTargets = minInt(numTargets, 500000/opts.numTargetEdges)
451+
numTargets = min(numTargets, 500000/opts.numTargetEdges)
452452
}
453453

454454
for i := 0; i < numTargets; i++ {

s2/edge_tessellator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ type EdgeTessellator struct {
196196
func NewEdgeTessellator(p Projection, tolerance s1.Angle) *EdgeTessellator {
197197
return &EdgeTessellator{
198198
projection: p,
199-
scaledTolerance: s1.ChordAngleFromAngle(maxAngle(tolerance, minTessellationTolerance)),
199+
scaledTolerance: s1.ChordAngleFromAngle(max(tolerance, minTessellationTolerance)),
200200
}
201201
}
202202

@@ -287,5 +287,5 @@ func (e *EdgeTessellator) estimateMaxError(pa r2.Point, a Point, pb r2.Point, b
287287
mid2 := Interpolate(t2, a, b)
288288
pmid1 := e.projection.Unproject(e.projection.Interpolate(t1, pa, pb))
289289
pmid2 := e.projection.Unproject(e.projection.Interpolate(t2, pa, pb))
290-
return maxChordAngle(ChordAngleBetweenPoints(mid1, pmid1), ChordAngleBetweenPoints(mid2, pmid2))
290+
return max(ChordAngleBetweenPoints(mid1, pmid1), ChordAngleBetweenPoints(mid2, pmid2))
291291
}

0 commit comments

Comments
 (0)