Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion s1/angle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }{
Expand Down
4 changes: 2 additions & 2 deletions s1/chordangle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion s2/builder_snapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions s2/cap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions s2/cap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions s2/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion s2/cell_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions s2/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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++
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)})
Expand Down
Loading