Skip to content

Commit ffd8e5c

Browse files
authored
Merge pull request #224 from Tronald/develop
2.19.1.1
2 parents 4e0d483 + 29da8af commit ffd8e5c

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed

CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For more information, please contact Signature Group, LLC at this address: sales
4747
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70</TargetFrameworks>
4848
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4949
<GenerateDocumentationFile>true</GenerateDocumentationFile>
50-
<Version>1.1.8.0</Version>
50+
<Version>1.1.9.0</Version>
5151
<Authors>Signature Group, LLC</Authors>
5252
<Company />
5353
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
@@ -61,7 +61,7 @@ For more information, please contact Signature Group, LLC at this address: sales
6161
<PackageIconUrl></PackageIconUrl>
6262
<PackageId>CoordinateSharp.Magnetic</PackageId>
6363
<Title>CoordinateSharp.Magnetic</Title>
64-
<AssemblyVersion>1.1.7.0</AssemblyVersion>
64+
<AssemblyVersion>1.1.9.0</AssemblyVersion>
6565
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
6666
<SignAssembly>true</SignAssembly>
6767
<PackageIcon>128x128.png</PackageIcon>

CoordinateSharp/Celestial/Celestial.Coordinates.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace CoordinateSharp
5454
public class SolarCoordinates
5555
{
5656
//Test Against https://www.timeanddate.com/worldclock/sunearth.html
57+
5758
internal double trueLongitude;
5859
internal double trueLatitude;
5960
internal double julianDayDecimal;
@@ -64,7 +65,7 @@ public class SolarCoordinates
6465
internal double rightAscension;
6566
internal double declination;
6667
internal double geometricMeanLongitude;
67-
68+
internal double obliquityOfEcliptic;
6869

6970
/// <summary>
7071
/// Radius Vector (expressed in astronomical units).
@@ -96,6 +97,11 @@ public class SolarCoordinates
9697
/// </summary>
9798
public double GeometricMeanLongitude { get { return geometricMeanLongitude; } }
9899

100+
/// <summary>
101+
/// Obliquity of the Ecliptic
102+
/// </summary>
103+
public double ObliquityOfEcliptic { get { return obliquityOfEcliptic; } }
104+
99105
/// <summary>
100106
/// Subsolar Latitude. The point at which the sun is perceived to be directly overhead of the Earth (at the zenith).
101107
/// </summary>

CoordinateSharp/Celestial/Solar/SunCalculations.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public static SolarCoordinates Get_Solar_Coordinates(DateTime d, double offset)
433433

434434
double tdec = Math.Asin(Math.Sin(E.ToRadians()) * Math.Sin(trueLongitude.ToRadians())); //25.7 True declination. Asin used in liu of sin.
435435

436-
double CE = E + .00256 * Math.Cos(ascendingNode.ToRadians());//22.2 Obliquity of the ecliptic
436+
double CE = E + .00256 * Math.Cos(ascendingNode.ToRadians());//25.6 & 25.7 Apparent position of the sun.
437437

438438
double ara = Math.Atan2(Math.Cos(CE.ToRadians()) * Math.Sin(apparentLongitude.ToRadians()), Math.Cos(apparentLongitude.ToRadians())); //25.8 Apparent Right Ascensions. Using Atan2 we can move tan to the right side of the function with Numerator, Denominator
439439
double adec = Math.Asin(Math.Sin(CE.ToRadians()) * Math.Sin(apparentLongitude.ToRadians())); //25.8 Apparent declination. Asin used in liu of sin.
@@ -443,14 +443,16 @@ public static SolarCoordinates Get_Solar_Coordinates(DateTime d, double offset)
443443
//Set to degrees
444444
//celC.trueRightAscension = tra.ToDegrees();
445445
//celC.trueDeclination = tdec.ToDegrees();
446+
var tr = tra.ToDegrees().NormalizeDegrees360();
446447
celC.rightAscension = ara.ToDegrees().NormalizeDegrees360();
447448
celC.declination = adec.ToDegrees();
448449
celC.julianDayDecimal = JD-.5 - Math.Floor(JD-.5);
449450
celC.trueLongitude = trueLongitude.NormalizeDegrees360();
450451
celC.longitude = apparentLongitude.NormalizeDegrees360();
451452
celC.radiusVector = R;
452453
celC.geometricMeanLongitude = L0.NormalizeDegrees360();
453-
//Latitude is always 0 for sun as perturbations no accounted for in low accuracy formulas
454+
celC.obliquityOfEcliptic = E.NormalizeDegrees360();
455+
//Latitude is always 0 for sun as perturbations not accounted for in low accuracy formulas
454456
celC.latitude = 0;
455457
celC.trueLatitude = 0;
456458

CoordinateSharp/CoordinateSharp.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,27 @@ Please visit http://coordinatesharp.com/licensing or contact Signature Group, LL
5050
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70</TargetFrameworks>
5151
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5252
<GenerateDocumentationFile>true</GenerateDocumentationFile>
53-
<Version>2.18.1.1</Version>
53+
<Version>2.19.1.1</Version>
5454
<Authors>Signature Group, LLC</Authors>
5555
<Company />
5656
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
5757
<PackageLicenseUrl></PackageLicenseUrl>
5858
<Copyright>Copyright 2023</Copyright>
5959
<Description>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.</Description>
60-
<PackageReleaseNotes>-Improves UTM and MGRS conversion efficiency by 13x.
61-
-Adds ability create geofence from a specified GEOREF coordinate and precision level.
62-
-Adds ability to locate GEOREF box corners based on a given precision level.
63-
-Restricts GEOREF easting and northing minutes and seconds to 59.999... to comply with library standards.</PackageReleaseNotes>
60+
<PackageReleaseNotes>-Fixes "Leap Year Bug" impacting celestial calculations and Julian date conversions prior to 1582 (pre-Gregorian).
61+
-Exposes the Obliquity of Ecliptic value within the SolarCoordinate class.</PackageReleaseNotes>
6462
<PackageTags>Conversion; Latitude; Longitude; Coordinates; Geography; Sun; Moon; Solar; Lunar; Time; MGRS; UTM; EPSG:3857; ECEF; GEOREF; Web Mercator;</PackageTags>
6563
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
6664
<PackageLicenseFile>License.txt</PackageLicenseFile> <PackageIconUrl></PackageIconUrl>
6765
<PackageId>CoordinateSharp</PackageId>
6866
<Title>CoordinateSharp</Title>
69-
<AssemblyVersion>2.17.1.1</AssemblyVersion>
67+
<AssemblyVersion>2.19.1.1</AssemblyVersion>
7068
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
7169
<SignAssembly>true</SignAssembly>
7270
<PackageIcon>128x128.png</PackageIcon>
7371
<AssemblyOriginatorKeyFile>CoordinateSharp Strong Name.snk</AssemblyOriginatorKeyFile>
7472
<DelaySign>false</DelaySign>
75-
<FileVersion>2.17.1.1</FileVersion>
73+
<FileVersion>2.19.1.1</FileVersion>
7674
<RepositoryUrl>https://github.com/Tronald/CoordinateSharp</RepositoryUrl>
7775
<PackageReadmeFile>README.md</PackageReadmeFile>
7876
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

CoordinateSharp/Julian/Julian.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ or shipping CoordinateSharp with a closed source product.
4343
Please visit http://coordinatesharp.com/licensing or contact Signature Group, LLC to purchase a commercial license, or for any questions regarding the AGPL 3.0 license requirements or free use license: sales@signatgroup.com.
4444
*/
4545
using System;
46+
using System.Diagnostics;
47+
4648
namespace CoordinateSharp
4749
{
4850
/// <summary>
@@ -125,6 +127,10 @@ public static double GetJulian_Epoch1970(DateTime d)
125127
/// Returns date from Julian
126128
/// Meeus ch. 7
127129
/// </summary>
130+
/// <remarks>
131+
/// The Gregorian calendar (started in 1582) contains different leap year rules than the Julian calendar. To avoid exceptions, any invalid pre-1582 Gregorian leap year conversions of
132+
/// February 29th will shift to March 1st. As such you may see two consecutive Julian to Gregorian conversions produce a date of March 1st on rare occasions.
133+
/// </remarks>
128134
/// <param name="j">Julian date</param>
129135
/// <returns>DateTime</returns>
130136
/// <example>
@@ -136,7 +142,7 @@ public static double GetJulian_Epoch1970(DateTime d)
136142
/// </example>
137143
public static DateTime? GetDate_FromJulian(double j)
138144
{
139-
if (Double.IsNaN(j)) { return null; } //No Event Occured
145+
if (Double.IsNaN(j)) { return null; } //No Event Occurred
140146

141147
j = j + .5;
142148
double Z = Math.Floor(j);
@@ -176,13 +182,30 @@ public static double GetJulian_Epoch1970(DateTime d)
176182
hours = Math.Floor(hours);
177183
minutes = Math.Floor(minutes);
178184

185+
//Leap year safety check due to differences in Julian and Gregorian calendars.
186+
//This limitation of CoordinateSharp is documented. Safety check implemented to prevent breakage.
187+
if (month == 2 && day == 29)
188+
{
189+
if (year / 100 == (int)(year / 100) && year / 400 != (int)(year / 400))
190+
{
191+
Debug.WriteLine($"CAUTION: Julian date {j} does not exist on the Gregorian calendar (29-FEB-{year}). Shifting to next Gregorian day (1-MAR-{year}).");
192+
month++;
193+
day = 1;
194+
195+
}
196+
}
197+
179198
DateTime? date = new DateTime?(new DateTime((int)year, (int)month, (int)day, (int)hours, (int)minutes, (int)seconds));
180199
return date;
181200
}
182201
/// <summary>
183202
/// Returns date from Julian based on epoch 2000
184203
/// Meeus ch. 7
185204
/// </summary>
205+
/// <remarks>
206+
/// The Gregorian calendar (started in 1582) contains different leap year rules than the Julian calendar. To avoid exceptions, any invalid pre-1582 Gregorian leap year conversions of
207+
/// February 29th will shift to March 1st. As such you may see two consecutive Julian to Gregorian conversions produce a date of March 1st on rare occasions.
208+
/// </remarks>
186209
/// <param name="j">Julian date (epoch 2000)</param>
187210
/// <returns>DateTime</returns>
188211
/// <example>
@@ -200,6 +223,10 @@ public static double GetJulian_Epoch1970(DateTime d)
200223
/// Returns date from Julian based on epoch 1970
201224
/// Meeus ch. 7
202225
/// </summary>
226+
/// <remarks>
227+
/// The Gregorian calendar (started in 1582) contains different leap year rules than the Julian calendar. To avoid exceptions, any invalid pre-1582 Gregorian leap year conversions of
228+
/// February 29th will shift to March 1st. As such you may see two consecutive Julian to Gregorian conversions produce a date of March 1st on rare occasions.
229+
/// </remarks>
203230
/// <param name="j">Julian date (epoch 1970)</param>
204231
/// <returns>DateTime</returns>
205232
/// <example>

CoordinateSharp_UnitTests/Formatters.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.IO;
77
using System.Runtime.Serialization.Formatters.Binary;
88
using System.Threading;
9+
using NuGet.Frameworks;
10+
911
namespace CoordinateSharp_UnitTests
1012
{
1113
[TestClass]
@@ -116,6 +118,24 @@ public void Normalize360()
116118
Assert.AreEqual(201.80720, Format.NormalizeDegrees360(signed),.000000001);
117119
}
118120

121+
[TestMethod]
122+
public void JulianLeapYearSafetyCheck()
123+
{
124+
//Ensure no throws due to calendar differences
125+
JulianConversions.GetDate_FromJulian(1757641.5);
126+
127+
for (int x = 100; x < 2400; x += 100)
128+
{
129+
Celestial.CalculateCelestialTimes(39, -72, new DateTime(x, 2, 26));
130+
Celestial.CalculateCelestialTimes(39, -72, new DateTime(x, 4, 21, 10, 10, 12));
131+
}
132+
133+
134+
135+
}
136+
137+
138+
119139
/// <summary>
120140
/// Ensures Coordinate and serialize in binary and deserialze properly
121141
/// </summary>

0 commit comments

Comments
 (0)