Skip to content

Commit 3b9843e

Browse files
committed
remove unused functions and fix static analysis warnings
1 parent 5538cee commit 3b9843e

4 files changed

Lines changed: 8 additions & 48 deletions

File tree

go/decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func Decode(code string) (CodeArea, error) {
9090
// Everything is ints so they all need to be cast to floats.
9191
lat := float64(normalLat)/pairPrecision + float64(extraLat)/finalLatPrecision
9292
lng := float64(normalLng)/pairPrecision + float64(extraLng)/finalLngPrecision
93-
// Round everthing off to 14 places.
93+
// Round everything off to 14 places.
9494
return CodeArea{
9595
LatLo: math.Round(lat*1e14) / 1e14,
9696
LngLo: math.Round(lng*1e14) / 1e14,

go/encode.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ var (
2727
ErrNotShort = errors.New("not short code")
2828
)
2929

30-
const (
31-
minTrimmableCodeLen = 6
32-
)
33-
3430
// Encode a location into an Open Location Code.
3531
//
3632
// Produces a code of the specified codeLen, or the default length if
@@ -106,8 +102,8 @@ func Encode(lat, lng float64, codeLen int) string {
106102
code[3], lngVal = pairIndexStep(lngVal)
107103
code[2], latVal = pairIndexStep(latVal)
108104

109-
code[1], lngVal = pairIndexStep(lngVal)
110-
code[0], latVal = pairIndexStep(latVal)
105+
code[1], _ = pairIndexStep(lngVal)
106+
code[0], _ = pairIndexStep(latVal)
111107

112108
// If we don't need to pad the code, return the requested section.
113109
if codeLen >= sepPos {
@@ -117,23 +113,6 @@ func Encode(lat, lng float64, codeLen int) string {
117113
return string(code[:codeLen]) + strings.Repeat(string(Padding), sepPos-codeLen) + string(Separator)
118114
}
119115

120-
// roundLatLngToInts rounds the passed latitude and longitude to integral values
121-
// representing a location within 1 centimetre of the passed coordinates.
122-
func roundLatLngToInts(lat, lng float64) (int64, int64) {
123-
// To round, we:
124-
// 1) Offset latitude and longitude so that all values are positive.
125-
// 2) Multiply by the final precision before conversion to integer to preserve precision.
126-
// 3) Multiply by desired rounding precision and add 1.
127-
// 4) Bit shift to undo the multiply used for rounding.
128-
129-
// Precision of rounding is equal to 2^roundPrecision.
130-
// A value of 20 corresponds to sub-centimetre precision.
131-
const roundPrecision = 20
132-
latVal := int64((lat+latMax)*finalLatPrecision*(1<<roundPrecision)+1) >> roundPrecision
133-
lngVal := int64((lng+lngMax)*finalLngPrecision*(1<<roundPrecision)+1) >> roundPrecision
134-
return latVal, lngVal
135-
}
136-
137116
// clipCodeLen returns the smallest valid code length greater than or equal to
138117
// the desired code length.
139118
func clipCodeLen(codeLen int) int {
@@ -167,14 +146,3 @@ func pairIndexStep(coordinate int64) (byte, int64) {
167146
latNdx := coordinate % int64(encBase)
168147
return Alphabet[latNdx], coordinate
169148
}
170-
171-
// computeLatPrec computes the precision value for a given code length.
172-
// Lengths <= 10 have the same precision for latitude and longitude,
173-
// but lengths > 10 have different precisions due to the grid method
174-
// having fewer columns than rows.
175-
func computeLatPrec(codeLen int) float64 {
176-
if codeLen <= pairCodeLen {
177-
return math.Pow(float64(encBase), math.Floor(float64(codeLen/-2+2)))
178-
}
179-
return math.Pow(float64(encBase), -3) / math.Pow(float64(gridRows), float64(codeLen-pairCodeLen))
180-
}

go/olc.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ func clipLatitude(lat float64) float64 {
231231
return lat
232232
}
233233

234-
func normalizeLat(value float64) float64 {
235-
return normalize(value, latMax)
236-
}
237-
238234
func normalizeLng(value float64) float64 {
239235
return normalize(value, lngMax)
240236
}

go/olc_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ type (
4747
}
4848

4949
decodingTest struct {
50-
code string
51-
length int
52-
lat, lng, latLo, lngLo, latHi, lngHi float64
50+
code string
51+
length int
52+
latLo, lngLo, latHi, lngHi float64
5353
}
5454

5555
shortenTest struct {
@@ -78,9 +78,7 @@ func init() {
7878

7979
go func() {
8080
defer wg.Done()
81-
for _, cols := range append(
82-
mustReadLines("encoding.csv"),
83-
) {
81+
for _, cols := range mustReadLines("encoding.csv") {
8482
encoding = append(encoding, encodingTest{
8583
lat: mustFloat(cols[0]),
8684
lng: mustFloat(cols[1]),
@@ -92,9 +90,7 @@ func init() {
9290

9391
go func() {
9492
defer wg.Done()
95-
for _, cols := range append(
96-
mustReadLines("decoding.csv"),
97-
) {
93+
for _, cols := range mustReadLines("decoding.csv") {
9894
decoding = append(decoding, decodingTest{
9995
code: cols[0],
10096
length: mustInt(cols[1]),

0 commit comments

Comments
 (0)