From e125668b79073b125d7f7906d50c60f2b60e9396 Mon Sep 17 00:00:00 2001 From: Tron Legacy Date: Mon, 8 Jul 2024 17:38:50 -0700 Subject: [PATCH] 2.24.1.1 -Fixes bug causing incorrect sun condition to report in circumpolar regions during slow transition at horizon. -Adds feature to allow custom specification of earth shape during point densification. --- .../CoordinateSharp.Magnetic.csproj | 4 +- .../Celestial/Celestial.StaticMethods.cs | 2 +- .../Celestial/Solar/SunCalculations.cs | 195 +++++++++++++++--- CoordinateSharp/CoordinateSharp.csproj | 9 +- CoordinateSharp/GeoFence/GeoFence.cs | 54 ++++- CoordinateSharp_UnitTests/Celestial.Solar.cs | 53 ++++- CoordinateSharp_UnitTests/GeoFence.cs | 7 +- 7 files changed, 281 insertions(+), 43 deletions(-) diff --git a/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj b/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj index 5a8b121a..be39c454 100644 --- a/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj +++ b/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj @@ -47,7 +47,7 @@ For more information, please contact Signature Group, LLC at this address: sales net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80 true true - 1.1.13.0 + 1.1.14.0 Signature Group, LLC https://github.com/Tronald/CoordinateSharp @@ -61,7 +61,7 @@ For more information, please contact Signature Group, LLC at this address: sales CoordinateSharp.Magnetic CoordinateSharp.Magnetic - 1.1.13.0 + 1.1.14.0 true true 128x128.png diff --git a/CoordinateSharp/Celestial/Celestial.StaticMethods.cs b/CoordinateSharp/Celestial/Celestial.StaticMethods.cs index ef402f0b..116182a2 100644 --- a/CoordinateSharp/Celestial/Celestial.StaticMethods.cs +++ b/CoordinateSharp/Celestial/Celestial.StaticMethods.cs @@ -1147,7 +1147,7 @@ public static AltitudeEvents Get_Time_at_Solar_Altitude(double lat, double longi double lw = rad * -longi; double phi = rad * lat; - var events = SunCalc.Get_Event_Time(lw, phi, alt, date, offset, false); + var events = SunCalc.Get_Event_Time(lat, longi, lw, phi, alt, date, offset, false); var altE = new AltitudeEvents() { Rising = events[0], Setting = events[1] }; diff --git a/CoordinateSharp/Celestial/Solar/SunCalculations.cs b/CoordinateSharp/Celestial/Solar/SunCalculations.cs index a1d21fab..93b1dec2 100644 --- a/CoordinateSharp/Celestial/Solar/SunCalculations.cs +++ b/CoordinateSharp/Celestial/Solar/SunCalculations.cs @@ -45,6 +45,7 @@ or shipping CoordinateSharp with a closed source product. using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using CoordinateSharp.Formatters; namespace CoordinateSharp { @@ -57,7 +58,9 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes if (el.Extensions.Solar_Cycle) { DateTime actualDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc); + + ////Sun Time Calculations //Get solar coordinate info and feed //Get Julian @@ -65,30 +68,38 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes double phi = rad * lat; //Rise Set - DateTime?[] evDate = Get_Event_Time(lw, phi, -.8333, actualDate, offset,true); //ADDED OFFSET TO ALL Get_Event_Time calls. + DateTime?[] evDate = Get_Event_Time(lat, lng, lw, phi, -.8333, actualDate, offset,true); //ADDED OFFSET TO ALL Get_Event_Time calls. c.sunRise = evDate[0]; c.sunSet = evDate[1]; c.solarNoon = evDate[2]; - - c.sunCondition = CelestialStatus.RiseAndSet; //Get Solar Coordinate var celC = Get_Solar_Coordinates(date, -offset); c.solarCoordinates = celC; //Azimuth and Altitude CalculateSunAngle(date.AddHours(-offset), lng, lat, c, celC); //SUBTRACT OFFSET TO CALC IN Z TIME AND ADJUST SUN ANGLE DURING LOCAL CALCULATIONS. + + //SET SUN CONDITION + c.sunCondition = CelestialStatus.RiseAndSet; + // neither sunrise nor sunset if ((!c.SunRise.HasValue) && (!c.SunSet.HasValue)) { - if (c.SunAltitude < 0) + //Check sun altitude at apex (solar noon) to ensure accurate logic. + //Previous logic determined of user time passed (c.sunAltitude), but due to Meeus limitation in 15.1, it could cause a misreport. + //https://github.com/Tronald/CoordinateSharp/issues/167 + + var safety = new Celestial(); + CalculateSunAngle(c.solarNoon.Value, lng, lat, safety, celC); + + if (safety.sunAltitude <= -.8333) { c.sunCondition = CelestialStatus.DownAllDay; - } else { - c.sunCondition = CelestialStatus.UpAllDay; + c.sunCondition = CelestialStatus.UpAllDay; } } // sunrise or sunset @@ -96,17 +107,14 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes { if (!c.SunRise.HasValue) { - // No sunrise this date c.sunCondition = CelestialStatus.NoRise; - } else if (!c.SunSet.HasValue) { - // No sunset this date c.sunCondition = CelestialStatus.NoSet; - } + } } - + //Sat day and night time spans within 24 hours period Set_DayNightSpan(c); @@ -114,24 +122,24 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes c.additionalSolarTimes = new AdditionalSolarTimes(); //Dusk and Dawn //Civil - evDate = Get_Event_Time(lw, phi, -6, actualDate, offset,false); + evDate = Get_Event_Time(lat, lng, lw, phi, -6, actualDate, offset,false); c.AdditionalSolarTimes.civilDawn = evDate[0]; c.AdditionalSolarTimes.civilDusk = evDate[1]; //Nautical - evDate = Get_Event_Time(lw, phi, -12, actualDate, offset, false); + evDate = Get_Event_Time(lat, lng, lw, phi, -12, actualDate, offset, false); c.AdditionalSolarTimes.nauticalDawn = evDate[0]; c.AdditionalSolarTimes.nauticalDusk = evDate[1]; //Astronomical - evDate = Get_Event_Time(lw, phi, -18, actualDate, offset, false); + evDate = Get_Event_Time(lat, lng, lw, phi, -18, actualDate, offset, false); c.AdditionalSolarTimes.astronomicalDawn = evDate[0]; c.AdditionalSolarTimes.astronomicalDusk = evDate[1]; //BottomDisc - evDate = Get_Event_Time(lw, phi, -.2998, actualDate, offset, false); + evDate = Get_Event_Time(lat, lng, lw, phi, -.2998, actualDate, offset, false); c.AdditionalSolarTimes.sunriseBottomDisc = evDate[0]; c.AdditionalSolarTimes.sunsetBottomDisc = evDate[1]; @@ -141,9 +149,22 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes if (el.Extensions.Solstice_Equinox){ Calculate_Solstices_Equinoxes(date, c, offset); } if (el.Extensions.Solar_Eclipse) { CalculateSolarEclipse(date, lat, lng, c); } } + + private static double GetAltitude(DateTime date, double offset, double lat, double lng) + { + var safety = new Celestial(); + + var celC = Get_Solar_Coordinates(date, offset); + CalculateSunAngle(date.AddHours(-offset), lng, lat, safety, celC); + + return safety.sunAltitude; + } + /// /// Gets time of event based on specified degree below specified altitude /// + /// Observer Latitude in degrees + /// Observer Longitude in degrees /// Observer Longitude in radians /// Observer Latitude in radians /// Angle in Degrees @@ -151,7 +172,7 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes /// Offset hours /// Should solar noon iterate and return value /// DateTime?[]{rise, set} - internal static DateTime?[] Get_Event_Time(double lw, double phi, double h, DateTime date, double offset, bool calculateNoon) + internal static DateTime?[] Get_Event_Time(double lat, double lng, double lw, double phi, double h, DateTime date, double offset, bool calculateNoon) { double julianOffset = offset * .04166667; @@ -167,16 +188,10 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes double d = JulianConversions.GetJulian(date.AddDays(x-2)) - j2000 + .5; //LESS PRECISE JULIAN NEEDED double n = julianCycle(d, lw); - //var celC = Get_Solar_Coordinates(date); //Change and Test locs! - - double ds = approxTransit(0, lw, n); - - //M = celC.MeanAnomaly.ToRadians(); + double ds = approxTransit(0, lw, n); double M = solarMeanAnomaly(ds); - - double L = eclipticLongitude(M); double dec = declination(L, 0); @@ -200,16 +215,144 @@ public static void CalculateSunTime(double lat, double lng, DateTime date, Celes } } + DateTime? tNoon = null; + if (calculateNoon) + { + tNoon = Get_Event_Target_Date(solarNoons, date); + solarEventsCorrection(lat, lng, date, offset, rises, sets, tNoon); + } + //Compare and send DateTime? tRise = Get_Event_Target_Date(rises, date); DateTime? tSet = Get_Event_Target_Date(sets, date); - DateTime? tNoon = null; - if (calculateNoon){tNoon = Get_Event_Target_Date(solarNoons, date); } + return new DateTime?[] { tRise, tSet, tNoon}; } + /// + /// Corrects near horizon miss calculations that may occur on rare occasion due to Meeus 15.1 limitation. + /// May cause slight efficiency decrease during transition from rise/set to up or down all day. + /// Occurs rare so delay should be negligent in most instances. + /// + /// latitude + /// longitude + /// target date + /// timezone offset + /// sun rises + /// sun sets + ///solar noon time + private static void solarEventsCorrection(double lat, double lng, DateTime target, double offset, DateTime?[] rises, DateTime?[] sets, DateTime? solarNoon) + { + if (!solarNoon.HasValue) { return; }//can't check + if (!datesContainNull(rises) && !datesContainNull(sets)) { return; } + + DateTime? tRise = Get_Event_Target_Date(rises, target); + DateTime? tSet = Get_Event_Target_Date(sets, target); + + int? setIndex = null; + int? riseIndex = null; + + //Determine if this can be passed through a top level call in future for efficiency. This is a duplicate call, but original may not return correct value + var solarAltitude = GetAltitude(solarNoon.Value, offset, lat, lng); + + if (tRise.HasValue && tSet.HasValue) + { + setIndex = targetEventIndex(sets, tSet.Value); + riseIndex = targetEventIndex(rises, tRise.Value); + + if(setIndex==null || riseIndex==null) { return; } + + //SEE IF NEXT DAY HAS DUPLICATE NULLS. SIGNALS ALL DAY EVENT OCCURING + if (setIndex != 4 && riseIndex != 4 && !sets[setIndex.Value + 1].HasValue && !rises[riseIndex.Value + 1].HasValue) + { + + + //IF RISE AFTER SET AND DOWN ALL DAY ZERO OUT RISE + if (solarAltitude<=-0.8333 && sets[setIndex.Value].Value < rises[riseIndex.Value].Value) + { + rises[riseIndex.Value] = null; + } + ////IF SET IS AFTER RISE AND UP ALL DAY, ZERO OUT SET + else if (solarAltitude> -0.8333 && sets[setIndex.Value].Value > rises[riseIndex.Value].Value) + { + sets[setIndex.Value] = null; + } + + + } + //SEE IF PREVIOUS DAY HAS DUPLICATE NULLS + else if (setIndex != 0 && riseIndex != 0 && !sets[setIndex.Value - 1].HasValue && !rises[riseIndex.Value - 1].HasValue) + { + + ////IF RISE IS BEFORE SET AND DOWN ALL DAY ZERO OUT RISE + if (solarAltitude <= -0.8333 && sets[setIndex.Value].Value > rises[riseIndex.Value].Value) + { + rises[riseIndex.Value] = null; + } + ////IF SET IS BEFORE RISE AND UP ALL DAY, ZERO OUT SET + else if (solarAltitude> -0.8333 && sets[setIndex.Value].Value < rises[riseIndex.Value].Value) + { + sets[setIndex.Value] = null; + } + } + } + else if(tRise.HasValue && !tSet.HasValue) + { + riseIndex = targetEventIndex(rises, tRise.Value); + if (riseIndex == null) { return; } + + //IF NEXT DAY IS UP DOWN ALL DAY SCRATCH THIS TIME BECAUSE THE SUN HAS TO SET FIRST + if(riseIndex != 4 && !rises[riseIndex.Value + 1].HasValue && solarAltitude <= -0.8333) + { + rises[riseIndex.Value] = null; + } + //IF PREVIOUS DAY IS UP ALL DAY SCRATCH AS THIS HAS TO SET FIRST + else if (riseIndex != 0 && !rises[riseIndex.Value - 1].HasValue && solarAltitude > -0.8333) + { + rises[riseIndex.Value] = null; + } + + + } + else if (!tRise.HasValue && tSet.HasValue) + { + setIndex = targetEventIndex(sets, tSet.Value); + if (setIndex == null) { return; } + + //IF NEXT DAY IS UP ALL DAY SCRATCH THIS TIME BECAUSE THE SUN HAS TO RISE FIRST + if (setIndex != 4 && !sets[setIndex.Value + 1].HasValue && solarAltitude > -0.8333) + { + sets[setIndex.Value] = null; + } + //IF PREVIOUS DAY IS DOWN ALL DAY SCRATCH AS THIS HAS TO RISE FIRST + else if (setIndex != 0 && !sets[setIndex.Value - 1].HasValue && solarAltitude <= -0.8333) + { + sets[setIndex.Value] = null; + } + } + + } + private static bool datesContainNull(DateTime?[] dates) + { + foreach(var d in dates) + { + if (!d.HasValue) { return true; } + } + return false; + } + + private static int? targetEventIndex(DateTime?[] dates, DateTime target) + { + int x = 0; + foreach(var d in dates) + { + if(d.HasValue && d.Value == target) { return x; } + x++; + } + return null; + } /// /// Iterates stored events and extracts the one that occurs on the target date. /// @@ -527,7 +670,7 @@ private static double approxTransit(double Ht, double lw, double n) private static double GetTime(double h, double lw, double phi, double dec, double n,double M, double L) { double approxTime = hourAngle(h, phi, dec); //Ch15 Formula 15.1 - + double a = approxTransit(approxTime, lw, n); double st = solarTransitJ(a, M, L); diff --git a/CoordinateSharp/CoordinateSharp.csproj b/CoordinateSharp/CoordinateSharp.csproj index 17c9f6ae..367ee328 100644 --- a/CoordinateSharp/CoordinateSharp.csproj +++ b/CoordinateSharp/CoordinateSharp.csproj @@ -50,26 +50,27 @@ Please visit http://coordinatesharp.com/licensing or contact Signature Group, LL net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80 true true - 2.23.1.1 + 2.24.1.1 Signature Group, LLC https://github.com/Tronald/CoordinateSharp Copyright 2024 CoordinateSharp is a high powered, lightweight .NET library that can convert geographical coordinates, perform distance logic, and calculate location based sun, moon, and magnetic information with minimal code. - -Adds the ability to densify polylines to mitigate geofence spherical distortions over long distances. + -Fixes bug causing incorrect sun condition to report in circumpolar regions during slow transition at horizon. +-Adds feature to allow custom specification of earth shape during point densification. Conversion; Latitude; Longitude; Coordinates; Geography; Sun; Moon; Solar; Lunar; Time; MGRS; UTM; EPSG:3857; ECEF; GEOREF; Web Mercator; License.txt CoordinateSharp CoordinateSharp - 2.23.1.1 + 2.24.1.1 true true 128x128.png CoordinateSharp Strong Name.snk false - 2.23.1.1 + 2.24.1.1 https://github.com/Tronald/CoordinateSharp README.md snupkg diff --git a/CoordinateSharp/GeoFence/GeoFence.cs b/CoordinateSharp/GeoFence/GeoFence.cs index 1e41baaa..8a1a4737 100644 --- a/CoordinateSharp/GeoFence/GeoFence.cs +++ b/CoordinateSharp/GeoFence/GeoFence.cs @@ -48,6 +48,7 @@ or shipping CoordinateSharp with a closed source product. using System.Collections.Generic; using System; using System.Linq; +using System.Reflection; namespace CoordinateSharp { @@ -341,7 +342,7 @@ public Distance DistanceFromNearestPolyLine(Coordinate point) /// public void Densify(Distance distance) { - Densify(distance, Shape.Ellipsoid); + Densify(distance, Shape.Ellipsoid, Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.WGS84_1984)); } /// @@ -382,6 +383,52 @@ public void Densify(Distance distance) /// /// public void Densify(Distance distance, Shape shape) + { + Densify(distance, shape, Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.WGS84_1984)); + } + /// + /// Densifies the polygon by adding additional points along each edge at specified intervals using ellipsoidal (Vincenty) logic with a user specified earth shape. + /// + /// The distance between points along the polygon's edges. This distance determines how frequently new points are inserted into the polygon + /// Specify earth ellipsoid shape. + /// + /// This method is particularly useful for large polygons where the curvature of the Earth can cause + /// significant distortion in geographic calculations. By adding more points at regular intervals, + /// the polygon better conforms to the curved surface of the Earth, reducing errors in area calculations, + /// perimeter calculations, and point-in-polygon tests. + /// + /// The function automatically calculates intermediate points based on the great-circle distance between + /// existing vertices, ensuring that the new points adhere to the true geographic shape of the polygon. + /// This is essential for maintaining geographic integrity when performing spatial operations or visualizations. + /// + /// Note: The densification process increases the number of vertices in the polygon, which may impact performance + /// and memory usage in spatial computations and data storage. Optimal use of this function depends on the required + /// precision and the geographic extent of the application. + /// + /// + /// Here is how you might use this function to densify a polygon representing a large geographic area: + /// + /// //Create a four point GeoFence around Utah + /// List<GeoFence.Point> points = new List<GeoFence.Point>(); + /// points.Add(new GeoFence.Point(41.003444, -109.045223)); + /// points.Add(new GeoFence.Point(41.003444, -102.041524)); + /// points.Add(new GeoFence.Point(36.993076, -102.041524)); + /// points.Add(new GeoFence.Point(36.993076, -109.045223)); + /// points.Add(new GeoFence.Point(41.003444, -109.045223)); + /// + /// GeoFence gf = new GeoFence(points); + /// + /// gf.Densify(new Distance(10, DistanceType.Kilometers), Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.GRS67_1967)); + /// + /// //The gf.Points list now contains additional points at intervals of approximately 10 kilometers. + /// + /// + public void Densify(Distance distance, Earth_Ellipsoid ellipsoid) + { + Densify(distance, Shape.Ellipsoid, ellipsoid); + } + + private void Densify(Distance distance, Shape shape, Earth_Ellipsoid ellipsoid) { if (_points.Count < 2) { @@ -402,10 +449,10 @@ public void Densify(Distance distance, Shape shape) List ipoints = new List(); //Coordinate to move - Coordinate mc = new Coordinate(p1.Latitude, p1.Longitude, new EagerLoad(false)); + Coordinate mc = new Coordinate(p1.Latitude, p1.Longitude, new EagerLoad(false), ellipsoid.Equatorial_Radius, ellipsoid.Inverse_Flattening); //Destination - Coordinate dc = new Coordinate(p2.Latitude, p2.Longitude, new EagerLoad(false)); + Coordinate dc = new Coordinate(p2.Latitude, p2.Longitude, new EagerLoad(false), ellipsoid.Equatorial_Radius, ellipsoid.Inverse_Flattening); while (new Distance(mc, dc).Meters > distance.Meters) { @@ -433,6 +480,5 @@ public void Densify(Distance distance, Shape shape) //Add last point to close shape. _points.Add(ogpoints.Last()); } - } } \ No newline at end of file diff --git a/CoordinateSharp_UnitTests/Celestial.Solar.cs b/CoordinateSharp_UnitTests/Celestial.Solar.cs index 4c7352a1..890605fc 100644 --- a/CoordinateSharp_UnitTests/Celestial.Solar.cs +++ b/CoordinateSharp_UnitTests/Celestial.Solar.cs @@ -725,15 +725,58 @@ public void Check_DayNight_Times() Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan); Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan); + //No Set + c = new Coordinate(66.771832, 22.339500, new DateTime(2024, 6, 2)); + c.Offset = 2; + Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan); + Assert.AreEqual(c.CelestialInfo.SunRise.Value.TimeOfDay, c.CelestialInfo.NightSpan); + //No Rise - c = new Coordinate(76, 45, new DateTime(2021, 4, 24)); + c = new Coordinate(78.2232, 15.6469, new DateTime(2024, 10, 26)); + c.Offset = -11; Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan); Assert.AreEqual(c.CelestialInfo.SunSet.Value.TimeOfDay, c.CelestialInfo.DaySpan); + } + [TestMethod] + public void Check_Horizon_Hang_Correction() + { + EagerLoad el = new EagerLoad(EagerLoadType.Celestial); + + //No Rise Reported, Correct to Up All Day + DateTime d = new DateTime(2021, 4, 24, 0, 0, 0); + var c = Celestial.CalculateCelestialTimes(76, 45, d, el, 0); + Assert.AreEqual(c.SunCondition, CelestialStatus.UpAllDay); + + //Next day is up all day, correct to No Set + d = new DateTime(2021, 4, 24, 0, 0, 0); + c = Celestial.CalculateCelestialTimes(76, 45, d, el, 3); + Assert.AreEqual(c.SunCondition, CelestialStatus.NoSet); + + //Ensure up all day + d = new DateTime(2021, 4, 25, 0, 0, 0); + c = Celestial.CalculateCelestialTimes(76, 45, d, el, 3); + Assert.AreEqual(c.SunCondition, CelestialStatus.UpAllDay); + + //No set correct to up all day + d = new DateTime(2024, 6, 4); + c = Celestial.CalculateCelestialTimes(66.771832, 22.339500, d, el, 2); + Assert.AreEqual(c.SunCondition, CelestialStatus.UpAllDay); + + //No rise correct to up all day + d = new DateTime(2024, 7, 9); + c = Celestial.CalculateCelestialTimes(66.771832, 22.339500, d, el, 2); + Assert.AreEqual(c.SunCondition, CelestialStatus.UpAllDay); + + //Correct Up All Day + d = new DateTime(2024, 1, 8); + c = Celestial.CalculateCelestialTimes(-66.771832, 22.339500, d, el, 2); + Assert.AreEqual(c.SunCondition, CelestialStatus.UpAllDay); + + //Strip Set correction + d = new DateTime(2024, 12, 4); + c = Celestial.CalculateCelestialTimes(-66.771832, 22.339500, d, el, 2); + Assert.AreEqual(c.SunCondition, CelestialStatus.NoSet); - //Down all day - c = new Coordinate(-76, 45, new DateTime(2021, 2, 13)); - Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan); - Assert.AreEqual(c.CelestialInfo.SunRise.Value.TimeOfDay, c.CelestialInfo.NightSpan); } } diff --git a/CoordinateSharp_UnitTests/GeoFence.cs b/CoordinateSharp_UnitTests/GeoFence.cs index 5125babd..3cf2ea2e 100644 --- a/CoordinateSharp_UnitTests/GeoFence.cs +++ b/CoordinateSharp_UnitTests/GeoFence.cs @@ -151,10 +151,11 @@ public void Densify() GeoFence ellipseTest = new GeoFence(points); GeoFence sphereTest = new GeoFence(new List(points)); + GeoFence customTest = new GeoFence(new List(points)); - ellipseTest.Densify(new Distance(5, DistanceType.Kilometers)); sphereTest.Densify(new Distance(5, DistanceType.Kilometers), Shape.Sphere); + customTest.Densify(new Distance(5, DistanceType.Kilometers), Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.WGS84_1984)); string[] ellipseTestPoints = File.ReadAllText("GeoFenceData\\ColoradoEllipse.txt").Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string[] sphereTestPoints = File.ReadAllText("GeoFenceData\\ColoradoSphere.txt").Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); @@ -166,6 +167,8 @@ public void Densify() double lng = double.Parse(point[1]); Assert.AreEqual(ellipseTest.Points[x].Latitude, lat, .00000000001); Assert.AreEqual(ellipseTest.Points[x].Longitude, lng, .00000000001); + Assert.AreEqual(customTest.Points[x].Latitude, lat, .00000000001); + Assert.AreEqual(customTest.Points[x].Longitude, lng, .00000000001); } for (int x = 0; x < sphereTestPoints.Length; x++) @@ -176,6 +179,8 @@ public void Densify() Assert.AreEqual(sphereTest.Points[x].Latitude, lat, .00000000001); Assert.AreEqual(sphereTest.Points[x].Longitude, lng, .00000000001); } + + } ///