From 9cdc4efd877e10885cb742603d38d3efa2782413 Mon Sep 17 00:00:00 2001 From: bert Date: Sun, 24 Sep 2017 10:39:50 +0200 Subject: [PATCH 1/2] . using .net standard 1.1 . adding unit tests --- PolylineEncoder.Net.sln | 30 +++++--- PolylineEncoder.Net.v3.ncrunchsolution | 6 ++ global.json | 6 -- .../Models/GeoCoordinate.cs | 58 ++++++++++++++ .../Models/IGeoCoordinate.cs | 8 ++ .../PolylineEncoder.Net.csproj | 34 +++++++++ .../Properties/AssemblyInfo.cs | 0 .../Utility/Decoders/Decoder.cs | 76 +++++++++++++++++++ .../Utility/Decoders/IPolylineDecoder.cs | 12 +++ .../Utility/Encoders/Encoder.cs | 69 +++++++++++++++++ .../Utility/Encoders/IPolylineEncoder.cs | 14 ++++ .../Utility/IPolylineUtility.cs | 9 +++ .../Utility/PolylineUtility.cs | 52 +++++++++++++ .../PolylineEncoder.Net.csproj | 12 +++ .../PolylineEncoder.Net.v3.ncrunchproject | 5 ++ .../PolylineEncoder.Net.xproj | 21 ----- src/PolylineEncoder.Net/project.json | 21 ----- .../PolylineEncder.Tests.csproj | 67 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 20 +++++ test/PolylineEncder.Tests/UnitTest1.cs | 14 ++++ test/PolylineEncder.Tests/packages.config | 5 ++ .../EncodingTests.cs | 43 +++++++++++ .../PolylineEncoder.Net.Tests.csproj | 59 ++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++++ .../PolylineEncoder.Net.Tests/packages.config | 4 + test/PolylineEncoder.Tests/DecodeTests.cs | 26 +++++++ .../PolylineEncoder.Tests.csproj | 15 ++++ 27 files changed, 663 insertions(+), 59 deletions(-) create mode 100644 PolylineEncoder.Net.v3.ncrunchsolution delete mode 100644 global.json create mode 100644 src/@PolylineEncoder.Net/Models/GeoCoordinate.cs create mode 100644 src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs create mode 100644 src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj rename src/{PolylineEncoder.Net => @PolylineEncoder.Net}/Properties/AssemblyInfo.cs (100%) create mode 100644 src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs create mode 100644 src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs create mode 100644 src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs create mode 100644 src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs create mode 100644 src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs create mode 100644 src/@PolylineEncoder.Net/Utility/PolylineUtility.cs create mode 100644 src/PolylineEncoder.Net/PolylineEncoder.Net.csproj create mode 100644 src/PolylineEncoder.Net/PolylineEncoder.Net.v3.ncrunchproject delete mode 100644 src/PolylineEncoder.Net/PolylineEncoder.Net.xproj delete mode 100644 src/PolylineEncoder.Net/project.json create mode 100644 test/PolylineEncder.Tests/PolylineEncder.Tests.csproj create mode 100644 test/PolylineEncder.Tests/Properties/AssemblyInfo.cs create mode 100644 test/PolylineEncder.Tests/UnitTest1.cs create mode 100644 test/PolylineEncder.Tests/packages.config create mode 100644 test/PolylineEncoder.Net.Tests/EncodingTests.cs create mode 100644 test/PolylineEncoder.Net.Tests/PolylineEncoder.Net.Tests.csproj create mode 100644 test/PolylineEncoder.Net.Tests/Properties/AssemblyInfo.cs create mode 100644 test/PolylineEncoder.Net.Tests/packages.config create mode 100644 test/PolylineEncoder.Tests/DecodeTests.cs create mode 100644 test/PolylineEncoder.Tests/PolylineEncoder.Tests.csproj diff --git a/PolylineEncoder.Net.sln b/PolylineEncoder.Net.sln index e6c7f53..25dc40c 100644 --- a/PolylineEncoder.Net.sln +++ b/PolylineEncoder.Net.sln @@ -1,37 +1,45 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{85E635ED-6B86-4A6E-A91C-D8FB551680AE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{617983B4-27C5-43E8-AED8-E7C101A1A86A}" ProjectSection(SolutionItems) = preProject - appveyor.yml = appveyor.yml - global.json = global.json LICENSE = LICENSE README.md = README.md EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PolylineEncoder.Net", "src\PolylineEncoder.Net\PolylineEncoder.Net.xproj", "{7D1B865F-C26D-4C54-B6D7-DC3E2A49749F}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{694420B5-3D4D-4CBA-A418-1D8BD96120BC}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolylineEncoder.Net", "src\PolylineEncoder.Net\PolylineEncoder.Net.csproj", "{C1FB0993-5199-4BFF-8717-8A4DEB098C29}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolylineEncoder.Net.Tests", "test\PolylineEncoder.Net.Tests\PolylineEncoder.Net.Tests.csproj", "{09EBD7BE-FC2F-4283-9133-4E4F4B68B546}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7D1B865F-C26D-4C54-B6D7-DC3E2A49749F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7D1B865F-C26D-4C54-B6D7-DC3E2A49749F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7D1B865F-C26D-4C54-B6D7-DC3E2A49749F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7D1B865F-C26D-4C54-B6D7-DC3E2A49749F}.Release|Any CPU.Build.0 = Release|Any CPU + {C1FB0993-5199-4BFF-8717-8A4DEB098C29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1FB0993-5199-4BFF-8717-8A4DEB098C29}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1FB0993-5199-4BFF-8717-8A4DEB098C29}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1FB0993-5199-4BFF-8717-8A4DEB098C29}.Release|Any CPU.Build.0 = Release|Any CPU + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {7D1B865F-C26D-4C54-B6D7-DC3E2A49749F} = {85E635ED-6B86-4A6E-A91C-D8FB551680AE} + {C1FB0993-5199-4BFF-8717-8A4DEB098C29} = {85E635ED-6B86-4A6E-A91C-D8FB551680AE} + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546} = {694420B5-3D4D-4CBA-A418-1D8BD96120BC} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3B2850B1-2113-4586-A7F6-5DB7FBA20C3A} EndGlobalSection EndGlobal diff --git a/PolylineEncoder.Net.v3.ncrunchsolution b/PolylineEncoder.Net.v3.ncrunchsolution new file mode 100644 index 0000000..f774ab9 --- /dev/null +++ b/PolylineEncoder.Net.v3.ncrunchsolution @@ -0,0 +1,6 @@ + + + False + True + + \ No newline at end of file diff --git a/global.json b/global.json deleted file mode 100644 index 68eb926..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-rc1-final" - } -} \ No newline at end of file diff --git a/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs b/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs new file mode 100644 index 0000000..588eb65 --- /dev/null +++ b/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs @@ -0,0 +1,58 @@ +using System; + +namespace PolylineEncoder.Net.Models +{ + public class GeoCoordinate : IGeoCoordinate + { + #region Properties + + private double _latitude; + public double Latitude + { + get + { + return _latitude; + } + set + { + if (value < -90D || value > 90D) + throw new ArgumentOutOfRangeException(nameof(Latitude), $"{nameof(Latitude)} must be between -90 and 90. Value {value}"); + + _latitude = value; + } + } + + + private double _longitude; + public double Longitude + { + get + { + return _longitude; + } + set + { + if (value < -180D || value >180D) + throw new ArgumentOutOfRangeException(nameof(Longitude), $"{nameof(Longitude)} must be between -180 and 180. Value: {value}"); + + _longitude = value; + } + } + + #endregion + + #region c'tor + + public GeoCoordinate() { } + + public GeoCoordinate(double latitude, double longitude) + { + Latitude = latitude; + Longitude = longitude; + } + + public GeoCoordinate(decimal latitude, decimal longitude) : this((double)latitude, (double)longitude) { } + + #endregion + } +} diff --git a/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs b/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs new file mode 100644 index 0000000..bc7d45d --- /dev/null +++ b/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs @@ -0,0 +1,8 @@ +namespace PolylineEncoder.Net.Models +{ + public interface IGeoCoordinate + { + double Latitude { get; set; } + double Longitude { get; set; } + } +} diff --git a/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj b/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj new file mode 100644 index 0000000..9215689 --- /dev/null +++ b/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj @@ -0,0 +1,34 @@ + + + + PolylineEncoder.Net + 1.0.1 + alexframe + net451;dotnet5.4 + PolylineEncoder.Net + PolylineEncoder.Net + google maps;polyline + https://github.com/alexframe/PolylineEncoder.Net/ + https://github.com/alexframe/PolylineEncoder.Net/blob/master/LICENSE + false + false + false + false + false + false + + + + + + + + + + + + + + + + diff --git a/src/PolylineEncoder.Net/Properties/AssemblyInfo.cs b/src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs similarity index 100% rename from src/PolylineEncoder.Net/Properties/AssemblyInfo.cs rename to src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs diff --git a/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs b/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs new file mode 100644 index 0000000..801dff0 --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using PolylineEncoder.Net.Models; + +namespace PolylineEncoder.Net.Utility.Decoders +{ + public class Decoder : IPolylineDecoder + { + public IEnumerable> DecodeAsTuples(string encodedPoints) + { + if (!string.IsNullOrEmpty(encodedPoints)) + { + foreach (var point in Decode(encodedPoints)) + { + yield return Tuple.Create(point.Latitude, point.Longitude); + } + } + } + + public IEnumerable Decode(string encodedPoints) + { + if (!string.IsNullOrEmpty(encodedPoints)) + { + var polyLineChars = encodedPoints.ToCharArray(); + var index = 0; + + var currentLat = 0; + var currentLng = 0; + + while (index < polyLineChars.Length) + { + // Calculate next Latitude + var sum = 0; + var shifter = 0; + int next5Bits; + + do + { + next5Bits = polyLineChars[index++] - 63; + sum |= (next5Bits & 31) << shifter; + shifter += 5; + } while (next5Bits >= 32 && index < polyLineChars.Length); + + if (index >= polyLineChars.Length) + break; + + currentLat += (sum & 1) == 1 ? ~(sum >> 1) : sum >> 1; + + // Calculate next longitude + sum = 0; + shifter = 0; + + do + { + next5Bits = polyLineChars[index++] - 63; + sum |= (next5Bits & 31) << shifter; + shifter += 5; + } while (next5Bits >= 32 && index < polyLineChars.Length); + + if (index >= polyLineChars.Length && next5Bits >= 32) + break; + + currentLng += (sum & 1) == 1 ? ~(sum >> 1) : sum >> 1; + + var geoPoint = new GeoCoordinate + { + Latitude = Convert.ToDouble(currentLat) / 100000.0, + Longitude = Convert.ToDouble(currentLng) / 100000.0 + }; + + yield return geoPoint; + } + } + } + } +} diff --git a/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs b/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs new file mode 100644 index 0000000..740af68 --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using PolylineEncoder.Net.Models; + +namespace PolylineEncoder.Net.Utility.Decoders +{ + public interface IPolylineDecoder + { + IEnumerable> DecodeAsTuples(string encodedPoints); + IEnumerable Decode(string encodedPoints); + } +} \ No newline at end of file diff --git a/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs b/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs new file mode 100644 index 0000000..40808e0 --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using PolylineEncoder.Net.Models; + +namespace PolylineEncoder.Net.Utility.Encoders +{ + public class Encoder : IPolylineEncoder + { + public string Encode(double latitude, double longitude) + { + return Encode(new GeoCoordinate(latitude, longitude)); + } + + public string Encode(IGeoCoordinate point) + { + return Encode(new[] { point }); + } + + public string Encode(IEnumerable> points) + { + if (points == null) + throw new ArgumentNullException(nameof(points)); + + var geoPoints = points.Select(point => new GeoCoordinate(point.Item1, point.Item2)).Cast().ToList(); + return Encode(geoPoints); + } + + public string Encode(IEnumerable points) + { + if (points == null) + throw new ArgumentNullException(nameof(points)); + + var encodedPolyline = new StringBuilder(); + + var encodeDiff = (Action)(diff => + { + var shifted = diff << 1; + if (diff < 0) + shifted = ~shifted; + + var rem = shifted; + while (rem >= 0x20) + { + encodedPolyline.Append((char)((0x20 | (rem & 0x1f)) + 63)); + rem >>= 5; + } + encodedPolyline.Append((char)(rem + 63)); + }); + + var lastLat = 0; + var lastLng = 0; + foreach (var point in points) + { + var lat = (int)Math.Round(point.Latitude * 1E5); + var lng = (int)Math.Round(point.Longitude * 1E5); + + encodeDiff(lat - lastLat); + encodeDiff(lng - lastLng); + + lastLat = lat; + lastLng = lng; + } + + return encodedPolyline.ToString(); + } + } +} diff --git a/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs b/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs new file mode 100644 index 0000000..e18816b --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using PolylineEncoder.Net.Models; + +namespace PolylineEncoder.Net.Utility.Encoders +{ + public interface IPolylineEncoder + { + string Encode(double latitude, double longitude); + string Encode(IGeoCoordinate point); + string Encode(IEnumerable> points); + string Encode(IEnumerable points); + } +} diff --git a/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs b/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs new file mode 100644 index 0000000..ba52a63 --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs @@ -0,0 +1,9 @@ +using PolylineEncoder.Net.Utility.Decoders; +using PolylineEncoder.Net.Utility.Encoders; + +namespace PolylineEncoder.Net.Utility +{ + public interface IPolylineUtility : IPolylineEncoder, IPolylineDecoder + { + } +} diff --git a/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs b/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs new file mode 100644 index 0000000..12420f4 --- /dev/null +++ b/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using PolylineEncoder.Net.Models; +using PolylineEncoder.Net.Utility.Decoders; +using PolylineEncoder.Net.Utility.Encoders; + +namespace PolylineEncoder.Net.Utility +{ + public class PolylineUtility : IPolylineUtility + { + private readonly IPolylineEncoder _encoder; + private readonly IPolylineDecoder _decoder; + + public PolylineUtility() : this(new Encoder(), new Decoder()) { } + + public PolylineUtility(IPolylineEncoder encoder, IPolylineDecoder decoder) + { + _encoder = encoder; + _decoder = decoder; + } + + public string Encode(double latitude, double longitude) + { + return _encoder.Encode(latitude, longitude); + } + + public string Encode(IGeoCoordinate point) + { + return _encoder.Encode(point); + } + + public string Encode(IEnumerable> points) + { + return _encoder.Encode(points); + } + + public string Encode(IEnumerable points) + { + return _encoder.Encode(points); + } + + public IEnumerable> DecodeAsTuples(string encodedPoints) + { + return _decoder.DecodeAsTuples(encodedPoints); + } + + public IEnumerable Decode(string encodedPoints) + { + return _decoder.Decode(encodedPoints); + } + } +} diff --git a/src/PolylineEncoder.Net/PolylineEncoder.Net.csproj b/src/PolylineEncoder.Net/PolylineEncoder.Net.csproj new file mode 100644 index 0000000..3970671 --- /dev/null +++ b/src/PolylineEncoder.Net/PolylineEncoder.Net.csproj @@ -0,0 +1,12 @@ + + + + netstandard1.1 + true + + + + + + + diff --git a/src/PolylineEncoder.Net/PolylineEncoder.Net.v3.ncrunchproject b/src/PolylineEncoder.Net/PolylineEncoder.Net.v3.ncrunchproject new file mode 100644 index 0000000..6800b4a --- /dev/null +++ b/src/PolylineEncoder.Net/PolylineEncoder.Net.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/src/PolylineEncoder.Net/PolylineEncoder.Net.xproj b/src/PolylineEncoder.Net/PolylineEncoder.Net.xproj deleted file mode 100644 index 8aa7154..0000000 --- a/src/PolylineEncoder.Net/PolylineEncoder.Net.xproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 7d1b865f-c26d-4c54-b6d7-dc3e2a49749f - PolylineEncoder.Net - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - True - - - \ No newline at end of file diff --git a/src/PolylineEncoder.Net/project.json b/src/PolylineEncoder.Net/project.json deleted file mode 100644 index 887c194..0000000 --- a/src/PolylineEncoder.Net/project.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "1.0.1-*", - "description": "PolylineEncoder.Net", - "authors": [ "alexframe" ], - "tags": [ "google maps", "polyline" ], - "projectUrl": "https://github.com/alexframe/PolylineEncoder.Net/", - "licenseUrl": "https://github.com/alexframe/PolylineEncoder.Net/blob/master/LICENSE", - - "frameworks": { - "net451": { }, - "dotnet5.4": { - "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-23516", - "System.Collections": "4.0.11-beta-23516", - "System.Linq": "4.0.1-beta-23516", - "System.Runtime": "4.0.21-beta-23516", - "System.Threading": "4.0.11-beta-23516" - } - } - } -} diff --git a/test/PolylineEncder.Tests/PolylineEncder.Tests.csproj b/test/PolylineEncder.Tests/PolylineEncder.Tests.csproj new file mode 100644 index 0000000..9bd0c58 --- /dev/null +++ b/test/PolylineEncder.Tests/PolylineEncder.Tests.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {EB72B3BF-E2EC-45B1-BD69-848060E5AD66} + Library + Properties + PolylineEncder.Tests + PolylineEncder.Tests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/test/PolylineEncder.Tests/Properties/AssemblyInfo.cs b/test/PolylineEncder.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c534f57 --- /dev/null +++ b/test/PolylineEncder.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("PolylineEncder.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PolylineEncder.Tests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("eb72b3bf-e2ec-45b1-bd69-848060e5ad66")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PolylineEncder.Tests/UnitTest1.cs b/test/PolylineEncder.Tests/UnitTest1.cs new file mode 100644 index 0000000..70cbeec --- /dev/null +++ b/test/PolylineEncder.Tests/UnitTest1.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace PolylineEncder.Tests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/test/PolylineEncder.Tests/packages.config b/test/PolylineEncder.Tests/packages.config new file mode 100644 index 0000000..d8c1b90 --- /dev/null +++ b/test/PolylineEncder.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/test/PolylineEncoder.Net.Tests/EncodingTests.cs b/test/PolylineEncoder.Net.Tests/EncodingTests.cs new file mode 100644 index 0000000..8fa39fc --- /dev/null +++ b/test/PolylineEncoder.Net.Tests/EncodingTests.cs @@ -0,0 +1,43 @@ +using NUnit.Framework; +using PolylineEncoder.Net.Models; +using PolylineEncoder.Net.Utility; +using System.Collections.Generic; +using System.Linq; + +namespace PolylineEncoder.Tests +{ + public class DecodeTests + { + [Test] + public void DecodeTest() + { + // arrange + var s = "sezbGuogHuAa@TmFgAeCrBsH|FaG~CHE{IrAPtFkKgF}h@rC{AMuG~FoBpFdNvDoGhDKpBfB~CnKlHmT`IDdB{Yk@}MyCkNjKrDM`DhElFxCvNt@sS|BhB~AeKhBaBqAqDqAV}AoF}Akd@}ByJpAc@JkLfAzPzAUKmf@rBgRn@KP|G|AxCvAuAMqBtAECqCnFsGaHcl@hC{AfAyNhF_IfDsKnGcGtRqC|MbG|AcCxFtHxAyCo@aIdAaA?aFkFuT`JaC~C|Eh@mLzMpCtCaC`@|EzC}HxGbMt@xH_AvAzFs@"; + var utility = new PolylineUtility(); + + // act + IEnumerable res = utility.Decode(s); + + // assert + Assert.IsTrue(res != null); + Assert.IsTrue(res.ToList().Count > 0); + } + + [Test] + public void EncodeTest() + { + // arrange + var expected = "_c`|@_c`|@"; + var utility = new PolylineUtility(); + var p = new GeoCoordinate(10.0, 10.0); + + // act + var encoded = utility.Encode(p); + + // assert + Assert.IsTrue(encoded != null); + Assert.IsTrue(encoded == expected); + } + + } +} diff --git a/test/PolylineEncoder.Net.Tests/PolylineEncoder.Net.Tests.csproj b/test/PolylineEncoder.Net.Tests/PolylineEncoder.Net.Tests.csproj new file mode 100644 index 0000000..64d577e --- /dev/null +++ b/test/PolylineEncoder.Net.Tests/PolylineEncoder.Net.Tests.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {09EBD7BE-FC2F-4283-9133-4E4F4B68B546} + Library + Properties + PolylineEncoder.Net.Tests + PolylineEncoder.Net.Tests + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + {c1fb0993-5199-4bff-8717-8a4deb098c29} + PolylineEncoder.Net + + + + \ No newline at end of file diff --git a/test/PolylineEncoder.Net.Tests/Properties/AssemblyInfo.cs b/test/PolylineEncoder.Net.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d5c16fa --- /dev/null +++ b/test/PolylineEncoder.Net.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PolylineEncoder.Net.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PolylineEncoder.Net.Tests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("09ebd7be-fc2f-4283-9133-4e4f4b68b546")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PolylineEncoder.Net.Tests/packages.config b/test/PolylineEncoder.Net.Tests/packages.config new file mode 100644 index 0000000..0ee860b --- /dev/null +++ b/test/PolylineEncoder.Net.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/PolylineEncoder.Tests/DecodeTests.cs b/test/PolylineEncoder.Tests/DecodeTests.cs new file mode 100644 index 0000000..ad94bd9 --- /dev/null +++ b/test/PolylineEncoder.Tests/DecodeTests.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using PolylineEncoder.Net.Models; +using PolylineEncoder.Net.Utility; +using System.Collections.Generic; +using System.Linq; + +namespace PolylineEncoder.Tests +{ + public class DecodeTests + { + [Test] + public void ToStringTest() + { + // arrange + var s = "sezbGuogHuAa@TmFgAeCrBsH|FaG~CHE{IrAPtFkKgF}h@rC{AMuG~FoBpFdNvDoGhDKpBfB~CnKlHmT`IDdB{Yk@}MyCkNjKrDM`DhElFxCvNt@sS|BhB~AeKhBaBqAqDqAV}AoF}Akd@}ByJpAc@JkLfAzPzAUKmf@rBgRn@KP|G|AxCvAuAMqBtAECqCnFsGaHcl@hC{AfAyNhF_IfDsKnGcGtRqC|MbG|AcCxFtHxAyCo@aIdAaA?aFkFuT`JaC~C|Eh@mLzMpCtCaC`@|EzC}HxGbMt@xH_AvAzFs@"; + var utility = new PolylineUtility(); + + // act + IEnumerable res = utility.Decode(s); + + // assert + Assert.IsTrue(res!=null); + Assert.IsTrue(res.ToList().Count > 0); + } + } +} diff --git a/test/PolylineEncoder.Tests/PolylineEncoder.Tests.csproj b/test/PolylineEncoder.Tests/PolylineEncoder.Tests.csproj new file mode 100644 index 0000000..b3aeafd --- /dev/null +++ b/test/PolylineEncoder.Tests/PolylineEncoder.Tests.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + + + + + + + + + + + From 21c0fbb0377e14914373e82ee5a89efd2f51403a Mon Sep 17 00:00:00 2001 From: bert Date: Sun, 24 Sep 2017 10:42:14 +0200 Subject: [PATCH 2/2] remove old project --- .../Models/GeoCoordinate.cs | 58 -------------- .../Models/IGeoCoordinate.cs | 8 -- .../PolylineEncoder.Net.csproj | 34 --------- .../Properties/AssemblyInfo.cs | 23 ------ .../Utility/Decoders/Decoder.cs | 76 ------------------- .../Utility/Decoders/IPolylineDecoder.cs | 12 --- .../Utility/Encoders/Encoder.cs | 69 ----------------- .../Utility/Encoders/IPolylineEncoder.cs | 14 ---- .../Utility/IPolylineUtility.cs | 9 --- .../Utility/PolylineUtility.cs | 52 ------------- 10 files changed, 355 deletions(-) delete mode 100644 src/@PolylineEncoder.Net/Models/GeoCoordinate.cs delete mode 100644 src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs delete mode 100644 src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj delete mode 100644 src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs delete mode 100644 src/@PolylineEncoder.Net/Utility/PolylineUtility.cs diff --git a/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs b/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs deleted file mode 100644 index 588eb65..0000000 --- a/src/@PolylineEncoder.Net/Models/GeoCoordinate.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; - -namespace PolylineEncoder.Net.Models -{ - public class GeoCoordinate : IGeoCoordinate - { - #region Properties - - private double _latitude; - public double Latitude - { - get - { - return _latitude; - } - set - { - if (value < -90D || value > 90D) - throw new ArgumentOutOfRangeException(nameof(Latitude), $"{nameof(Latitude)} must be between -90 and 90. Value {value}"); - - _latitude = value; - } - } - - - private double _longitude; - public double Longitude - { - get - { - return _longitude; - } - set - { - if (value < -180D || value >180D) - throw new ArgumentOutOfRangeException(nameof(Longitude), $"{nameof(Longitude)} must be between -180 and 180. Value: {value}"); - - _longitude = value; - } - } - - #endregion - - #region c'tor - - public GeoCoordinate() { } - - public GeoCoordinate(double latitude, double longitude) - { - Latitude = latitude; - Longitude = longitude; - } - - public GeoCoordinate(decimal latitude, decimal longitude) : this((double)latitude, (double)longitude) { } - - #endregion - } -} diff --git a/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs b/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs deleted file mode 100644 index bc7d45d..0000000 --- a/src/@PolylineEncoder.Net/Models/IGeoCoordinate.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PolylineEncoder.Net.Models -{ - public interface IGeoCoordinate - { - double Latitude { get; set; } - double Longitude { get; set; } - } -} diff --git a/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj b/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj deleted file mode 100644 index 9215689..0000000 --- a/src/@PolylineEncoder.Net/PolylineEncoder.Net.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - PolylineEncoder.Net - 1.0.1 - alexframe - net451;dotnet5.4 - PolylineEncoder.Net - PolylineEncoder.Net - google maps;polyline - https://github.com/alexframe/PolylineEncoder.Net/ - https://github.com/alexframe/PolylineEncoder.Net/blob/master/LICENSE - false - false - false - false - false - false - - - - - - - - - - - - - - - - diff --git a/src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs b/src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs deleted file mode 100644 index 1f370a5..0000000 --- a/src/@PolylineEncoder.Net/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("PolylineEncoder.Net")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Fairfax Media")] -[assembly: AssemblyProduct("PolylineEncoder.Net")] -[assembly: AssemblyCopyright("Copyright © Fairfax Media 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("7d1b865f-c26d-4c54-b6d7-dc3e2a49749f")] diff --git a/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs b/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs deleted file mode 100644 index 801dff0..0000000 --- a/src/@PolylineEncoder.Net/Utility/Decoders/Decoder.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using PolylineEncoder.Net.Models; - -namespace PolylineEncoder.Net.Utility.Decoders -{ - public class Decoder : IPolylineDecoder - { - public IEnumerable> DecodeAsTuples(string encodedPoints) - { - if (!string.IsNullOrEmpty(encodedPoints)) - { - foreach (var point in Decode(encodedPoints)) - { - yield return Tuple.Create(point.Latitude, point.Longitude); - } - } - } - - public IEnumerable Decode(string encodedPoints) - { - if (!string.IsNullOrEmpty(encodedPoints)) - { - var polyLineChars = encodedPoints.ToCharArray(); - var index = 0; - - var currentLat = 0; - var currentLng = 0; - - while (index < polyLineChars.Length) - { - // Calculate next Latitude - var sum = 0; - var shifter = 0; - int next5Bits; - - do - { - next5Bits = polyLineChars[index++] - 63; - sum |= (next5Bits & 31) << shifter; - shifter += 5; - } while (next5Bits >= 32 && index < polyLineChars.Length); - - if (index >= polyLineChars.Length) - break; - - currentLat += (sum & 1) == 1 ? ~(sum >> 1) : sum >> 1; - - // Calculate next longitude - sum = 0; - shifter = 0; - - do - { - next5Bits = polyLineChars[index++] - 63; - sum |= (next5Bits & 31) << shifter; - shifter += 5; - } while (next5Bits >= 32 && index < polyLineChars.Length); - - if (index >= polyLineChars.Length && next5Bits >= 32) - break; - - currentLng += (sum & 1) == 1 ? ~(sum >> 1) : sum >> 1; - - var geoPoint = new GeoCoordinate - { - Latitude = Convert.ToDouble(currentLat) / 100000.0, - Longitude = Convert.ToDouble(currentLng) / 100000.0 - }; - - yield return geoPoint; - } - } - } - } -} diff --git a/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs b/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs deleted file mode 100644 index 740af68..0000000 --- a/src/@PolylineEncoder.Net/Utility/Decoders/IPolylineDecoder.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using PolylineEncoder.Net.Models; - -namespace PolylineEncoder.Net.Utility.Decoders -{ - public interface IPolylineDecoder - { - IEnumerable> DecodeAsTuples(string encodedPoints); - IEnumerable Decode(string encodedPoints); - } -} \ No newline at end of file diff --git a/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs b/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs deleted file mode 100644 index 40808e0..0000000 --- a/src/@PolylineEncoder.Net/Utility/Encoders/Encoder.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using PolylineEncoder.Net.Models; - -namespace PolylineEncoder.Net.Utility.Encoders -{ - public class Encoder : IPolylineEncoder - { - public string Encode(double latitude, double longitude) - { - return Encode(new GeoCoordinate(latitude, longitude)); - } - - public string Encode(IGeoCoordinate point) - { - return Encode(new[] { point }); - } - - public string Encode(IEnumerable> points) - { - if (points == null) - throw new ArgumentNullException(nameof(points)); - - var geoPoints = points.Select(point => new GeoCoordinate(point.Item1, point.Item2)).Cast().ToList(); - return Encode(geoPoints); - } - - public string Encode(IEnumerable points) - { - if (points == null) - throw new ArgumentNullException(nameof(points)); - - var encodedPolyline = new StringBuilder(); - - var encodeDiff = (Action)(diff => - { - var shifted = diff << 1; - if (diff < 0) - shifted = ~shifted; - - var rem = shifted; - while (rem >= 0x20) - { - encodedPolyline.Append((char)((0x20 | (rem & 0x1f)) + 63)); - rem >>= 5; - } - encodedPolyline.Append((char)(rem + 63)); - }); - - var lastLat = 0; - var lastLng = 0; - foreach (var point in points) - { - var lat = (int)Math.Round(point.Latitude * 1E5); - var lng = (int)Math.Round(point.Longitude * 1E5); - - encodeDiff(lat - lastLat); - encodeDiff(lng - lastLng); - - lastLat = lat; - lastLng = lng; - } - - return encodedPolyline.ToString(); - } - } -} diff --git a/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs b/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs deleted file mode 100644 index e18816b..0000000 --- a/src/@PolylineEncoder.Net/Utility/Encoders/IPolylineEncoder.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using PolylineEncoder.Net.Models; - -namespace PolylineEncoder.Net.Utility.Encoders -{ - public interface IPolylineEncoder - { - string Encode(double latitude, double longitude); - string Encode(IGeoCoordinate point); - string Encode(IEnumerable> points); - string Encode(IEnumerable points); - } -} diff --git a/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs b/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs deleted file mode 100644 index ba52a63..0000000 --- a/src/@PolylineEncoder.Net/Utility/IPolylineUtility.cs +++ /dev/null @@ -1,9 +0,0 @@ -using PolylineEncoder.Net.Utility.Decoders; -using PolylineEncoder.Net.Utility.Encoders; - -namespace PolylineEncoder.Net.Utility -{ - public interface IPolylineUtility : IPolylineEncoder, IPolylineDecoder - { - } -} diff --git a/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs b/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs deleted file mode 100644 index 12420f4..0000000 --- a/src/@PolylineEncoder.Net/Utility/PolylineUtility.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using PolylineEncoder.Net.Models; -using PolylineEncoder.Net.Utility.Decoders; -using PolylineEncoder.Net.Utility.Encoders; - -namespace PolylineEncoder.Net.Utility -{ - public class PolylineUtility : IPolylineUtility - { - private readonly IPolylineEncoder _encoder; - private readonly IPolylineDecoder _decoder; - - public PolylineUtility() : this(new Encoder(), new Decoder()) { } - - public PolylineUtility(IPolylineEncoder encoder, IPolylineDecoder decoder) - { - _encoder = encoder; - _decoder = decoder; - } - - public string Encode(double latitude, double longitude) - { - return _encoder.Encode(latitude, longitude); - } - - public string Encode(IGeoCoordinate point) - { - return _encoder.Encode(point); - } - - public string Encode(IEnumerable> points) - { - return _encoder.Encode(points); - } - - public string Encode(IEnumerable points) - { - return _encoder.Encode(points); - } - - public IEnumerable> DecodeAsTuples(string encodedPoints) - { - return _decoder.DecodeAsTuples(encodedPoints); - } - - public IEnumerable Decode(string encodedPoints) - { - return _decoder.Decode(encodedPoints); - } - } -}