diff --git a/src/AprsParser/Position.cs b/src/AprsParser/Position.cs index b51d2e7..dd86c82 100644 --- a/src/AprsParser/Position.cs +++ b/src/AprsParser/Position.cs @@ -198,35 +198,6 @@ public void Decode(string coords) } } - private static int DecodeBase91(string encoded) - { - var bytes = Encoding.ASCII.GetBytes(encoded); - - var result = 0; - for (var i = 0; i < bytes.Length; i++) - { - result += i == bytes.Length - 1 - ? bytes[i] - 33 - : (bytes[i] - 33) * (int)Math.Pow(91, bytes.Length - i - 1); - } - - return result; - } - - private static double DecodeCompressedLatitude(string coords) - { - Debug.Assert(coords.Length == 4, "Compressed latitude must be 4 characters"); - var latitude = 90 - (DecodeBase91(coords) / 380926.0); - return Math.Round(latitude, 4); - } - - private static double DecodeCompressedLongitude(string coords) - { - Debug.Assert(coords.Length == 4, "Compressed longitude must be 4 characters"); - var longitude = -180 + (DecodeBase91(coords) / 190463.0); - return Math.Round(longitude, 4); - } - /// /// Decode from Maidenhead Location System gridsquare to a point in the middle of the gridsquare. /// @@ -477,6 +448,35 @@ public string EncodeLongitude() return EncodeCoordinates(CoordinateSystem.Longitude); } + private static int DecodeBase91(string encoded) + { + var bytes = Encoding.ASCII.GetBytes(encoded); + + var result = 0; + for (var i = 0; i < bytes.Length; i++) + { + result += i == bytes.Length - 1 + ? bytes[i] - 33 + : (bytes[i] - 33) * (int)Math.Pow(91, bytes.Length - i - 1); + } + + return result; + } + + private static double DecodeCompressedLatitude(string coords) + { + Debug.Assert(coords.Length == 4, "Compressed latitude must be 4 characters"); + var latitude = 90 - (DecodeBase91(coords) / 380926.0); + return Math.Round(latitude, 4); + } + + private static double DecodeCompressedLongitude(string coords) + { + Debug.Assert(coords.Length == 4, "Compressed longitude must be 4 characters"); + var longitude = -180 + (DecodeBase91(coords) / 190463.0); + return Math.Round(longitude, 4); + } + /// /// Encode either the latitude or longitude part of a Maidenhead gridsquare. /// diff --git a/src/AprsParser/RegexStrings.cs b/src/AprsParser/RegexStrings.cs index 512a99a..3ffc8c6 100644 --- a/src/AprsParser/RegexStrings.cs +++ b/src/AprsParser/RegexStrings.cs @@ -42,7 +42,7 @@ internal static class RegexStrings /// Compressed Longitude /// Symbol code /// Compressed one of: course/speed, radio range, or altitude - /// Compressed data type + /// Compressed data type. /// public const string CompressedPosition = @"(.)(.{4})(.{4})(.)(.{2})(.)";