public virtual void TestNormLon() { var lons = new double[][] { new double[] { 1.23, 1.23 }, //1.23 might become 1.2299999 after some math and we want to ensure that doesn't happen new double[] { -180, -180 }, new double[] { 180, +180 }, new double[] { 0, 0 }, new double[] { -190, 170 }, new double[] { 181, -179 }, new double[] { -180 - 360, -180 }, new double[] { -180 - 720, -180 }, new double[] { 180 + 360, +180 }, new double[] { 180 + 720, +180 } }; foreach (var pair in lons) { CustomAssert.EqualWithDelta( /*"input "+pair[0],*/ pair[1], DistanceUtils.NormLonDEG(pair[0]), double.Epsilon); } var random = new Random(RandomSeed.Seed()); for (int i = -1000; i < 1000; i += random.Next(9) * 10) { double d = DistanceUtils.NormLonDEG(i); Assert.True(d >= -180 && d <= 180, i + " " + d); } }
private void TestDistCalcPointOnBearing(double distKm) { for (int angDEG = 0; angDEG < 360; angDEG += random.Next(1, 20 + 1)) { IPoint c = ctx.MakePoint( DistanceUtils.NormLonDEG(random.Next(359 + 1)), random.Next(-90, 90 + 1)); //0 distance means same point IPoint p2 = Dc().PointOnBearing(c, 0, angDEG, ctx, null); Assert.Equal(c, p2); p2 = Dc().PointOnBearing(c, distKm * DistanceUtils.KM_TO_DEG, angDEG, ctx, null); double calcDistKm = Dc().Distance(c, p2) * DistanceUtils.DEG_TO_KM; AssertEqualsRatio(distKm, calcDistKm); } }