diff --git a/s1/angle_test.go b/s1/angle_test.go index 91360bad..1ae3d66a 100644 --- a/s1/angle_test.go +++ b/s1/angle_test.go @@ -145,7 +145,7 @@ func TestDegreesVsRadians(t *testing.T) { } } - for k := uint64(0); k < 30; k++ { + for k := range uint64(30) { m := 1 << k n := float64(m) for _, test := range []struct{ deg, rad float64 }{ diff --git a/s1/chordangle_test.go b/s1/chordangle_test.go index db89c573..3bcd5424 100644 --- a/s1/chordangle_test.go +++ b/s1/chordangle_test.go @@ -118,7 +118,7 @@ func TestChordAngleSuccessor(t *testing.T) { t.Errorf("InfChordAngle.Successor() = %v, want %v", got, want) } x := NegativeChordAngle - for i := 0; i < 10; i++ { + for i := range 10 { if x >= x.Successor() { t.Errorf("%d. %0.24f >= %0.24f.Successor() = %0.24f, want <", i, x, x, x.Successor()) } @@ -137,7 +137,7 @@ func TestChordAnglePredecessor(t *testing.T) { t.Errorf("NegativeChordAngle.Predecessor() = %v, want %v", got, want) } x := InfChordAngle() - for i := 0; i < 10; i++ { + for range 10 { if x <= x.Predecessor() { t.Errorf("%v <= %v.Predecessor() = %v, want <", x, x, x.Predecessor()) } diff --git a/s2/builder_snapper_test.go b/s2/builder_snapper_test.go index 31afdda8..8f3d1c0d 100644 --- a/s2/builder_snapper_test.go +++ b/s2/builder_snapper_test.go @@ -64,7 +64,7 @@ func TestCellIDSnapperLevelToFromSnapRadius(t *testing.T) { } func TestCellIDSnapperSnapPoint(t *testing.T) { - for iter := 0; iter < 1; iter++ { + for range 1 { for level := 0; level <= MaxLevel; level++ { // This checks that points are snapped to the correct level, since // CellID centers at different levels are always different. diff --git a/s2/cap.go b/s2/cap.go index ef6ca645..dcb73912 100644 --- a/s2/cap.go +++ b/s2/cap.go @@ -341,7 +341,7 @@ func radiusToHeight(r s1.Angle) float64 { func (c Cap) ContainsCell(cell Cell) bool { // If the cap does not contain all cell vertices, return false. var vertices [4]Point - for k := 0; k < 4; k++ { + for k := range 4 { vertices[k] = cell.Vertex(k) if !c.ContainsPoint(vertices[k]) { return false @@ -355,7 +355,7 @@ func (c Cap) ContainsCell(cell Cell) bool { func (c Cap) IntersectsCell(cell Cell) bool { // If the cap contains any cell vertex, return true. var vertices [4]Point - for k := 0; k < 4; k++ { + for k := range 4 { vertices[k] = cell.Vertex(k) if c.ContainsPoint(vertices[k]) { return true @@ -389,7 +389,7 @@ func (c Cap) intersects(cell Cell, vertices [4]Point) bool { // does not contain any cell vertex. The only way that they can intersect is if the // cap intersects the interior of some edge. sin2Angle := c.radius.Sin2() - for k := 0; k < 4; k++ { + for k := range 4 { edge := cell.Edge(k).Vector dot := c.center.Dot(edge) if dot > 0 { @@ -429,7 +429,7 @@ func (c Cap) CellUnionBound() []CellID { // If level < 0, more than three face cells are required. if level < 0 { cellIDs := make([]CellID, 6) - for face := 0; face < 6; face++ { + for face := range 6 { cellIDs[face] = CellIDFromFace(face) } return cellIDs diff --git a/s2/cap_test.go b/s2/cap_test.go index b68dd91e..9b7f2383 100644 --- a/s2/cap_test.go +++ b/s2/cap_test.go @@ -453,7 +453,7 @@ func TestCapAddCap(t *testing.T) { func TestCapContainsCell(t *testing.T) { faceRadius := math.Atan(math.Sqrt2) - for face := 0; face < 6; face++ { + for face := range 6 { // The cell consisting of the entire face. rootCell := CellFromCellID(CellIDFromFace(face)) @@ -480,7 +480,7 @@ func TestCapContainsCell(t *testing.T) { } } - for capFace := 0; capFace < 6; capFace++ { + for capFace := range 6 { // A cap that barely contains all of capFace. center := unitNorm(capFace) covering := CapFromCenterAngle(center, s1.Angle(faceRadius+epsilon)) @@ -514,7 +514,7 @@ func TestCapContainsCell(t *testing.T) { func TestCapIntersectsCell(t *testing.T) { faceRadius := math.Atan(math.Sqrt2) - for face := 0; face < 6; face++ { + for face := range 6 { // The cell consisting of the entire face. rootCell := CellFromCellID(CellIDFromFace(face)) @@ -542,7 +542,7 @@ func TestCapIntersectsCell(t *testing.T) { } antiFace := (face + 3) % 6 - for capFace := 0; capFace < 6; capFace++ { + for capFace := range 6 { // A cap that barely contains all of capFace. center := unitNorm(capFace) covering := CapFromCenterAngle(center, s1.Angle(faceRadius+epsilon)) @@ -593,7 +593,7 @@ func TestCapCentroid(t *testing.T) { } // Random caps. - for i := 0; i < 100; i++ { + for range 100 { center := randomPoint() height := randomUniformFloat64(0.0, 2.0) c := CapFromCenterHeight(center, height) diff --git a/s2/cell.go b/s2/cell.go index ee042cda..5f1023c1 100644 --- a/s2/cell.go +++ b/s2/cell.go @@ -223,7 +223,7 @@ func (c Cell) Children() ([4]Cell, bool) { // Create four children with the appropriate bounds. cid := c.id.ChildBegin() - for pos := 0; pos < 4; pos++ { + for pos := range 4 { children[pos] = Cell{ face: c.face, level: c.level + 1, @@ -446,7 +446,7 @@ func (c Cell) CapBound() Cap { // to GetCenter() and faster to compute. Neither one of these vectors yields the // bounding cap with minimal surface area, but they are both pretty close. cap := CapFromPoint(Point{faceUVToXYZ(int(c.face), c.uv.Center().X, c.uv.Center().Y).Normalize()}) - for k := 0; k < 4; k++ { + for k := range 4 { cap = cap.AddPoint(c.Vertex(k)) } return cap @@ -693,7 +693,7 @@ func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle { // Otherwise, check whether the edge crosses the cell boundary. crosser := NewChainEdgeCrosser(a, b, c.Vertex(3)) - for i := 0; i < 4; i++ { + for i := range 4 { if crosser.ChainCrossingSign(c.Vertex(i)) != DoNotCross { return 0 } @@ -706,7 +706,7 @@ func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle { // Note that we don't need to check the distance from the interior of AB to // the interior of a cell edge, because the only way that this distance can // be minimal is if the two edges cross (already checked above). - for i := 0; i < 4; i++ { + for i := range 4 { minDist, _ = UpdateMinDistance(c.Vertex(i), a, b, minDist) } return minDist @@ -744,13 +744,13 @@ func (c Cell) DistanceToCell(target Cell) s1.ChordAngle { // the set of possible closest vertex/edge pairs using the faces and (u,v) // ranges of both cells. var va, vb [4]Point - for i := 0; i < 4; i++ { + for i := range 4 { va[i] = c.Vertex(i) vb[i] = target.Vertex(i) } minDist := s1.InfChordAngle() - for i := 0; i < 4; i++ { - for j := 0; j < 4; j++ { + for i := range 4 { + for j := range 4 { minDist, _ = UpdateMinDistance(va[i], vb[j], vb[(j+1)&3], minDist) minDist, _ = UpdateMinDistance(vb[i], va[j], va[(j+1)&3], minDist) } @@ -777,13 +777,13 @@ func (c Cell) MaxDistanceToCell(target Cell) s1.ChordAngle { // always attained between a pair of vertices, and this could be made much // faster by testing each vertex pair once rather than the current 4 times. var va, vb [4]Point - for i := 0; i < 4; i++ { + for i := range 4 { va[i] = c.Vertex(i) vb[i] = target.Vertex(i) } maxDist := s1.NegativeChordAngle - for i := 0; i < 4; i++ { - for j := 0; j < 4; j++ { + for i := range 4 { + for j := range 4 { maxDist, _ = UpdateMaxDistance(va[i], vb[j], vb[(j+1)&3], maxDist) maxDist, _ = UpdateMaxDistance(vb[i], va[j], va[(j+1)&3], maxDist) } diff --git a/s2/cell_index_test.go b/s2/cell_index_test.go index e3a482d5..bf41346d 100644 --- a/s2/cell_index_test.go +++ b/s2/cell_index_test.go @@ -332,7 +332,7 @@ func TestCellIndexRandomCellUnions(t *testing.T) { // because the cell level is chosen uniformly, there is a very high // likelihood that the cell unions will overlap. index := &CellIndex{} - for i := int32(0); i < 100; i++ { + for i := range int32(100) { index.AddCellUnion(randomCellUnion(10), i) } cellIndexQuadraticValidate(t, "Random Cell Unions", index, nil) diff --git a/s2/cell_test.go b/s2/cell_test.go index b173a5e0..27524183 100644 --- a/s2/cell_test.go +++ b/s2/cell_test.go @@ -36,7 +36,7 @@ func TestCellFaces(t *testing.T) { edgeCounts := make(map[Point]int) vertexCounts := make(map[Point]int) - for face := 0; face < 6; face++ { + for face := range 6 { id := CellIDFromFace(face) cell := CellFromCellID(id) @@ -60,7 +60,7 @@ func TestCellFaces(t *testing.T) { if cell.IsLeaf() { t.Errorf("cell should not be a leaf: IsLeaf = %v", cell.IsLeaf()) } - for k := 0; k < 4; k++ { + for k := range 4 { edgeCounts[cell.EdgeRaw(k)]++ vertexCounts[cell.VertexRaw(k)]++ if d := cell.VertexRaw(k).Dot(cell.EdgeRaw(k).Vector); !float64Eq(0.0, d) { @@ -105,7 +105,7 @@ func TestCellUVCoordOfEdge(t *testing.T) { CellFromCellID(CellIDFromToken("91")), } - for k := 0; k < 4; k++ { + for k := range 4 { if got, want := cell0[k].UVCoordOfEdge(k+0), 0.0; !float64Eq(got, want) { t.Errorf("%v.UVCoordOfEdge[%d] = %f, want %f", cell4[k], k+0, got, want) } @@ -122,7 +122,7 @@ func TestCellUVCoordOfEdge(t *testing.T) { } func Test2CellIJCoordOfEdge(t *testing.T) { - for i := 0; i < 100; i++ { + for range 100 { id := randomCellID() cell := CellFromCellID(id) @@ -141,7 +141,7 @@ func Test2CellIJCoordOfEdge(t *testing.T) { ijBounds.Y.Hi = float64(ijLo + ijSize) // Check that each boundary coordinate is correct. - for k := 0; k < 4; k++ { + for k := range 4 { got := cell.IJCoordOfEdge(k) var want int if (k+1)%2 == 0 { @@ -200,7 +200,7 @@ func testCellChildren(t *testing.T, cell Cell) { t.Errorf("%v.Center() = %v, want %v", ci, ci.Center(), direct.Center()) } - for k := 0; k < 4; k++ { + for k := range 4 { if !direct.VertexRaw(k).ApproxEqual(ci.VertexRaw(k)) { t.Errorf("child %d %v.VertexRaw(%d) = %v, want %v", i, ci, k, ci.VertexRaw(k), direct.VertexRaw(k)) } @@ -222,7 +222,7 @@ func testCellChildren(t *testing.T, cell Cell) { if !cell.ContainsPoint(ci.Center()) { t.Errorf("%v.ContainsPoint(%v) = false, want true", cell, ci.Center()) } - for j := 0; j < 4; j++ { + for j := range 4 { if !cell.ContainsPoint(ci.VertexRaw(j)) { t.Errorf("%v.ContainsPoint(%v.VertexRaw(%d)) = false, want true", cell, ci, j) } @@ -258,7 +258,7 @@ func testCellChildren(t *testing.T, cell Cell) { if !parentRect.ContainsPoint(ci.Center()) { t.Errorf("parentRect %v.ContainsPoint(%v.Center()) = false, want true", parentRect, ci) } - for j := 0; j < 4; j++ { + for j := range 4 { if !childCap.ContainsPoint(ci.Vertex(j)) { t.Errorf("childCap %v.ContainsPoint(%v.Vertex(%d)) = false, want true", childCap, ci, j) } @@ -282,7 +282,7 @@ func testCellChildren(t *testing.T, cell Cell) { // they exclude at least two vertices of each adjacent cell. capCount := 0 rectCount := 0 - for k := 0; k < 4; k++ { + for k := range 4 { if childCap.ContainsPoint(children[j].Vertex(k)) { capCount++ } @@ -476,7 +476,7 @@ func TestCellRectBound(t *testing.T) { for _, test := range tests { c := CellFromLatLng(LatLngFromDegrees(test.lat, test.lng)) rect := c.RectBound() - for i := 0; i < 4; i++ { + for i := range 4 { if !rect.ContainsLatLng(LatLngFromPoint(c.Vertex(i))) { t.Errorf("%v should contain %v", rect, c.Vertex(i)) } @@ -521,7 +521,7 @@ func TestCellRectBoundAroundPoleMinLat(t *testing.T) { func TestCellCapBound(t *testing.T) { c := CellFromCellID(CellIDFromFace(0).ChildBeginAtLevel(20)) s2Cap := c.CapBound() - for i := 0; i < 4; i++ { + for i := range 4 { if !s2Cap.ContainsPoint(c.Vertex(i)) { t.Errorf("%v should contain %v", s2Cap, c.Vertex(i)) } @@ -560,7 +560,7 @@ func TestCellContainsPoint(t *testing.T) { func TestCellContainsPointConsistentWithS2CellIDFromPoint(t *testing.T) { // Construct many points that are nearly on a Cell edge, and verify that // CellFromCellID(cellIDFromPoint(p)).Contains(p) is always true. - for iter := 0; iter < 1000; iter++ { + for range 1000 { cell := CellFromCellID(randomCellID()) i1 := randomUniformInt(4) i2 := (i1 + 1) & 3 @@ -605,7 +605,7 @@ func TestCellContainsPointContainsAmbiguousPoint(t *testing.T) { } func TestCellDistance(t *testing.T) { - for iter := 0; iter < 1000; iter++ { + for range 1000 { cell := CellFromCellID(randomCellID()) target := randomPoint() @@ -677,7 +677,7 @@ func chooseEdgeNearCell(cell Cell) (a, b Point) { func minDistanceToPointBruteForce(cell Cell, target Point) s1.ChordAngle { minDistance := s1.InfChordAngle() - for i := 0; i < 4; i++ { + for i := range 4 { minDistance, _ = UpdateMinDistance(target, cell.Vertex(i), cell.Vertex((i+1)%4), minDistance) } @@ -689,7 +689,7 @@ func maxDistanceToPointBruteForce(cell Cell, target Point) s1.ChordAngle { return s1.StraightChordAngle } maxDistance := s1.NegativeChordAngle - for i := 0; i < 4; i++ { + for i := range 4 { maxDistance, _ = UpdateMaxDistance(target, cell.Vertex(i), cell.Vertex((i+1)%4), maxDistance) } @@ -702,7 +702,7 @@ func minDistanceToEdgeBruteForce(cell Cell, a, b Point) s1.ChordAngle { } minDist := s1.InfChordAngle() - for i := 0; i < 4; i++ { + for i := range 4 { v0 := cell.Vertex(i) v1 := cell.Vertex((i + 1) % 4) // If the antipodal edge crosses through the cell, min distance is 0. @@ -723,7 +723,7 @@ func maxDistanceToEdgeBruteForce(cell Cell, a, b Point) s1.ChordAngle { } maxDist := s1.NegativeChordAngle - for i := 0; i < 4; i++ { + for i := range 4 { v0 := cell.Vertex(i) v1 := cell.Vertex((i + 1) % 4) // If the antipodal edge crosses through the cell, min distance is Pi. @@ -741,7 +741,7 @@ func TestCellDistanceToEdge(t *testing.T) { // TODO: Is it still about 0.1% flaky with a random seed. // TODO(rsned): https://github.com/golang/geo/issues/120 - for iter := 0; iter < 1000; iter++ { + for range 1000 { cell := CellFromCellID(randomCellID()) a, b := chooseEdgeNearCell(cell) @@ -803,7 +803,7 @@ func TestCellMaxDistanceToCellAntipodal(t *testing.T) { } func TestCellMaxDistanceToCell(t *testing.T) { - for i := 0; i < 1000; i++ { + for range 1000 { cell := CellFromCellID(randomCellID()) testCell := CellFromCellID(randomCellID()) antipodalLeafID := cellIDFromPoint(Point{testCell.Center().Mul(-1)}) diff --git a/s2/cellid_test.go b/s2/cellid_test.go index 9cf63ae1..a5cc8e22 100644 --- a/s2/cellid_test.go +++ b/s2/cellid_test.go @@ -25,7 +25,7 @@ import ( ) func TestCellIDFromFace(t *testing.T) { - for face := 0; face < 6; face++ { + for face := range 6 { fpl := CellIDFromFacePosLevel(face, 0, 0) f := CellIDFromFace(face) if fpl != f { @@ -289,7 +289,7 @@ func dedupCellIDs(ids []CellID) []CellID { func TestCellIDAllNeighbors(t *testing.T) { // Check that AllNeighbors produces results that are consistent // with VertexNeighbors for a bunch of random cells. - for i := 0; i < 1000; i++ { + for range 1000 { id := randomCellID() if id.IsLeaf() { id = id.immediateParent() @@ -883,13 +883,13 @@ func projectToBoundary(u, v float64, rect r2.Rect) r2.Point { func TestCellIDExpandedByDistanceUV(t *testing.T) { const maxDistDegrees = 10 - for i := 0; i < 1000; i++ { + for range 1000 { id := randomCellID() distance := s1.Degree * s1.Angle(randomUniformFloat64(-maxDistDegrees, maxDistDegrees)) bound := id.boundUV() expanded := expandedByDistanceUV(bound, distance) - for iter := 0; iter < 10; iter++ { + for range 10 { // Choose a point on the boundary of the rectangle. face := randomUniformInt(6) centerU, centerV := sampleBoundary(bound) @@ -932,7 +932,7 @@ func TestCellIDExpandedByDistanceUV(t *testing.T) { func TestCellIDMaxTile(t *testing.T) { // This method is also tested more thoroughly in s2cellunion_test. - for iter := 0; iter < 1000; iter++ { + for range 1000 { id := randomCellIDForLevel(10) // Check that limit is returned for tiles at or beyond limit. diff --git a/s2/cellunion.go b/s2/cellunion.go index 1e892020..36993c9a 100644 --- a/s2/cellunion.go +++ b/s2/cellunion.go @@ -501,7 +501,7 @@ func (cu CellUnion) Equal(o CellUnion) bool { if len(cu) != len(o) { return false } - for i := 0; i < len(cu); i++ { + for i := range cu { if cu[i] != o[i] { return false } diff --git a/s2/cellunion_test.go b/s2/cellunion_test.go index 6c3e9744..e0b1e914 100644 --- a/s2/cellunion_test.go +++ b/s2/cellunion_test.go @@ -303,7 +303,7 @@ func addCells(id CellID, selected bool, input *[]CellID, expected *[]CellID, t * if id == 0 { // Initial call: decide whether to add cell(s) from each face. - for face := 0; face < 6; face++ { + for face := range 6 { addCells(CellIDFromFace(face), false, input, expected, t) } return @@ -389,7 +389,7 @@ func TestCellUnionNormalizePseudoRandom(t *testing.T) { outSum := 0 iters := 2000 - for i := 0; i < iters; i++ { + for range iters { input := []CellID{} expected := []CellID{} addCells(CellID(0), false, &input, &expected, t) @@ -723,7 +723,7 @@ func TestCellUnionLeafCellsCovered(t *testing.T) { } func TestCellUnionFromRange(t *testing.T) { - for iter := 0; iter < 2000; iter++ { + for range 2000 { min := randomCellIDForLevel(MaxLevel) max := randomCellIDForLevel(MaxLevel) if min > max { @@ -778,7 +778,7 @@ func TestCellUnionFromRange(t *testing.T) { func TestCellUnionFromUnionDiffIntersection(t *testing.T) { const iters = 2000 - for i := 0; i < iters; i++ { + for range iters { input := []CellID{} expected := []CellID{} addCells(CellID(0), false, &input, &expected, t) @@ -880,7 +880,7 @@ func cellUnionDistanceFromAxis(cu CellUnion, axis Point) float64 { var maxDist float64 for _, cid := range cu { cell := CellFromCellID(cid) - for j := 0; j < 4; j++ { + for j := range 4 { a := cell.Vertex(j) b := cell.Vertex((j + 1) & 3) var dist float64 @@ -908,7 +908,7 @@ func TestCellUnionExpand(t *testing.T) { // the coverings by a random radius, and then make sure that the new // covering covers the expanded cap. It also makes sure that the // new covering is not too much larger than expected. - for i := 0; i < 5000; i++ { + for range 5000 { rndCap := randomCap(AvgAreaMetric.Value(MaxLevel), 4*math.Pi) // Expand the cap area by a random factor whose log is uniformly @@ -959,7 +959,7 @@ func TestCellUnionExpand(t *testing.T) { // invalid value is used as the ID, then all faces are checked. func checkCellUnionCovering(t *testing.T, r Region, covering CellUnion, checkTight bool, id CellID) { if !id.IsValid() { - for face := 0; face < 6; face++ { + for face := range 6 { checkCellUnionCovering(t, r, covering, checkTight, CellIDFromFace(face)) } return diff --git a/s2/centroids_test.go b/s2/centroids_test.go index 1cf82754..811bcb19 100644 --- a/s2/centroids_test.go +++ b/s2/centroids_test.go @@ -53,7 +53,7 @@ func TestCentroidsPlanarCentroid(t *testing.T) { func TestCentroidsTrueCentroid(t *testing.T) { // Test TrueCentroid with very small triangles. This test assumes that // the triangle is small enough so that it is nearly planar. - for i := 0; i < 100; i++ { + for range 100 { f := randomFrame() p := f.col(0) x := f.col(1) @@ -112,7 +112,7 @@ func TestCentroidsEdgeTrueCentroidGreatCircles(t *testing.T) { // // Note that this is a direct test of the properties that the centroid // should have, rather than a test that it matches a particular formula. - for iter := 0; iter < 100; iter++ { + for range 100 { f := randomFrameAtPoint(randomPoint()) x := f.col(0) y := f.col(1) diff --git a/s2/contains_point_query_test.go b/s2/contains_point_query_test.go index 3080acd1..0a3d82d3 100644 --- a/s2/contains_point_query_test.go +++ b/s2/contains_point_query_test.go @@ -142,13 +142,13 @@ func TestContainsPointQueryContainingShapes(t *testing.T) { centerCap := CapFromCenterAngle(randomPoint(), maxLoopRadius) index := NewShapeIndex() - for i := 0; i < 100; i++ { + for range 100 { index.Add(RegularLoop(samplePointFromCap(centerCap), s1.Angle(randomFloat64())*maxLoopRadius, numVerticesPerLoop)) } query := NewContainsPointQuery(index, VertexModelSemiOpen) - for i := 0; i < 100; i++ { + for i := range 100 { p := samplePointFromCap(centerCap) var want []Shape diff --git a/s2/convex_hull_query_test.go b/s2/convex_hull_query_test.go index e6fb2add..47ac93e2 100644 --- a/s2/convex_hull_query_test.go +++ b/s2/convex_hull_query_test.go @@ -132,7 +132,7 @@ func TestConvexHullQueryNonConvexPoints(t *testing.T) { // sphere by repeatedly linearly interpolating between the points. (The // four points of a tetrahedron would also work, but this is easier.) query := NewConvexHullQuery() - for face := 0; face < 6; face++ { + for face := range 6 { query.AddPoint(CellIDFromFace(face).Point()) } result := query.ConvexHull() @@ -193,14 +193,14 @@ func TestConvexHullQueryPointsInsideHull(t *testing.T) { // inside that loop and build the convex hull again. The result should // always be the same. const iters = 1000 - for iter := 0; iter < iters; iter++ { + for range iters { // Choose points from within a cap of random size, up to but not including // an entire hemisphere. c := randomCap(1e-15, 1.999*math.Pi) numPoints1 := randomUniformInt(100) + 3 query := NewConvexHullQuery() - for i := 0; i < numPoints1; i++ { + for range numPoints1 { query.AddPoint(samplePointFromCap(c)) } hull := query.ConvexHull() @@ -223,7 +223,7 @@ func TestConvexHullQueryPointsInsideHull(t *testing.T) { // Otherwise, add more points inside the convex hull. const numPoints2 = 1000 - for i := 0; i < numPoints2; i++ { + for range numPoints2 { p := samplePointFromCap(c) if hull.ContainsPoint(p) { query.AddPoint(p) diff --git a/s2/crossing_edge_query.go b/s2/crossing_edge_query.go index ed86accd..fe8f388f 100644 --- a/s2/crossing_edge_query.go +++ b/s2/crossing_edge_query.go @@ -62,7 +62,7 @@ func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType Crossin out := 0 n := len(edges) - for in := 0; in < n; in++ { + for in := range n { b := shape.Edge(edges[in]) sign := crosser.CrossingSign(b.V0, b.V1) if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { @@ -97,7 +97,7 @@ func (c *CrossingEdgeQuery) CrossingsEdgeMap(a, b Point, crossType CrossingType) for shape, edges := range edgeMap { out := 0 n := len(edges) - for in := 0; in < n; in++ { + for in := range n { edge := shape.Edge(edges[in]) sign := crosser.CrossingSign(edge.V0, edge.V1) if (crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross)) || (crossType != CrossingTypeAll && sign == Cross) { @@ -128,7 +128,7 @@ func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { maxEdges := shape.NumEdges() if maxEdges <= maxBruteForceEdges { edges = make([]int, maxEdges) - for i := 0; i < maxEdges; i++ { + for i := range maxEdges { edges[i] = i } return edges diff --git a/s2/crossing_edge_query_test.go b/s2/crossing_edge_query_test.go index 1fadd2f4..f19bfd69 100644 --- a/s2/crossing_edge_query_test.go +++ b/s2/crossing_edge_query_test.go @@ -56,7 +56,7 @@ func generatePerturbedSubEdges(a, b Point, count int) []Edge { b = Point{b.Normalize()} length0 := a.Distance(b) - for i := 0; i < count; i++ { + for range count { length := length0 * s1.Angle(math.Pow(1e-15, randomFloat64())) offset := (length0 - length) * s1.Angle(randomFloat64()) edges = append(edges, Edge{ @@ -71,7 +71,7 @@ func generatePerturbedSubEdges(a, b Point, count int) []Edge { // whose length is randomly chosen up to maxLength. func generateCapEdges(centerCap Cap, maxLength s1.Angle, count int) []Edge { var edges []Edge - for i := 0; i < count; i++ { + for range count { center := samplePointFromCap(centerCap) edgeCap := CapFromCenterAngle(center, 0.5*maxLength) p1 := samplePointFromCap(edgeCap) @@ -231,7 +231,7 @@ func TestCrossingEdgeQueryCrossingCandidatesPerturbedCubeEdges(t *testing.T) { // This test is sufficient to demonstrate that padding the cell boundaries // is necessary for correctness. (It will fails if ShapeIndexes CellPadding is // set to zero.) - for iter := 0; iter < 10; iter++ { + for range 10 { face := randomUniformInt(6) scale := math.Pow(1e-15, randomFloat64()) u := scale*2*float64(randomUniformInt(2)) - 1 @@ -250,7 +250,7 @@ func TestCrossingEdgeQueryCrossingCandidatesPerturbedCubeEdges(t *testing.T) { // edges are special because one coordinate is zero, and they lie on the // boundaries between the immediate child cells of the cube face. func TestCrossingEdgeQueryCandidatesPerturbedCubeFaceAxes(t *testing.T) { - for iter := 0; iter < 5; iter++ { + for range 5 { face := randomUniformInt(6) scale := math.Pow(1e-15, randomFloat64()) axis := uvwAxis(face, randomUniformInt(2)) @@ -269,7 +269,7 @@ func TestCrossingEdgeQueryCandidatesCapEdgesNearCubeVertex(t *testing.T) { } func TestCrossingEdgeQueryCandidatesDegenerateEdgeOnCellVertexIsItsOwnCandidate(t *testing.T) { - for iter := 0; iter < 100; iter++ { + for range 100 { cell := CellFromCellID(randomCellID()) edges := []Edge{{cell.Vertex(0), cell.Vertex(0)}} testCrossingEdgeQueryAllCrossings(t, edges) diff --git a/s2/edge_clipping_test.go b/s2/edge_clipping_test.go index b30aae26..0185b193 100644 --- a/s2/edge_clipping_test.go +++ b/s2/edge_clipping_test.go @@ -143,7 +143,7 @@ func testClipToPaddedFace(t *testing.T, a, b Point) { aTan := Point{norm.Cross(a.Vector)} bTan := Point{b.Cross(norm.Vector)} - for i := 0; i < n; i++ { + for i := range n { // Vertices may not protrude outside the biunit square. if !biunit.ContainsPoint(segments[i].a) { t.Errorf("biunit.ContainsPoint(%v) = false, want true", segments[i].a) @@ -197,7 +197,7 @@ func testClipToPaddedFace(t *testing.T, a, b Point) { maxs := expectedAngles.Expanded(faceClipErrorRadians) var actualAngles s1.Interval - for face := 0; face < 6; face++ { + for face := range 6 { aUV, bUV, intersects := ClipToPaddedFace(a, b, face, padding) if !intersects { continue @@ -268,7 +268,7 @@ func TestEdgeClippingClipToPaddedFace(t *testing.T) { // that nearly follow one of the 12 cube edges. biunit := r2.Rect{X: r1.Interval{Lo: -1, Hi: 1}, Y: r1.Interval{Lo: -1, Hi: 1}} - for i := 0; i < 1000; i++ { + for range 1000 { // Choose two adjacent cube corners P and Q. face := randomUniformInt(6) i := randomUniformInt(4) @@ -395,7 +395,7 @@ func TestEdgeClippingClipEdge(t *testing.T) { } for _, r := range testRects { - for i := 0; i < 1000; i++ { + for range 1000 { a := chooseRectEndpoint(r) b := chooseRectEndpoint(r) diff --git a/s2/edge_crossings_test.go b/s2/edge_crossings_test.go index c89e7d9f..04523426 100644 --- a/s2/edge_crossings_test.go +++ b/s2/edge_crossings_test.go @@ -41,7 +41,7 @@ func TestEdgeutilIntersectionError(t *testing.T) { // exact intersection point and also to the edges. var maxPointDist, maxEdgeDist s1.Angle - for iter := 0; iter < 5000; iter++ { + for range 5000 { // We construct two edges AB and CD that intersect near "p". The angle // between AB and CD (expressed as a slope) is chosen randomly between // 1e-15 and 1e15 such that its logarithm is uniformly distributed. diff --git a/s2/edge_distances_test.go b/s2/edge_distances_test.go index 32cafe6b..a943c40e 100644 --- a/s2/edge_distances_test.go +++ b/s2/edge_distances_test.go @@ -473,10 +473,10 @@ func TestEdgeDistancesInterpolateAntipodal(t *testing.T) { func TestEdgeDistancesRepeatedInterpolation(t *testing.T) { // Check that points do not drift away from unit length when repeated // interpolations are done. - for i := 0; i < 100; i++ { + for range 100 { a := randomPoint() b := randomPoint() - for j := 0; j < 1000; j++ { + for range 1000 { a = Interpolate(0.01, a, b) } if !a.IsUnit() { diff --git a/s2/edge_query_test.go b/s2/edge_query_test.go index e584d7b6..66f82a55 100644 --- a/s2/edge_query_test.go +++ b/s2/edge_query_test.go @@ -203,7 +203,7 @@ func fractalLoopShapeIndexGenerator(c Cap, numEdges int, index *ShapeIndex) { // fills the given Cap. func pointCloudShapeIndexGenerator(c Cap, numPoints int, index *ShapeIndex) { var points PointVector - for i := 0; i < numPoints; i++ { + for range numPoints { points = append(points, samplePointFromCap(c)) } index.Add(&points) diff --git a/s2/interleave_test.go b/s2/interleave_test.go index 13f10960..f7c772e7 100644 --- a/s2/interleave_test.go +++ b/s2/interleave_test.go @@ -26,7 +26,7 @@ func TestInterleaveUint32(t *testing.T) { func referenceBitInterleave(x, y uint32) uint64 { var ret uint64 - for i := uint(0); i < 32; i++ { + for i := range uint(32) { ret |= uint64((x>>i)&1) << (i * 2) ret |= uint64((y>>i)&1) << (i*2 + 1) } @@ -35,7 +35,7 @@ func referenceBitInterleave(x, y uint32) uint64 { func TestInterleaveUint32AgainstReference(t *testing.T) { // TODO(nsch): Add the remaining parts of the tests later. (the various other primes and bit AND-ings.) - for i := 0; i < 100000; i++ { + for i := range 100000 { wantEven := uint32(i) * 14233781 wantOdd := uint32(i) * 18400439 diff --git a/s2/lax_loop_test.go b/s2/lax_loop_test.go index f383074c..8ba483ce 100644 --- a/s2/lax_loop_test.go +++ b/s2/lax_loop_test.go @@ -59,7 +59,7 @@ func TestLaxLoopNonEmptyLoop(t *testing.T) { if got, want := shape.Chain(0).Length, len(vertices); got != want { t.Errorf("shape.Chain(0).Length = %v, want %v", got, want) } - for i := 0; i < len(vertices); i++ { + for i := range vertices { if got, want := shape.(*LaxLoop).vertex(i), vertices[i]; got != want { t.Errorf("%d. vertex(%d) = %v, want %v", i, i, got, want) } diff --git a/s2/lax_polygon_test.go b/s2/lax_polygon_test.go index 70101cd1..5eced6b5 100644 --- a/s2/lax_polygon_test.go +++ b/s2/lax_polygon_test.go @@ -150,7 +150,7 @@ func TestLaxPolygonShapeSingleLoopPolygon(t *testing.T) { if got, want := shape.Chain(0).Length, lenVerts; got != want { t.Errorf("shape.Chain(0).Length = %d, want %d", got, want) } - for i := 0; i < lenVerts; i++ { + for i := range lenVerts { if got, want := shape.loopVertex(0, i), vertices[i]; got != want { t.Errorf("shape.loopVertex(%d) = %v, want %v", i, got, want) } diff --git a/s2/loop.go b/s2/loop.go index 3421505c..c4b1e9d2 100644 --- a/s2/loop.go +++ b/s2/loop.go @@ -1509,7 +1509,7 @@ func (l *loopCrosser) startEdge(aj int) { func (l *loopCrosser) edgeCrossesCell(bClipped *clippedShape) bool { // Test the current edge of A against all edges of bClipped bNumEdges := bClipped.numEdges() - for j := 0; j < bNumEdges; j++ { + for j := range bNumEdges { bj := bClipped.edges[j] if bj != l.bjPrev+1 { l.crosser.RestartAt(l.b.Vertex(bj)) diff --git a/s2/loop_test.go b/s2/loop_test.go index 4677c708..7abfa21f 100644 --- a/s2/loop_test.go +++ b/s2/loop_test.go @@ -443,7 +443,7 @@ func TestLoopContainsPoint(t *testing.T) { }, } { l := tc.l - for i := 0; i < 4; i++ { + for i := range 4 { if !l.ContainsPoint(tc.in) { t.Errorf("%s loop should contain %v at rotation %d", tc.name, tc.in, i) } @@ -456,7 +456,7 @@ func TestLoopContainsPoint(t *testing.T) { // This code checks each cell vertex is contained by exactly one of // the adjacent cells. - for level := 0; level < 3; level++ { + for level := range 3 { // set of unique points across all loops at this level. points := make(map[Point]bool) var loops []*Loop @@ -464,7 +464,7 @@ func TestLoopContainsPoint(t *testing.T) { var vertices []Point cell := CellFromCellID(id) points[cell.Center()] = true - for k := 0; k < 4; k++ { + for k := range 4 { vertices = append(vertices, cell.Vertex(k)) points[cell.Vertex(k)] = true } @@ -732,7 +732,7 @@ func TestLoopContainsMatchesCrossingSign(t *testing.T) { } points := make([]Point, 4) - for i := 0; i < 4; i++ { + for i := range 4 { // Note extra normalization. Center() is already normalized. // The test results will no longer be inconsistent if the extra // Normalize() is removed. @@ -1560,7 +1560,7 @@ func TestLoopTurningAngle(t *testing.T) { // Set the center point of the spiral. vertices[armPoints] = PointFromCoords(0, 0, 1) - for i := 0; i < armPoints; i++ { + for i := range armPoints { angle := (2 * math.Pi / 3) * float64(i) x := math.Cos(angle) y := math.Sin(angle) @@ -1642,7 +1642,7 @@ func TestLoopAreaAndCentroid(t *testing.T) { // Construct spherical caps of random height, and approximate their boundary // with closely spaces vertices. Then check that the area and centroid are // correct. - for i := 0; i < 50; i++ { + for range 50 { // Choose a coordinate frame for the spherical cap. f := randomFrame() x := f.col(0) @@ -1863,7 +1863,7 @@ func BenchmarkLoopContainsPoint(b *testing.B) { func(b *testing.B) { b.StopTimer() loops := make([]*Loop, numLoopSamples) - for i := 0; i < numLoopSamples; i++ { + for i := range numLoopSamples { loops[i] = RegularLoop(randomPoint(), kmToAngle(10.0), vertices) } @@ -1871,7 +1871,7 @@ func BenchmarkLoopContainsPoint(b *testing.B) { for i, loop := range loops { queries[i] = make([]Point, numQueriesPerLoop) - for j := 0; j < numQueriesPerLoop; j++ { + for j := range numQueriesPerLoop { queries[i][j] = samplePointFromRect(loop.RectBound()) } } diff --git a/s2/max_distance_targets.go b/s2/max_distance_targets.go index 0409145e..a244c9e8 100644 --- a/s2/max_distance_targets.go +++ b/s2/max_distance_targets.go @@ -261,7 +261,7 @@ func (m *MaxDistanceToShapeIndexTarget) visitContainingShapes(index *ShapeIndex, numChains := shape.NumChains() // Shapes that don't have any edges require a special case (below). testedPoint := false - for c := 0; c < numChains; c++ { + for c := range numChains { chain := shape.Chain(c) if chain.Length == 0 { continue diff --git a/s2/max_distance_targets_test.go b/s2/max_distance_targets_test.go index e75e531c..518c959c 100644 --- a/s2/max_distance_targets_test.go +++ b/s2/max_distance_targets_test.go @@ -26,12 +26,12 @@ func TestDistanceTargetMaxCellTargetCapBound(t *testing.T) { var md maxDistance zero := md.zero() - for i := 0; i < 100; i++ { + for range 100 { cell := CellFromCellID(randomCellID()) target := NewMaxDistanceToCellTarget(cell) c := target.capBound() - for j := 0; j < 100; j++ { + for range 100 { pTest := randomPoint() // Check points outside of cap to be away from maxDistance's zero(). if !c.ContainsPoint(pTest) { @@ -432,7 +432,7 @@ func TestDistanceTargetMaxShapeIndexTargetCapBound(t *testing.T) { target := NewMaxDistanceToShapeIndexTarget(index) c := target.capBound() - for j := 0; j < 100; j++ { + for range 100 { pTest := randomPoint() // Check points outside of cap to be away from maxDistance's zero(). if !c.ContainsPoint(pTest) { diff --git a/s2/metric.go b/s2/metric.go index d2ca8dff..a75b0c6e 100644 --- a/s2/metric.go +++ b/s2/metric.go @@ -122,10 +122,7 @@ func (m Metric) MinLevel(val float64) int { return MaxLevel } - level := min(-(math.Ilogb(val/m.Deriv) >> uint(m.Dim-1)), MaxLevel) - if level < 0 { - level = 0 - } + level := max(min(-(math.Ilogb(val/m.Deriv)>>uint(m.Dim-1)), MaxLevel), 0) return level } @@ -141,10 +138,7 @@ func (m Metric) MaxLevel(val float64) int { return MaxLevel } - level := min(math.Ilogb(m.Deriv/val)>>uint(m.Dim-1), MaxLevel) - if level < 0 { - level = 0 - } + level := max(min(math.Ilogb(m.Deriv/val)>>uint(m.Dim-1), MaxLevel), 0) return level } diff --git a/s2/min_distance_targets.go b/s2/min_distance_targets.go index 1d2ad37b..1ab5be64 100644 --- a/s2/min_distance_targets.go +++ b/s2/min_distance_targets.go @@ -317,7 +317,7 @@ func (m *MinDistanceToShapeIndexTarget) visitContainingShapes(index *ShapeIndex, numChains := shape.NumChains() // Shapes that don't have any edges require a special case (below). testedPoint := false - for c := 0; c < numChains; c++ { + for c := range numChains { chain := shape.Chain(c) if chain.Length == 0 { continue diff --git a/s2/paddedcell_test.go b/s2/paddedcell_test.go index 4123579c..239fd1a7 100644 --- a/s2/paddedcell_test.go +++ b/s2/paddedcell_test.go @@ -24,7 +24,7 @@ import ( func TestPaddedCellMethods(t *testing.T) { // Test the PaddedCell methods that have approximate Cell equivalents. - for i := 0; i < 1000; i++ { + for range 1000 { cid := randomCellID() padding := math.Pow(1e-15, randomFloat64()) cell := CellFromCellID(cid) @@ -62,7 +62,7 @@ func TestPaddedCellMethods(t *testing.T) { t.Errorf("%v.Children() failed but should not have", cell) continue } - for pos := 0; pos < 4; pos++ { + for pos := range 4 { i, j := pCell.ChildIJ(pos) cellChild := children[pos] @@ -96,7 +96,7 @@ func TestPaddedCellMethods(t *testing.T) { } func TestPaddedCellEntryExitVertices(t *testing.T) { - for i := 0; i < 1000; i++ { + for range 1000 { id := randomCellID() unpadded := PaddedCellFromCellID(id, 0) padded := PaddedCellFromCellID(id, 0.5) @@ -132,7 +132,7 @@ func TestPaddedCellEntryExitVertices(t *testing.T) { } func TestPaddedCellShrinkToFit(t *testing.T) { - for iter := 0; iter < 1000; iter++ { + for range 1000 { // Start with the desired result and work backwards. result := randomCellID() resultUV := result.boundUV() diff --git a/s2/point_measures_test.go b/s2/point_measures_test.go index 15007364..33caf862 100644 --- a/s2/point_measures_test.go +++ b/s2/point_measures_test.go @@ -66,7 +66,7 @@ func TestPointMeasuresPointArea(t *testing.T) { } maxGirard := 0.0 - for i := 0; i < 10000; i++ { + for range 10000 { p0 := randomPoint() d1 := randomPoint() d2 := randomPoint() @@ -120,7 +120,7 @@ func TestPointMeasuresPointAreaQuarterHemisphere(t *testing.T) { // Compute the area of a hemisphere using four triangles with one near-180 // degree edge and one near-degenerate edge. - for i := 0; i < 100; i++ { + for range 100 { lng := s1.Angle(2 * math.Pi * randomFloat64()) p2Lng := lng + s1.Angle(randomFloat64()) p0 := PointFromLatLng(LatLng{1e-20, lng}.Normalized()) diff --git a/s2/point_test.go b/s2/point_test.go index 75c29197..5da788a9 100644 --- a/s2/point_test.go +++ b/s2/point_test.go @@ -100,7 +100,7 @@ func TestPointDistance(t *testing.T) { } func TestChordAngleBetweenPoints(t *testing.T) { - for iter := 0; iter < 100; iter++ { + for range 100 { m := randomFrame() x := m.col(0) y := m.col(1) @@ -232,7 +232,7 @@ func TestPointRegularPoints(t *testing.T) { // Make sure the angle between each point is correct. wantAngle := math.Pi / 2 - for i := 0; i < len(pts); i++ { + for i := range pts { // Mod the index by 4 to wrap the values at each end. v0, v1, v2 := pts[(4+i+1)%4], pts[(4+i)%4], pts[(4+i-1)%4] if got := float64(v0.Sub(v1.Vector).Angle(v2.Sub(v1.Vector))); !float64Eq(got, wantAngle) { @@ -242,7 +242,7 @@ func TestPointRegularPoints(t *testing.T) { // Make sure that all edges of the polygon have the same length. wantLength := 27.990890717782829 - for i := 0; i < len(lls); i++ { + for i := range lls { ll1, ll2 := lls[i], lls[(i+1)%4] if got := ll1.Distance(ll2).Degrees(); !float64Near(got, wantLength, epsilon) { t.Errorf("%v.Distance(%v) = %v, want %v", ll1, ll2, got, wantLength) @@ -296,7 +296,7 @@ func TestPointRegion(t *testing.T) { } func TestPointRotate(t *testing.T) { - for iter := 0; iter < 1000; iter++ { + for range 1000 { axis := randomPoint() target := randomPoint() // Choose a distance whose logarithm is uniformly distributed. diff --git a/s2/point_vector_test.go b/s2/point_vector_test.go index 69affc8a..56522cf6 100644 --- a/s2/point_vector_test.go +++ b/s2/point_vector_test.go @@ -45,7 +45,7 @@ func TestPointVectorBasics(t *testing.T) { const numPoints = 100 var p PointVector = make([]Point, numPoints) - for i := 0; i < numPoints; i++ { + for i := range numPoints { p[i] = randomPoint() } @@ -66,7 +66,7 @@ func TestPointVectorBasics(t *testing.T) { t.Errorf("shape.IsFull() = true, want false") } - for i := 0; i < numPoints; i++ { + for i := range numPoints { if got, want := shape.Chain(i).Start, i; got != want { t.Errorf("shape.Chain(%d).Start = %d, want %d", i, got, want) } diff --git a/s2/pointcompression.go b/s2/pointcompression.go index 40da10f3..7773dd32 100644 --- a/s2/pointcompression.go +++ b/s2/pointcompression.go @@ -97,7 +97,7 @@ func encodeFirstPointFixedLength(e *encoder, pi, qi uint32, level int, piCoder, // Write as little endian. bytesRequired := (level + 7) / 8 * 2 - for i := 0; i < bytesRequired; i++ { + for range bytesRequired { e.writeUint8(uint8(interleaved)) interleaved >>= 8 } @@ -243,7 +243,7 @@ func decodePointsCompressed(d *decoder, level int, target []Point) { d.err = fmt.Errorf("numOffCenter = %d, should be at most len(target) = %d", numOffCenter, len(target)) return } - for i := 0; i < numOffCenter; i++ { + for range numOffCenter { idx := int(d.readUvarint()) if d.err != nil { return @@ -261,7 +261,7 @@ func decodePointsCompressed(d *decoder, level int, target []Point) { func decodeFirstPointFixedLength(d *decoder, level int, piCoder, qiCoder *nthDerivativeCoder) (pi, qi uint32) { bytesToRead := (level + 7) / 8 * 2 var interleaved uint64 - for i := 0; i < bytesToRead; i++ { + for i := range bytesToRead { rr := d.readUint8() interleaved |= (uint64(rr) << uint(i*8)) } diff --git a/s2/pointcompression_test.go b/s2/pointcompression_test.go index a2cd9642..3a4707bd 100644 --- a/s2/pointcompression_test.go +++ b/s2/pointcompression_test.go @@ -47,7 +47,7 @@ func makeSnappedPoints(nvertices int, level int) []Point { func TestPointsCompression(t *testing.T) { loop100Mixed15 := makeSnappedPoints(100, MaxLevel) - for i := 0; i < 15; i++ { + for i := range 15 { loop100Mixed15[3*i] = CellFromPoint(loop100Mixed15[3*i]).ID().Parent(4).Point() } diff --git a/s2/polygon.go b/s2/polygon.go index 63078f9e..c14ccdff 100644 --- a/s2/polygon.go +++ b/s2/polygon.go @@ -773,7 +773,7 @@ func (p *Polygon) Chain(chainID int) Chain { return Chain{p.cumulativeEdges[chainID], len(p.Loop(chainID).vertices)} } e := 0 - for j := 0; j < chainID; j++ { + for j := range chainID { e += len(p.Loop(j).vertices) } diff --git a/s2/polygon_test.go b/s2/polygon_test.go index 47558e2f..52511a87 100644 --- a/s2/polygon_test.go +++ b/s2/polygon_test.go @@ -300,7 +300,7 @@ func reverseLoopVertices(l *Loop) { // shuffleLoops randomizes the slice of loops using Fisher-Yates shuffling. func shuffleLoops(loops []*Loop) { n := len(loops) - for i := 0; i < n; i++ { + for i := range n { // choose index uniformly in [i, n-1] r := i + rand.Intn(n-i) loops[r], loops[i] = loops[i], loops[r] @@ -338,7 +338,7 @@ func generatePolygonConcentricTestLoops(numLoops, minVertices int) []*Loop { var loops []*Loop center := randomPoint() numVertices := minVertices + randomUniformInt(10) - for i := 0; i < numLoops; i++ { + for i := range numLoops { radius := s1.Angle(80*math.Pow(0.1, float64(i))) * s1.Degree loops = append(loops, RegularLoop(center, radius, numVertices)) } @@ -373,7 +373,7 @@ func TestPolygonUninitializedIsValid(t *testing.T) { func TestPolygonIsValidLoopNestingInvalid(t *testing.T) { const iters = 1000 - for iter := 0; iter < iters; iter++ { + for range iters { loops := generatePolygonConcentricTestLoops(2+randomUniformInt(4), 3) // Randomly invert all the loops in order to generate cases where the // outer loop encompasses almost the entire sphere. This tests different diff --git a/s2/polyline.go b/s2/polyline.go index 4a1c1a1f..6185a16a 100644 --- a/s2/polyline.go +++ b/s2/polyline.go @@ -147,7 +147,7 @@ func (p *Polyline) IntersectsCell(cell Cell) bool { cell.Vertex(3), } - for j := 0; j < 4; j++ { + for j := range 4 { crosser := NewChainEdgeCrosser(cellVertices[j], cellVertices[(j+1)&3], (*p)[0]) for i := 1; i < len(*p); i++ { if crosser.ChainCrossingSign((*p)[i]) != DoNotCross { diff --git a/s2/polyline_alignment.go b/s2/polyline_alignment.go index a1d66741..52179f9e 100644 --- a/s2/polyline_alignment.go +++ b/s2/polyline_alignment.go @@ -245,7 +245,7 @@ func (w *window) upsample(newRows, newCols int) *window { colScale := float64(newCols) / float64(w.cols) newStrides := make([]columnStride, newRows) var fromStride columnStride - for row := 0; row < newRows; row++ { + for row := range newRows { fromStride = w.strides[int((float64(row)+0.5)/rowScale)] newStrides[row] = columnStride{ start: int(colScale*float64(fromStride.start) + 0.5), @@ -341,7 +341,7 @@ type costTable [][]float64 func newCostTable(rows, cols int) costTable { c := make([][]float64, rows) - for i := 0; i < rows; i++ { + for i := range rows { c[i] = make([]float64, cols) } return c @@ -386,12 +386,12 @@ func ExactVertexAlignmentCost(a, b *Polyline) float64 { aN := len(*a) bN := len(*b) cost := make([]float64, bN) - for i := 0; i < bN; i++ { + for i := range bN { cost[i] = math.MaxFloat64 } leftDiagMinCost := 0.0 - for row := 0; row < aN; row++ { - for col := 0; col < bN; col++ { + for row := range aN { + for col := range bN { upCost := cost[col] cost[col] = math.Min(leftDiagMinCost, upCost) + (*a)[row].Sub((*b)[col].Vector).Norm() @@ -409,7 +409,7 @@ func ExactVertexAlignment(a, b *Polyline) *vertexAlignment { aN := len(*a) bN := len(*b) strides := make([]columnStride, aN) - for i := 0; i < aN; i++ { + for i := range aN { strides[i] = columnStride{start: 0, end: bN} } w := windowFromStrides(strides) @@ -447,7 +447,7 @@ func dynamicTimewarp(a, b *Polyline, w *window) *vertexAlignment { var curr columnStride prev := allColumnStride() - for row := 0; row < rows; row++ { + for row := range rows { curr = w.columnStride(row) for col := curr.start; col < curr.end; col++ { // The total cost up to (row,col) is the minimum of the cost up, down, diff --git a/s2/polyline_alignment_test.go b/s2/polyline_alignment_test.go index b83f30e4..ddbaee7a 100644 --- a/s2/polyline_alignment_test.go +++ b/s2/polyline_alignment_test.go @@ -326,9 +326,9 @@ func distanceMatrix(a, b *Polyline) costTable { aN := len(*a) bN := len(*b) table := costTable(make([][]float64, aN)) - for i := 0; i < aN; i++ { + for i := range aN { table[i] = make([]float64, bN) - for j := 0; j < bN; j++ { + for j := range bN { table[i][j] = (*a)[i].Sub((*b)[j].Vector).Norm() } } diff --git a/s2/polyline_measures_test.go b/s2/polyline_measures_test.go index 08d57e50..497dcc62 100644 --- a/s2/polyline_measures_test.go +++ b/s2/polyline_measures_test.go @@ -24,7 +24,7 @@ func TestPolylineMeasuresGreatCircles(t *testing.T) { // Then make sure that the length and centroid are correct. Note that // because of the way the centroid is computed, it does not matter how // we split the great circle into segments. - for iter := 0; iter < 100; iter++ { + for range 100 { // Choose a coordinate frame for the great circle. f := randomFrame() x := f.row(0) diff --git a/s2/polyline_test.go b/s2/polyline_test.go index f661d867..2435c200 100644 --- a/s2/polyline_test.go +++ b/s2/polyline_test.go @@ -108,7 +108,7 @@ func TestPolylineLengthAndCentroid(t *testing.T) { // because of the way the centroid is computed, it does not matter how // we split the great circle into segments. - for i := 0; i < 100; i++ { + for range 100 { // Choose a coordinate frame for the great circle. f := randomFrame() @@ -141,7 +141,7 @@ func TestPolylineIntersectsCell(t *testing.T) { Point{r3.Vector{X: 1, Y: -0.8, Z: 1.1}.Normalize()}, } - for face := 0; face < 6; face++ { + for face := range 6 { cell := CellFromCellID(CellIDFromFace(face)) if got, want := pline.IntersectsCell(cell), face&1 == 0; got != want { t.Errorf("%v.IntersectsCell(%v) = %v, want %v", pline, cell, got, want) diff --git a/s2/predicates_test.go b/s2/predicates_test.go index eb96eedb..31212427 100644 --- a/s2/predicates_test.go +++ b/s2/predicates_test.go @@ -306,7 +306,7 @@ func TestPredicatesStableSignFailureRate(t *testing.T) { // by counting up the times it returns Indeterminate. failureCount := 0 m := math.Tan(spacing / earthRadiusKm) - for iter := 0; iter < iters; iter++ { + for range iters { f := randomFrame() a := f.col(0) x := f.col(1) @@ -919,7 +919,7 @@ func TestPredicatesCompareDistancesConsistency(t *testing.T) { t.Errorf("CompareDistances with 2 equidistant points didn't use symbolic compare, got %q want %q", got, want) } - for iter := 0; iter < iters; iter++ { + for range iters { x := choosePointNearPlaneOrAxes() dir := choosePointNearPlaneOrAxes() r := s1.Angle(math.Pi / 2 * math.Pow(1e-30, randomFloat64())) @@ -960,7 +960,7 @@ func TestPredicatesCompareDistanceConsistency(t *testing.T) { // comments in the CompareDistances consistency test. const iters = 1000 - for iter := 0; iter < iters; iter++ { + for range iters { x := choosePointNearPlaneOrAxes() dir := choosePointNearPlaneOrAxes() r := s1.Angle(math.Pi / 2 * math.Pow(1e-30, randomFloat64())) diff --git a/s2/rect_bounder_test.go b/s2/rect_bounder_test.go index 593060ae..b672552d 100644 --- a/s2/rect_bounder_test.go +++ b/s2/rect_bounder_test.go @@ -112,7 +112,7 @@ func TestRectBounderMaxLatitudeRandom(t *testing.T) { // 3 * dblEpsilon (the expected maximum error). We concentrate on maximum // latitudes near the equator and north pole since these are the extremes. - for i := 0; i < 100; i++ { + for range 100 { // Construct a right-handed coordinate frame (U,V,W) such that U points // slightly above the equator, V points at the equator, and W is slightly // offset from the north pole. diff --git a/s2/rect_test.go b/s2/rect_test.go index bba2f5d3..66c105cf 100644 --- a/s2/rect_test.go +++ b/s2/rect_test.go @@ -183,7 +183,7 @@ func TestRectVertex(t *testing.T) { } } func TestRectVertexCCWOrder(t *testing.T) { - for i := 0; i < 4; i++ { + for i := range 4 { lat := math.Pi / 4 * float64(i-2) lng := math.Pi/2*float64(i-2) + 0.2 r := Rect{ @@ -194,7 +194,7 @@ func TestRectVertexCCWOrder(t *testing.T) { }, } - for k := 0; k < 4; k++ { + for k := range 4 { if !Sign(PointFromLatLng(r.Vertex((k-1)&3)), PointFromLatLng(r.Vertex(k)), PointFromLatLng(r.Vertex((k+1)&3))) { t.Errorf("%v.Vertex(%v), vertices were not in CCW order", r, k) } @@ -932,7 +932,7 @@ func TestDistanceRectFromLatLng(t *testing.T) { func TestDistanceRectFromLatLngRandomPairs(t *testing.T) { latlng := func() LatLng { return LatLngFromPoint(randomPoint()) } - for i := 0; i < 10000; i++ { + for range 10000 { r := RectFromLatLng(latlng()).AddPoint(latlng()) ll := latlng() got := r.DistanceToLatLng(ll) @@ -986,7 +986,7 @@ func verifyDirectedHausdorffDistance(t *testing.T, a, b Rect) { func TestRectDirectedHausdorffDistanceRandomPairs(t *testing.T) { // Test random pairs. rnd := func() LatLng { return LatLngFromPoint(randomPoint()) } - for i := 0; i < 1000; i++ { + for range 1000 { a := RectFromLatLng(rnd()).AddPoint(rnd()) b := RectFromLatLng(rnd()).AddPoint(rnd()) // a and b are *minimum* bounding rectangles of two random points, in @@ -1166,7 +1166,7 @@ func testRectCentroidSplitting(t *testing.T, r Rect, leftSplits int) { func TestRectCentroidFullRange(t *testing.T) { // Rectangles that cover the full longitude range. - for i := 0; i < 100; i++ { + for range 100 { lat1 := randomUniformFloat64(-math.Pi/2, math.Pi/2) lat2 := randomUniformFloat64(-math.Pi/2, math.Pi/2) r := Rect{r1.Interval{Lo: lat1, Hi: lat2}, s1.FullInterval()} @@ -1180,7 +1180,7 @@ func TestRectCentroidFullRange(t *testing.T) { } // Rectangles that cover the full latitude range. - for i := 0; i < 100; i++ { + for range 100 { lat1 := randomUniformFloat64(-math.Pi, math.Pi) lat2 := randomUniformFloat64(-math.Pi, math.Pi) r := Rect{r1.Interval{Lo: -math.Pi / 2, Hi: math.Pi / 2}, s1.Interval{Lo: lat1, Hi: lat2}} diff --git a/s2/regioncoverer_test.go b/s2/regioncoverer_test.go index f6b2e08b..a7c86e56 100644 --- a/s2/regioncoverer_test.go +++ b/s2/regioncoverer_test.go @@ -26,7 +26,7 @@ func TestCovererRandomCells(t *testing.T) { rc := &RegionCoverer{MinLevel: 0, MaxLevel: 30, LevelMod: 1, MaxCells: 1} // Test random cell ids at all levels. - for i := 0; i < 10000; i++ { + for i := range 10000 { id := randomCellID() covering := rc.Covering(Region(CellFromCellID(id))) if len(covering) != 1 { @@ -85,7 +85,7 @@ func checkCovering(t *testing.T, rc *RegionCoverer, r Region, covering CellUnion // do not intersect the given region. ("id" is only used internally.) func checkCoveringTight(t *testing.T, r Region, cover CellUnion, checkTight bool, id CellID) { if !id.IsValid() { - for f := 0; f < 6; f++ { + for f := range 6 { checkCoveringTight(t, r, cover, checkTight, CellIDFromFace(f)) } return @@ -115,7 +115,7 @@ func checkCoveringTight(t *testing.T, r Region, cover CellUnion, checkTight bool func TestCovererRandomCaps(t *testing.T) { rc := &RegionCoverer{MinLevel: 0, MaxLevel: 30, LevelMod: 1, MaxCells: 1} - for i := 0; i < 1000; i++ { + for i := range 1000 { rc.MinLevel = int(rand.Int31n(MaxLevel + 1)) rc.MaxLevel = int(rand.Int31n(MaxLevel + 1)) for rc.MinLevel > rc.MaxLevel { @@ -174,7 +174,7 @@ func TestRegionCovererInteriorCovering(t *testing.T) { if len(interior) != 3 { t.Fatalf("len(coverer.InteriorCovering(%v)) = %v, want 3", diff, len(interior)) } - for i := 0; i < 3; i++ { + for i := range 3 { if got, want := interior[i].Level(), level+1; got != want { t.Errorf("interior[%d].Level() = %v, want %v", i, got, want) } @@ -183,7 +183,7 @@ func TestRegionCovererInteriorCovering(t *testing.T) { func TestRegionCovererSimpleRegionCovering(t *testing.T) { const MaxLevel = MaxLevel - for i := 0; i < 100; i++ { + for range 100 { level := randomUniformInt(MaxLevel + 1) maxArea := math.Min(4*math.Pi, 1000.0*AvgAreaMetric.Value(level)) c := randomCap(0.1*AvgAreaMetric.Value(MaxLevel), maxArea) @@ -309,7 +309,7 @@ func BenchmarkRegionCovererCoveringCap(b *testing.B) { }, func(n int) []Region { regions := make([]Region, numCoveringBMRegions) - for i := 0; i < numCoveringBMRegions; i++ { + for i := range numCoveringBMRegions { regions[i] = randomCap(0.1*AvgAreaMetric.Value(MaxLevel), 4*math.Pi) } return regions @@ -322,7 +322,7 @@ func BenchmarkRegionCovererCoveringCell(b *testing.B) { }, func(n int) []Region { regions := make([]Region, numCoveringBMRegions) - for i := 0; i < numCoveringBMRegions; i++ { + for i := range numCoveringBMRegions { regions[i] = CellFromCellID(randomCellIDForLevel(MaxLevel - randomUniformInt(n))) } return regions @@ -336,7 +336,7 @@ func BenchmarkRegionCovererCoveringLoop(b *testing.B) { func(n int) []Region { size := int(math.Pow(2.0, float64(n))) regions := make([]Region, numCoveringBMRegions) - for i := 0; i < numCoveringBMRegions; i++ { + for i := range numCoveringBMRegions { regions[i] = RegularLoop(randomPoint(), kmToAngle(10.0), size) } return regions @@ -350,7 +350,7 @@ func BenchmarkRegionCovererCoveringCellUnion(b *testing.B) { func(n int) []Region { size := int(math.Pow(2.0, float64(n))) regions := make([]Region, numCoveringBMRegions) - for i := 0; i < numCoveringBMRegions; i++ { + for i := range numCoveringBMRegions { cu := randomCellUnion(size) regions[i] = &cu } diff --git a/s2/s2_test.go b/s2/s2_test.go index b554f2f3..6445f541 100644 --- a/s2/s2_test.go +++ b/s2/s2_test.go @@ -190,7 +190,7 @@ func randomCellID(r ...*rand.Rand) CellID { // randomCellUnion returns a CellUnion of the given size of randomly selected cells. func randomCellUnion(n int, r ...*rand.Rand) CellUnion { var cu CellUnion - for i := 0; i < n; i++ { + for range n { cu = append(cu, randomCellID(r...)) } return cu @@ -200,7 +200,7 @@ func randomCellUnion(n int, r ...*rand.Rand) CellUnion { // number of concentric loops and vertices per loop. func concentricLoopsPolygon(center Point, numLoops, verticesPerLoop int) *Polygon { var loops []*Loop - for li := 0; li < numLoops; li++ { + for li := range numLoops { radius := s1.Angle(0.005 * float64(li+1) / float64(numLoops)) loops = append(loops, RegularLoop(center, radius, verticesPerLoop)) } diff --git a/s2/s2_test_test.go b/s2/s2_test_test.go index 22bcdcab..4598fd98 100644 --- a/s2/s2_test_test.go +++ b/s2/s2_test_test.go @@ -219,7 +219,7 @@ func TestChordAngleMaxPointError(t *testing.T) { // Check that the error bound returned by s1.MaxPointError() is // large enough. const iters = 100000 - for iter := 0; iter < iters; iter++ { + for range iters { x := randomPoint() y := randomPoint() if oneIn(10) { diff --git a/s2/shapeindex.go b/s2/shapeindex.go index 0224042f..60f7257d 100644 --- a/s2/shapeindex.go +++ b/s2/shapeindex.go @@ -772,7 +772,7 @@ func (s *ShapeIndex) Remove(shape Shape) { edges: make([]Edge, numEdges), } - for e := 0; e < numEdges; e++ { + for e := range numEdges { removed.edges[e] = shape.Edge(e) } @@ -850,7 +850,7 @@ func (s *ShapeIndex) applyUpdatesInternal() { s.addShapeInternal(id, allEdges, t) } - for face := 0; face < 6; face++ { + for face := range 6 { s.updateFaceEdges(face, allEdges[face], t) } @@ -879,7 +879,7 @@ func (s *ShapeIndex) addShapeInternal(shapeID int32, allEdges [][]faceEdge, t *t } numEdges := shape.NumEdges() - for e := 0; e < numEdges; e++ { + for e := range numEdges { edge := shape.Edge(e) faceEdge.edgeID = e @@ -909,7 +909,7 @@ func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) { } // Otherwise, we simply clip the edge to all six faces. - for face := 0; face < 6; face++ { + for face := range 6 { if aClip, bClip, intersects := ClipToPaddedFace(fe.edge.V0, fe.edge.V1, face, cellPadding); intersects { fe.a = aClip fe.b = bClip @@ -933,7 +933,7 @@ func (s *ShapeIndex) updateFaceEdges(face int, faceEdges []faceEdge, t *tracker) // pointers in order to propagate an edge to the correct child. clippedEdges := make([]*clippedEdge, numEdges) bound := r2.EmptyRect() - for e := 0; e < numEdges; e++ { + for e := range numEdges { clipped := &clippedEdge{ faceEdge: &faceEdges[e], } @@ -1125,7 +1125,7 @@ func (s *ShapeIndex) updateEdges(pcell *PaddedCell, edges []*clippedEdge, t *tra // Now recursively update the edges in each child. We call the children in // increasing order of CellID so that when the index is first constructed, // all insertions into cellMap are at the end (which is much faster). - for pos := 0; pos < 4; pos++ { + for pos := range 4 { i, j := pcell.ChildIJ(pos) if len(childEdges[i][j]) > 0 || len(t.shapeIDs) > 0 { s.updateEdges(PaddedCellFromParentIJ(pcell, i, j), childEdges[i][j], @@ -1208,7 +1208,7 @@ func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *track // as we go along. Both sets of shape ids are already sorted. eNext := 0 cNextIdx := 0 - for i := 0; i < numShapes; i++ { + for i := range numShapes { var clipped *clippedShape // advance to next value base + i eshapeID := int32(s.Len()) @@ -1437,7 +1437,7 @@ func (s *ShapeIndex) absorbIndexCell(p *PaddedCell, iter *ShapeIndexIterator, ed trackerMoved = true } } - for i := 0; i < numClipped; i++ { + for i := range numClipped { edgeID := clipped.edges[i] edge.edgeID = edgeID edge.edge = shape.Edge(edgeID) diff --git a/s2/shapeindex_test.go b/s2/shapeindex_test.go index 1f4f2691..4dcf5d18 100644 --- a/s2/shapeindex_test.go +++ b/s2/shapeindex_test.go @@ -258,7 +258,7 @@ func testIteratorMethods(t *testing.T, index *ShapeIndex) { skipped := CellUnionFromRange(minCellID, ci.RangeMin()) it2 := NewShapeIndexIterator(index, IteratorEnd) - for i := 0; i < len(skipped); i++ { + for i := range skipped { if it2.LocatePoint(skipped[i].Point()) { t.Errorf("iterator should not have been able to find the cell %v which was not in the index", skipped[i].Point()) } @@ -335,7 +335,7 @@ func testIteratorMethods(t *testing.T, index *ShapeIndex) { } if !ci.IsLeaf() { - for i := 0; i < 4; i++ { + for i := range 4 { it2.Begin() if got, want := it2.LocateCellID(ci.Children()[i]), Indexed; got != want { t.Errorf("it2.LocateCellID(%v.Children[%d]) = %v, want %v", ci, i, got, want) @@ -379,7 +379,7 @@ func TestShapeIndexManyIdenticalEdges(t *testing.T) { b := PointFromCoords(-0.99, -0.99, 1) index := NewShapeIndex() - for i := int32(0); i < numEdges; i++ { + for i := range int32(numEdges) { if got := index.Add(edgeVectorShapeFromPoints(a, b)); got != i { t.Errorf("element %d id = %v, want %v", i, got, i) } @@ -432,7 +432,7 @@ func TestShapeIndexManyTinyEdges(t *testing.T) { a := cellIDFromPoint(PointFromCoords(1, 0, 0)).Point() b := Point{a.Add(r3.Vector{X: 0, Y: 1e-12, Z: 0}).Normalize()} shape := &edgeVectorShape{} - for i := 0; i < 100; i++ { + for range 100 { shape.Add(a, b) } @@ -553,9 +553,9 @@ func TestShapeIndexNumEdgesUpTo(t *testing.T) { func BenchmarkShapeIndexIteratorLocatePoint(b *testing.B) { index := NewShapeIndex() - for i := 0; i < 100; i++ { + for range 100 { var points []Point - for j := 0; j < 100; j++ { + for range 100 { points = append(points, randomPoint()) } polyline := Polyline(points) diff --git a/s2/shapeutil.go b/s2/shapeutil.go index 27936dfd..c5e83b31 100644 --- a/s2/shapeutil.go +++ b/s2/shapeutil.go @@ -136,7 +136,7 @@ func referencePointForShape(shape Shape) ReferencePoint { n := shape.NumEdges() var edges = make([]Edge, n) var revEdges = make([]Edge, n) - for i := 0; i < n; i++ { + for i := range n { edge := shape.Edge(i) edges[i] = edge revEdges[i] = Edge{V0: edge.V1, V1: edge.V0} @@ -145,7 +145,7 @@ func referencePointForShape(shape Shape) ReferencePoint { sortEdges(edges) sortEdges(revEdges) - for i := 0; i < n; i++ { + for i := range n { if edges[i].Cmp(revEdges[i]) == -1 { // edges[i] is unmatched if ref, ok := referencePointAtVertex(shape, edges[i].V0); ok { return ref @@ -183,7 +183,7 @@ func referencePointAtVertex(shape Shape, vTest Point) (ReferencePoint, bool) { containsQuery := NewContainsVertexQuery(vTest) n := shape.NumEdges() - for e := 0; e < n; e++ { + for e := range n { edge := shape.Edge(e) if edge.V0 == vTest { containsQuery.AddEdge(edge.V1, 1) diff --git a/s2/stuv_test.go b/s2/stuv_test.go index cf14c8c9..152413d7 100644 --- a/s2/stuv_test.go +++ b/s2/stuv_test.go @@ -32,8 +32,8 @@ func invertBits(ij int) int { } func TestSTUVTraversalOrder(t *testing.T) { - for r := 0; r < 4; r++ { - for i := 0; i < 4; i++ { + for r := range 4 { + for i := range 4 { // Check consistency with respect to swapping axes. if got, want := ijToPos[r][i], ijToPos[r^swapMask][swapAxes(i)]; got != want { t.Errorf("(ijToPos[%d][%d] = %d) != ijToPos[%d^swapMask][swapAxes(%d)] = %d", @@ -95,7 +95,7 @@ func TestSTUVConversions(t *testing.T) { func TestUVNorms(t *testing.T) { step := 1 / 1024.0 - for face := 0; face < 6; face++ { + for face := range 6 { for x := -1.0; x <= 1; x += step { if !float64Eq(float64(faceUVToXYZ(face, x, -1).Cross(faceUVToXYZ(face, x, 1)).Angle(uNorm(face, x))), 0.0) { t.Errorf("UNorm not orthogonal to the face(%d)", face) @@ -110,7 +110,7 @@ func TestUVNorms(t *testing.T) { func TestFaceUVToXYZ(t *testing.T) { // Check that each face appears exactly once. var sum r3.Vector - for face := 0; face < 6; face++ { + for face := range 6 { center := faceUVToXYZ(face, 0, 0) if !center.ApproxEqual(unitNorm(face).Vector) { t.Errorf("faceUVToXYZ(%d, 0, 0) != unitNorm(%d), should be equal", face, face) @@ -200,7 +200,7 @@ func TestFaceXYZtoUVW(t *testing.T) { negZ = Point{r3.Vector{X: 0, Y: 0, Z: -1}} ) - for face := 0; face < 6; face++ { + for face := range 6 { if got := faceXYZtoUVW(face, origin); got != origin { t.Errorf("faceXYZtoUVW(%d, %v) = %v, want %v", face, origin, got, origin) } @@ -232,7 +232,7 @@ func TestFaceXYZtoUVW(t *testing.T) { } func TestUVWAxis(t *testing.T) { - for face := 0; face < 6; face++ { + for face := range 6 { // Check that the axes are consistent with faceUVtoXYZ. if faceUVToXYZ(face, 1, 0).Sub(faceUVToXYZ(face, 0, 0)) != uAxis(face).Vector { t.Errorf("face 1,0 - face 0,0 should equal uAxis") @@ -264,14 +264,14 @@ func TestUVWAxis(t *testing.T) { func TestSiTiSTRoundtrip(t *testing.T) { // test int -> float -> int direction. - for i := 0; i < 1000; i++ { + for range 1000 { si := uint32(randomUniformInt(maxSiTi)) if got := stToSiTi(siTiToST(si)); got != si { t.Errorf("stToSiTi(siTiToST(%v)) = %v, want %v", si, got, si) } } // test float -> int -> float direction. - for i := 0; i < 1000; i++ { + for range 1000 { st := randomUniformFloat64(0, 1.0) // this uses near not exact because there is some loss in precision // when scaling down to the nearest 1/MaxLevel and back. @@ -283,8 +283,8 @@ func TestSiTiSTRoundtrip(t *testing.T) { func TestUVWFace(t *testing.T) { // Check that uvwFace is consistent with uvwAxis. - for f := 0; f < 6; f++ { - for axis := 0; axis < 3; axis++ { + for f := range 6 { + for axis := range 3 { if got, want := face(uvwAxis(f, axis).Mul(-1)), uvwFace(f, axis, 0); got != want { t.Errorf("face(%v) in positive direction = %v, want %v", uvwAxis(f, axis).Mul(-1), got, want) } @@ -296,8 +296,8 @@ func TestUVWFace(t *testing.T) { } func TestXYZToFaceSiTi(t *testing.T) { - for level := 0; level < MaxLevel; level++ { - for i := 0; i < 1000; i++ { + for level := range MaxLevel { + for range 1000 { ci := randomCellIDForLevel(level) f, si, ti, gotLevel := xyzToFaceSiTi(ci.Point()) if gotLevel != level { @@ -369,8 +369,8 @@ func TestXYZToFaceSiTi(t *testing.T) { } func TestXYZFaceSiTiRoundtrip(t *testing.T) { - for level := 0; level < MaxLevel; level++ { - for i := 0; i < 1000; i++ { + for level := range MaxLevel { + for range 1000 { ci := randomCellIDForLevel(level) f, si, ti, _ := xyzToFaceSiTi(ci.Point()) op := faceSiTiToXYZ(f, si, ti)