Skip to content

Commit

Permalink
Merge pull request #233 from Tronald/develop
Browse files Browse the repository at this point in the history
2.22.1.1
  • Loading branch information
Tronald authored Feb 20, 2024
2 parents ef8382c + f703110 commit 0e93934
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 33 deletions.
9 changes: 4 additions & 5 deletions CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@ For more information, please contact Signature Group, LLC at this address: sales
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.1.11.0</Version>
<Version>1.1.12.0</Version>
<Authors>Signature Group, LLC</Authors>
<Company />
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<Copyright>Copyright 2023</Copyright>
<Copyright>Copyright 2024</Copyright>
<Description>CoordinateSharp magnetic data extensions.</Description>
<PackageReleaseNotes>-Adds NET 8.0 support.
-Maps to latest CoordinateSharp version.</PackageReleaseNotes>
<PackageReleaseNotes>-Maps to latest CoordinateSharp version.</PackageReleaseNotes>
<PackageTags>CoordinateSharp Latitude Longitude Coordinates Geography Magnetic Declination</PackageTags>
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
<PackageLicenseFile>License.txt</PackageLicenseFile>
<PackageIconUrl></PackageIconUrl>
<PackageId>CoordinateSharp.Magnetic</PackageId>
<Title>CoordinateSharp.Magnetic</Title>
<AssemblyVersion>1.1.11.0</AssemblyVersion>
<AssemblyVersion>1.1.12.0</AssemblyVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<SignAssembly>true</SignAssembly>
<PackageIcon>128x128.png</PackageIcon>
Expand Down
13 changes: 13 additions & 0 deletions CoordinateSharp/Celestial/Celestial.Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public partial class Celestial
internal DateTime? moonSet;
internal DateTime? moonRise;

internal TimeSpan daySpan;
internal TimeSpan nightSpan;

internal DateTime? solarNoon;

internal double sunAltitude;
Expand Down Expand Up @@ -195,6 +198,16 @@ public partial class Celestial
/// Sun azimuth in degrees (E of N).
/// </summary>
public double SunAzimuth { get { return sunAzimuth; } }

/// <summary>
/// Daylight time span for date and location.
/// </summary>
public TimeSpan DaySpan { get { return daySpan; } }
/// <summary>
/// Night time span for date and location.
/// </summary>
public TimeSpan NightSpan { get { return nightSpan; } }

/// <summary>
/// Moon altitude in degrees (E of N) (corrected for parallax and refraction).
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions CoordinateSharp/Celestial/Celestial.StaticMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ public static Solstices Get_Solstices(DateTime d)
public static Solstices Get_Solstices(DateTime d, double offset)
{
Celestial c = new Celestial();
SunCalc.Calculate_Soltices_Equinoxes(d, c, offset);
SunCalc.Calculate_Solstices_Equinoxes(d, c, offset);
return c.Solstices;
}

Expand All @@ -1069,7 +1069,7 @@ public static Equinoxes Get_Equinoxes(DateTime d)
public static Equinoxes Get_Equinoxes(DateTime d, double offset)
{
Celestial c = new Celestial();
SunCalc.Calculate_Soltices_Equinoxes(d, c, offset);
SunCalc.Calculate_Solstices_Equinoxes(d, c, offset);
return c.Equinoxes;
}

Expand Down
74 changes: 61 additions & 13 deletions CoordinateSharp/Celestial/Solar/SunCalculations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace CoordinateSharp
{
internal class SunCalc
{
public static void CalculateSunTime(double lat, double longi, DateTime date, Celestial c, EagerLoad el, double offset)
public static void CalculateSunTime(double lat, double lng, DateTime date, Celestial c, EagerLoad el, double offset)
{

if (date.Year == 0001) { return; } //Return if date value hasn't been established.
Expand All @@ -61,7 +61,7 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
////Sun Time Calculations
//Get solar coordinate info and feed
//Get Julian
double lw = rad * -longi;
double lw = rad * -lng;
double phi = rad * lat;

//Rise Set
Expand All @@ -77,17 +77,18 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
var celC = Get_Solar_Coordinates(date, -offset);
c.solarCoordinates = celC;
//Azimuth and Altitude
CalculateSunAngle(date.AddHours(-offset), longi, lat, c, celC); //SUBTRACT OFFSET TO CALC IN Z TIME AND ADJUST SUN ANGLE DURING LOCAL CALCULATIONS.
CalculateSunAngle(date.AddHours(-offset), lng, lat, c, celC); //SUBTRACT OFFSET TO CALC IN Z TIME AND ADJUST SUN ANGLE DURING LOCAL CALCULATIONS.
// neither sunrise nor sunset
if ((!c.SunRise.HasValue) && (!c.SunSet.HasValue))
{
if (c.SunAltitude < 0)
{
c.sunCondition = CelestialStatus.DownAllDay;

}
else
{
c.sunCondition = CelestialStatus.UpAllDay;
c.sunCondition = CelestialStatus.UpAllDay;
}
}
// sunrise or sunset
Expand All @@ -104,7 +105,15 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
// No sunset this date
c.sunCondition = CelestialStatus.NoSet;
}
else
{

}
}

//Sat day and night time spans within 24 hours period
Set_DayNightSpan(c);

//Additional Times
c.additionalSolarTimes = new AdditionalSolarTimes();
//Dusk and Dawn
Expand All @@ -128,10 +137,13 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
//BottomDisc
evDate = Get_Event_Time(lw, phi, -.2998, actualDate, offset, false);
c.AdditionalSolarTimes.sunriseBottomDisc = evDate[0];
c.AdditionalSolarTimes.sunsetBottomDisc = evDate[1];
c.AdditionalSolarTimes.sunsetBottomDisc = evDate[1];

//Day Night Span

}
if (el.Extensions.Solstice_Equinox){ Calculate_Soltices_Equinoxes(date, c, offset); }
if (el.Extensions.Solar_Eclipse) { CalculateSolarEclipse(date, lat, longi, c); }
if (el.Extensions.Solstice_Equinox){ Calculate_Solstices_Equinoxes(date, c, offset); }
if (el.Extensions.Solar_Eclipse) { CalculateSolarEclipse(date, lat, lng, c); }
}
/// <summary>
/// Gets time of event based on specified degree below specified altitude
Expand Down Expand Up @@ -224,7 +236,43 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
}
return target;
}

private static void Set_DayNightSpan(Celestial c)
{
if(c.sunCondition == CelestialStatus.RiseAndSet)
{
//Need to handle set before rise for UTC and timezone adjustments.
if(c.sunSet>c.SunRise)
{
c.daySpan= c.sunSet.Value.TimeOfDay - c.SunRise.Value.TimeOfDay;
c.nightSpan = new TimeSpan(24, 0, 0) - c.daySpan;
}
else
{
c.nightSpan = c.sunRise.Value.TimeOfDay - c.SunSet.Value.TimeOfDay;
c.daySpan = new TimeSpan(24, 0, 0) - c.nightSpan;
}
}
else if(c.sunCondition == CelestialStatus.DownAllDay)
{
c.nightSpan= new TimeSpan(24, 0, 0);
c.daySpan = new TimeSpan(0);
}
else if(c.sunCondition == CelestialStatus.UpAllDay)
{
c.daySpan = new TimeSpan(24, 0, 0);
c.nightSpan = new TimeSpan(0);
}
else if(c.sunCondition == CelestialStatus.NoRise)
{
c.nightSpan = new TimeSpan(24, 0, 0) - c.sunSet.Value.TimeOfDay;
c.daySpan = c.sunSet.Value.TimeOfDay;
}
else if(c.sunCondition == CelestialStatus.NoSet)
{
c.daySpan= new TimeSpan(24, 0, 0) - c.sunRise.Value.TimeOfDay;
c.nightSpan = c.sunRise.Value.TimeOfDay;
}
}
public static void CalculateZodiacSign(DateTime date, Celestial c)
{
//Aquarius (January 20 to February 18)
Expand Down Expand Up @@ -304,11 +352,11 @@ public static void CalculateZodiacSign(DateTime date, Celestial c)
return;
}
}
public static void CalculateSolarEclipse(DateTime date, double lat, double longi, Celestial c)
public static void CalculateSolarEclipse(DateTime date, double lat, double lng, Celestial c)
{
//Convert to Radian
double latR = lat * Math.PI / 180;
double longR = longi * Math.PI / 180;
double longR = lng * Math.PI / 180;
List<List<string>> se = SolarEclipseCalc.CalculateSolarEclipse(date, latR, longR);
//RETURN FIRST AND LAST
if (se.Count == 0) { return; }
Expand Down Expand Up @@ -338,7 +386,7 @@ public static void CalculateSolarEclipse(DateTime date, double lat, double longi
}
}

public static void Calculate_Soltices_Equinoxes(DateTime d, Celestial c, double offset)
public static void Calculate_Solstices_Equinoxes(DateTime d, Celestial c, double offset)
{
double springEquinoxJDE;
double fallEquinoxJDE;
Expand Down Expand Up @@ -504,12 +552,12 @@ private static void CalculateSunAngle(DateTime date, double longi, double lat, C
c.sunAzimuth = ang[0];
c.sunAltitude = ang[1];
}
public static double[] CalculateSunAngle(DateTime date, double longi, double lat, SolarCoordinates solC)
public static double[] CalculateSunAngle(DateTime date, double lng, double lat, SolarCoordinates solC)
{
TimeSpan ts = date - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
double dms = (ts.TotalMilliseconds / dayMS - .5 + j1970) - j2000;

double lw = rad * -longi;
double lw = rad * -lng;
double phi = rad * lat;
double e = rad * 23.4397;

Expand Down
13 changes: 5 additions & 8 deletions CoordinateSharp/CoordinateSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,26 @@ Please visit http://coordinatesharp.com/licensing or contact Signature Group, LL
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.21.1.1</Version>
<Version>2.22.1.1</Version>
<Authors>Signature Group, LLC</Authors>
<Company />
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<Copyright>Copyright 2023</Copyright>
<Copyright>Copyright 2024</Copyright>
<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>
<PackageReleaseNotes>-Adds accessible Magnitude and Coverage property values to the SolarEclipseDetails class.
-Adds accessible Penumbral and Umbral Magnitude property values to the LunarEclipseDetails class.
-Add NET 8.0 support.
-Adds correctly named 'PartialEclipseEnd' property to 'SolarEclipseDetails' and deprecates incorrectly named property.</PackageReleaseNotes>
<PackageReleaseNotes>-Adds Day and Night TimeSpan properties to the CelestialInfo class for easier calculation of total day and night hours for a date at a specified location.</PackageReleaseNotes>
<PackageTags>Conversion; Latitude; Longitude; Coordinates; Geography; Sun; Moon; Solar; Lunar; Time; MGRS; UTM; EPSG:3857; ECEF; GEOREF; Web Mercator;</PackageTags>
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
<PackageLicenseFile>License.txt</PackageLicenseFile> <PackageIconUrl></PackageIconUrl>
<PackageId>CoordinateSharp</PackageId>
<Title>CoordinateSharp</Title>
<AssemblyVersion>2.21.1.1</AssemblyVersion>
<AssemblyVersion>2.22.1.1</AssemblyVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<SignAssembly>true</SignAssembly>
<PackageIcon>128x128.png</PackageIcon>
<AssemblyOriginatorKeyFile>CoordinateSharp Strong Name.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<FileVersion>2.21.1.1</FileVersion>
<FileVersion>2.22.1.1</FileVersion>
<RepositoryUrl>https://github.com/Tronald/CoordinateSharp</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
63 changes: 58 additions & 5 deletions CoordinateSharp_UnitTests/Celestial.Solar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
// Ignore Spelling: Azs Astro

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using CoordinateSharp;
using System.Reflection;
Expand Down Expand Up @@ -82,7 +84,7 @@ public CelestialSolar()
//THESE OBJECT ARE TESTED AGAINST SERIALIZED OBJECTS.
//IF CHANGING THE MODEL YOU WILL HAVE TO CHANGE THE OBJECTS THEY ARE TESTED AGAINST AS WELL

data.SolarEclispe = c.CelestialInfo.SolarEclipse;
data.SolarEclipse = c.CelestialInfo.SolarEclipse;

}
/// <summary>
Expand Down Expand Up @@ -181,8 +183,8 @@ public void SolarEclipses()
SolarEclipse ev = c.CelestialInfo.SolarEclipse;
SolarEclipseDetails lE1 = ev.LastEclipse;
SolarEclipseDetails nE1 = ev.NextEclipse;
SolarEclipseDetails lE2 = data.SolarEclispe.LastEclipse;
SolarEclipseDetails nE2 = data.SolarEclispe.NextEclipse;
SolarEclipseDetails lE2 = data.SolarEclipse.LastEclipse;
SolarEclipseDetails nE2 = data.SolarEclipse.NextEclipse;

PropertyInfo[] properties = typeof(SolarEclipseDetails).GetProperties();
foreach (PropertyInfo property in properties)
Expand Down Expand Up @@ -682,6 +684,57 @@ public void Solar_Coordinate_Accuracy_Local_Time_Check()
Assert.AreEqual(lcZ.SubsolarLongitude, lcL.SubsolarLongitude, .0001, "Subsolar Longitude");
Assert.AreEqual(lcZ.RightAscension, lcL.RightAscension, .0000001, "Right Ascension");
}
/// <summary>
/// Ensures day and night time spans are calculating correctly
/// </summary>
[TestMethod]
public void Check_DayNight_Times()
{
//Rise and set at Z
Coordinate c = new Coordinate(45, 112, new DateTime(2024, 9, 30));
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);

//Rise and set at local
Coordinate c2 = new Coordinate(45, 112, new DateTime(2024, 9, 30));
for (int i = -12; i <=14; i++)
{
c2.Offset = i;
Assert.AreEqual(c.CelestialInfo.DaySpan.TotalMinutes, c2.CelestialInfo.DaySpan.TotalMinutes ,3.2); //3.2 minute delta accounts for day shift. Still accurate as long as sum of span = 24hrs
Assert.AreEqual(new TimeSpan(24, 0, 0), c2.CelestialInfo.DaySpan + c2.CelestialInfo.NightSpan);
Assert.AreEqual(new TimeSpan(11, 45, 0).TotalMinutes, c2.CelestialInfo.DaySpan.TotalMinutes, 3.8); //3.8 minute delta accounts for local day shift. Still accurate as long as sum of span = 24hrs
Assert.AreEqual(new TimeSpan(12, 15, 0).TotalMinutes, c2.CelestialInfo.NightSpan.TotalMinutes, 3.8); //3.8 minute delta accounts for local day shift. Still accurate as long as sum of span = 24hrs
if (c2.CelestialInfo.SunRise < c2.CelestialInfo.SunSet)
{
Assert.AreEqual(c2.CelestialInfo.DaySpan, c2.CelestialInfo.SunSet - c2.CelestialInfo.SunRise); //Checks timespan is calculating correctly
}
else
{

Assert.AreEqual(c2.CelestialInfo.NightSpan, c2.CelestialInfo.SunRise - c2.CelestialInfo.SunSet); //Checks timespan is calculating correctly
}
}


//Up all day
c = new Coordinate(89, 112, new DateTime(2024, 12, 12));
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
Assert.AreEqual(new TimeSpan(0, 0, 0), c.CelestialInfo.DaySpan);

//Down all day
c = new Coordinate(89, 112, new DateTime(2024, 6, 21));
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan);

//No Rise
c = new Coordinate(76, 45, new DateTime(2021, 4, 24));
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
Assert.AreEqual(c.CelestialInfo.SunSet.Value.TimeOfDay, c.CelestialInfo.DaySpan);

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


Expand All @@ -703,7 +756,7 @@ public class Solar_Data
public List<double> SunAlts { get; set; }
public List<double> SunAzs { get; set; }

public SolarEclipse SolarEclispe { get; set; }
public SolarEclipse SolarEclipse { get; set; }

public List<bool> IsSunUp { get; set; }

Expand Down

0 comments on commit 0e93934

Please sign in to comment.