* GeoTest.cs: chore: 完善 Geo 功能及测试

* LCGeoPoint.cs:
oneRain 2020-02-27 15:38:23 +08:00
parent 2e026c2b76
commit 774745cfae
2 changed files with 24 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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));
}
}
}