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.
139118func 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- }
0 commit comments