Skip to content

Commit

Permalink
all: Fix a bunch of typos, unnecessary casts and little errors.
Browse files Browse the repository at this point in the history
Fixes #53.
  • Loading branch information
dsymonds committed Aug 12, 2019
1 parent 006f9f6 commit f41920e
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion r3/precisevector.go
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions s2/cellid.go
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion s2/cellunion.go
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion s2/cellunion_test.go
Expand Up @@ -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))
}
Expand Down
9 changes: 4 additions & 5 deletions s2/crossing_edge_query.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion s2/interleave_test.go
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions s2/loop.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion s2/loop_test.go
Expand Up @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion s2/paddedcell.go
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions s2/predicates.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion s2/rect.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion s2/regioncoverer.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion s2/regioncoverer_test.go
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion s2/s2_test_test.go
Expand Up @@ -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))
}

Expand Down
5 changes: 2 additions & 3 deletions s2/shapeindex.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions s2/stuv_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit f41920e

Please sign in to comment.