From 774745cfaed1ed83eed51a32faa6e3dd56537193 Mon Sep 17 00:00:00 2001 From: oneRain Date: Thu, 27 Feb 2020 15:38:23 +0800 Subject: [PATCH] =?UTF-8?q?*=20GeoTest.cs:=20chore:=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=20Geo=20=E5=8A=9F=E8=83=BD=E5=8F=8A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * LCGeoPoint.cs: --- Storage/Storage.Test/GeoTest.cs | 23 +++++++++++++++++++++++ Storage/Storage/LCGeoPoint.cs | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Storage/Storage.Test/GeoTest.cs diff --git a/Storage/Storage.Test/GeoTest.cs b/Storage/Storage.Test/GeoTest.cs new file mode 100644 index 0000000..64eacdf --- /dev/null +++ b/Storage/Storage.Test/GeoTest.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using LeanCloud.Storage; + +namespace LeanCloud.Test { + public class GeoTest { + [Test] + public void Calculate() { + LCGeoPoint p1 = new LCGeoPoint(20.0059, 110.3665); + LCGeoPoint p2 = new LCGeoPoint(20.0353, 110.3645); + double kilometers = p1.KilometersTo(p2); + TestContext.WriteLine(kilometers); + Assert.Less(kilometers - 3.275, 0.01); + + double miles = p1.MilesTo(p2); + TestContext.WriteLine(miles); + Assert.Less(miles - 2.035, 0.01); + + double radians = p1.RadiansTo(p2); + TestContext.WriteLine(radians); + Assert.Less(radians - 0.0005, 0.0001); + } + } +} diff --git a/Storage/Storage/LCGeoPoint.cs b/Storage/Storage/LCGeoPoint.cs index dd5c103..4e1cc39 100644 --- a/Storage/Storage/LCGeoPoint.cs +++ b/Storage/Storage/LCGeoPoint.cs @@ -72,7 +72,7 @@ namespace LeanCloud.Storage { double a = sinDeltaLatDiv2 * sinDeltaLatDiv2 + Math.Cos(lat1rad) * Math.Cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2; a = Math.Min(1.0, a); - return 2 * Math.Cos(Math.Sqrt(a)); + return 2 * Math.Sin(Math.Sqrt(a)); } } }