Skip to content

Commit 5906ab3

Browse files
authored
Use clampInt (#231)
Replace min(max(...), ...) with clampInt.
1 parent b937987 commit 5906ab3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

s2/builder_snapper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ func (sf IntLatLngSnapper) exponentForMaxSnapRadius(snapRadius s1.Angle) int {
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 max(minIntSnappingExponent,
439-
min(maxIntSnappingExponent, int(math.Ceil(exponent-2*dblEpsilon))))
438+
return clampInt(int(math.Ceil(exponent-2*dblEpsilon)),
439+
minIntSnappingExponent, maxIntSnappingExponent)
440440
}
441441

442442
// MinVertexSeparation reports the minimum separation between vertices depending on

s2/regioncoverer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,24 +336,24 @@ func (c *coverer) coveringInternal(region Region) {
336336
// newCoverer returns an instance of coverer.
337337
func (rc *RegionCoverer) newCoverer() *coverer {
338338
return &coverer{
339-
minLevel: max(0, min(MaxLevel, rc.MinLevel)),
340-
MaxLevel: max(0, min(MaxLevel, rc.MaxLevel)),
341-
levelMod: max(1, min(3, rc.LevelMod)),
339+
minLevel: clampInt(rc.MinLevel, 0, MaxLevel),
340+
MaxLevel: clampInt(rc.MaxLevel, 0, MaxLevel),
341+
levelMod: clampInt(rc.LevelMod, 1, 3),
342342
maxCells: rc.MaxCells,
343343
}
344344
}
345345

346346
// Covering returns a CellUnion that covers the given region and satisfies the various restrictions.
347347
func (rc *RegionCoverer) Covering(region Region) CellUnion {
348348
covering := rc.CellUnion(region)
349-
covering.Denormalize(max(0, min(MaxLevel, rc.MinLevel)), max(1, min(3, rc.LevelMod)))
349+
covering.Denormalize(clampInt(rc.MinLevel, 0, MaxLevel), clampInt(rc.LevelMod, 1, 3))
350350
return covering
351351
}
352352

353353
// InteriorCovering returns a CellUnion that is contained within the given region and satisfies the various restrictions.
354354
func (rc *RegionCoverer) InteriorCovering(region Region) CellUnion {
355355
intCovering := rc.InteriorCellUnion(region)
356-
intCovering.Denormalize(max(0, min(MaxLevel, rc.MinLevel)), max(1, min(3, rc.LevelMod)))
356+
intCovering.Denormalize(clampInt(rc.MinLevel, 0, MaxLevel), clampInt(rc.LevelMod, 1, 3))
357357
return intCovering
358358
}
359359

0 commit comments

Comments
 (0)