diff --git a/r3/precisevector.go b/r3/precisevector.go index e7940f5..b13393d 100644 --- a/r3/precisevector.go +++ b/r3/precisevector.go @@ -64,7 +64,7 @@ func precMul(a, b *big.Float) *big.Float { // PreciseVector represents a point in ℝ³ using high-precision values. // Note that this is NOT a complete implementation because there are some // operations that Vector supports that are not feasible with arbitrary precision -// math. (e.g., methods that need divison like Normalize, or methods needing a +// math. (e.g., methods that need division like Normalize, or methods needing a // square root operation such as Norm) type PreciseVector struct { X, Y, Z *big.Float diff --git a/s2/cellid.go b/s2/cellid.go index e2806bc..769b9b3 100644 --- a/s2/cellid.go +++ b/s2/cellid.go @@ -576,8 +576,8 @@ func cellIDFromFaceIJ(f, i, j int) CellID { // Hilbert curve orientation respectively. for k := 7; k >= 0; k-- { mask := (1 << lookupBits) - 1 - bits += int((i>>uint(k*lookupBits))&mask) << (lookupBits + 2) - bits += int((j>>uint(k*lookupBits))&mask) << 2 + bits += ((i >> uint(k*lookupBits)) & mask) << (lookupBits + 2) + bits += ((j >> uint(k*lookupBits)) & mask) << 2 bits = lookupPos[bits] n |= uint64(bits>>2) << (uint(k) * 2 * lookupBits) bits &= (swapMask | invertMask) diff --git a/s2/cellunion.go b/s2/cellunion.go index 2d898bd..0654de9 100644 --- a/s2/cellunion.go +++ b/s2/cellunion.go @@ -379,7 +379,7 @@ func areSiblings(a, b, c, d CellID) bool { // mask that blocks out the two bits that encode the child position of // "id" with respect to its parent, then check that the other three // children all agree with "mask". - mask := uint64(d.lsb() << 1) + mask := d.lsb() << 1 mask = ^(mask + (mask << 1)) idMasked := (uint64(d) & mask) return ((uint64(a)&mask) == idMasked && diff --git a/s2/cellunion_test.go b/s2/cellunion_test.go index ea48820..2bc5b0b 100644 --- a/s2/cellunion_test.go +++ b/s2/cellunion_test.go @@ -881,7 +881,7 @@ func cellUnionDistanceFromAxis(cu CellUnion, axis Point) float64 { // // TODO: Improve edgeutil's DistanceFromSegment accuracy near Pi. if a.Angle(axis.Vector) > math.Pi/2 || b.Angle(axis.Vector) > math.Pi/2 { - dist = math.Pi - float64(DistanceFromSegment(Point{axis.Mul(-1)}, a, b).Radians()) + dist = math.Pi - DistanceFromSegment(Point{axis.Mul(-1)}, a, b).Radians() } else { dist = float64(a.Angle(axis.Vector)) } diff --git a/s2/crossing_edge_query.go b/s2/crossing_edge_query.go index 50e364c..51852da 100644 --- a/s2/crossing_edge_query.go +++ b/s2/crossing_edge_query.go @@ -152,14 +152,13 @@ func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { for _, cell := range c.cells { if cell == nil { + continue } clipped := cell.findByShapeID(shapeID) if clipped == nil { continue } - for _, j := range clipped.edges { - edges = append(edges, j) - } + edges = append(edges, clipped.edges...) } if len(c.cells) > 1 { @@ -190,7 +189,7 @@ func uniqueInts(in []int) []int { // CAVEAT: This method may return shapes that have an empty set of candidate edges. // However the return value is non-empty only if at least one shape has a candidate edge. func (c *CrossingEdgeQuery) candidatesEdgeMap(a, b Point) EdgeMap { - edgeMap := make(EdgeMap, 0) + edgeMap := make(EdgeMap) // If there are only a few edges then it's faster to use brute force. We // only bother with this optimization when there is a single shape. @@ -232,7 +231,7 @@ func (c *CrossingEdgeQuery) candidatesEdgeMap(a, b Point) EdgeMap { } // getCells returns the set of ShapeIndexCells that might contain edges intersecting -// the edge AB in the given cell root. This method is used primarly by loop and shapeutil. +// the edge AB in the given cell root. This method is used primarily by loop and shapeutil. func (c *CrossingEdgeQuery) getCells(a, b Point, root *PaddedCell) []*ShapeIndexCell { aUV, bUV, ok := ClipToFace(a, b, root.id.Face()) if ok { diff --git a/s2/interleave_test.go b/s2/interleave_test.go index 8074916..13f1096 100644 --- a/s2/interleave_test.go +++ b/s2/interleave_test.go @@ -19,7 +19,7 @@ import "testing" func TestInterleaveUint32(t *testing.T) { x, y := uint32(13356), uint32(1073728367) gotX, gotY := deinterleaveUint32(interleaveUint32(x, y)) - if gotX != x || gotY != gotY { + if gotX != x || gotY != y { t.Errorf("deinterleave after interleave = %d, %d; want %d, %d", gotX, gotY, x, y) } } diff --git a/s2/loop.go b/s2/loop.go index ae2ad4f..882d858 100644 --- a/s2/loop.go +++ b/s2/loop.go @@ -878,7 +878,7 @@ func (l *Loop) Invert() { } // originInside must be set correctly before building the ShapeIndex. - l.originInside = l.originInside != true + l.originInside = !l.originInside if l.bound.Lat.Lo > -math.Pi/2 && l.bound.Lat.Hi < math.Pi/2 { // The complement of this loop contains both poles. l.bound = FullRect() @@ -1094,7 +1094,7 @@ func (l *Loop) surfaceIntegralPoint(f func(a, b, c Point) Point) Point { // the loop. The return value is between 0 and 4*pi. (Note that the return // value is not affected by whether this loop is a "hole" or a "shell".) func (l *Loop) Area() float64 { - // It is suprisingly difficult to compute the area of a loop robustly. The + // It is surprisingly difficult to compute the area of a loop robustly. The // main issues are (1) whether degenerate loops are considered to be CCW or // not (i.e., whether their area is close to 0 or 4*pi), and (2) computing // the areas of small loops with good relative accuracy. diff --git a/s2/loop_test.go b/s2/loop_test.go index 240e875..8683e7f 100644 --- a/s2/loop_test.go +++ b/s2/loop_test.go @@ -621,7 +621,7 @@ func TestLoopFromCell(t *testing.T) { // Demonstrates the reason for this test; the cell bounds are more // conservative than the resulting loop bounds. if loopFromCell.RectBound().Contains(cell.RectBound()) { - t.Errorf("loopFromCell's RectBound countains the original cells RectBound, but should not") + t.Errorf("loopFromCell's RectBound contains the original cells RectBound, but should not") } } diff --git a/s2/paddedcell.go b/s2/paddedcell.go index 2dc3964..ac304a6 100644 --- a/s2/paddedcell.go +++ b/s2/paddedcell.go @@ -243,7 +243,7 @@ func (p *PaddedCell) ShrinkToFit(rect r2.Rect) CellID { // if both pairs of endpoints are equal we choose maxLevel; if they differ // only at bit 0, we choose (maxLevel - 1), and so on. levelMSB := uint64(((iXor | jXor) << 1) + 1) - level := maxLevel - int(findMSBSetNonZero64(levelMSB)) + level := maxLevel - findMSBSetNonZero64(levelMSB) if level <= p.level { return p.id } diff --git a/s2/predicates.go b/s2/predicates.go index b19d323..9fc5e17 100644 --- a/s2/predicates.go +++ b/s2/predicates.go @@ -79,8 +79,8 @@ type Direction int // These are the three options for the direction of a set of points. const ( Clockwise Direction = -1 - Indeterminate = 0 - CounterClockwise = 1 + Indeterminate Direction = 0 + CounterClockwise Direction = 1 ) // newBigFloat constructs a new big.Float with maximum precision. @@ -228,7 +228,7 @@ func expensiveSign(a, b, c Point) Direction { // the three points are truly collinear (e.g., three points on the equator). detSign := stableSign(a, b, c) if detSign != Indeterminate { - return Direction(detSign) + return detSign } // Otherwise fall back to exact arithmetic and symbolic permutations. @@ -240,7 +240,7 @@ func expensiveSign(a, b, c Point) Direction { func exactSign(a, b, c Point, perturb bool) Direction { // Sort the three points in lexicographic order, keeping track of the sign // of the permutation. (Each exchange inverts the sign of the determinant.) - permSign := Direction(CounterClockwise) + permSign := CounterClockwise pa := &a pb := &b pc := &c @@ -275,7 +275,7 @@ func exactSign(a, b, c Point, perturb bool) Direction { // sign of the determinant. detSign = symbolicallyPerturbedSign(xa, xb, xc, xbCrossXc) } - return permSign * Direction(detSign) + return permSign * detSign } // symbolicallyPerturbedSign reports the sign of the determinant of three points diff --git a/s2/rect.go b/s2/rect.go index 6c5927b..73537a5 100644 --- a/s2/rect.go +++ b/s2/rect.go @@ -220,7 +220,7 @@ func (r Rect) Intersects(other Rect) bool { return r.Lat.Intersects(other.Lat) && r.Lng.Intersects(other.Lng) } -// CapBound returns a cap that countains Rect. +// CapBound returns a cap that contains Rect. func (r Rect) CapBound() Cap { // We consider two possible bounding caps, one whose axis passes // through the center of the lat-long rectangle and one whose axis diff --git a/s2/regioncoverer.go b/s2/regioncoverer.go index 9a5efa8..476e585 100644 --- a/s2/regioncoverer.go +++ b/s2/regioncoverer.go @@ -94,7 +94,7 @@ type candidate struct { terminal bool // Cell should not be expanded further. numChildren int // Number of children that intersect the region. children []*candidate // Actual size may be 0, 4, 16, or 64 elements. - priority int // Priority of the candiate. + priority int // Priority of the candidate. } type priorityQueue []*candidate diff --git a/s2/regioncoverer_test.go b/s2/regioncoverer_test.go index 3b7bec2..26ceb2e 100644 --- a/s2/regioncoverer_test.go +++ b/s2/regioncoverer_test.go @@ -123,7 +123,7 @@ func TestCovererRandomCaps(t *testing.T) { rc.MaxLevel = int(rand.Int31n(maxLevel + 1)) } rc.LevelMod = int(1 + rand.Int31n(3)) - rc.MaxCells = int(skewedInt(10)) + rc.MaxCells = skewedInt(10) maxArea := math.Min(4*math.Pi, float64(3*rc.MaxCells+1)*AvgAreaMetric.Value(rc.MinLevel)) r := Region(randomCap(0.1*AvgAreaMetric.Value(maxLevel), maxArea)) diff --git a/s2/s2_test_test.go b/s2/s2_test_test.go index 4399292..716ba34 100644 --- a/s2/s2_test_test.go +++ b/s2/s2_test_test.go @@ -168,7 +168,7 @@ func TestTestingFractal(t *testing.T) { if got, want := loop.NumVertices(), numVerticesAtLevel(test.maxLevel); got > want { t.Errorf("%s. number of vertices = %d, should be less than %d", test.label, got, want) } - if got, want := float64(expectedNumVertices), float64(loop.NumVertices()); !float64Near(got, want, relativeError*(expectedNumVertices-float64(minVertices))) { + if got, want := expectedNumVertices, float64(loop.NumVertices()); !float64Near(got, want, relativeError*(expectedNumVertices-float64(minVertices))) { t.Errorf("%s. expected number of vertices %v should be close to %v, difference: %v", test.label, got, want, (got - want)) } diff --git a/s2/shapeindex.go b/s2/shapeindex.go index 5374bbf..6f66c9f 100644 --- a/s2/shapeindex.go +++ b/s2/shapeindex.go @@ -894,7 +894,6 @@ func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) { allEdges[face] = append(allEdges[face], fe) } } - return } // updateFaceEdges adds or removes the various edges from the index. @@ -1188,7 +1187,7 @@ func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *track var clipped *clippedShape // advance to next value base + i eshapeID := int32(s.Len()) - cshapeID := int32(eshapeID) // Sentinels + cshapeID := eshapeID // Sentinels if eNext != len(edges) { eshapeID = edges[eNext].faceEdge.shapeID @@ -1495,7 +1494,7 @@ func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int { } // Count any remaining containing shapes. - count += int(len(shapeIDs)) - int(shapeIDidx) + count += len(shapeIDs) - shapeIDidx return count } diff --git a/s2/stuv_test.go b/s2/stuv_test.go index 641bc52..c889f77 100644 --- a/s2/stuv_test.go +++ b/s2/stuv_test.go @@ -269,11 +269,11 @@ func TestXYZToFaceSiTi(t *testing.T) { // levels, or not at a valid level at all (for example, si == 0). faceRandom := randomUniformInt(numFaces) mask := -1 << uint32(maxLevel-level) - siRandom := uint32(randomUint32() & uint32(mask)) - tiRandom := uint32(randomUint32() & uint32(mask)) + siRandom := randomUint32() & uint32(mask) + tiRandom := randomUint32() & uint32(mask) for siRandom > maxSiTi || tiRandom > maxSiTi { - siRandom = uint32(randomUint32() & uint32(mask)) - tiRandom = uint32(randomUint32() & uint32(mask)) + siRandom = randomUint32() & uint32(mask) + tiRandom = randomUint32() & uint32(mask) } pRandom := faceSiTiToXYZ(faceRandom, siRandom, tiRandom)