Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/code cleanup #39

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [1.0.4] - 2024.04.28

**Changed**

* Code refactoring: compound assignments, explicit types, and removed unnecessary parentheses.
4 changes: 2 additions & 2 deletions PALib.Tests/PACoordinates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void CorrectForPrecession()
[Fact]
public void NutationInEclipticLongitudeAndObliquity()
{
var result = _paCoordinates.NutationInEclipticLongitudeAndObliquity(1, 9, 1988);
(double nutInLongDeg, double nutInOblDeg) result = _paCoordinates.NutationInEclipticLongitudeAndObliquity(1, 9, 1988);

Assert.Equal((0.001525808, 0.0025671), (Math.Round(result.nutInLongDeg, 9), Math.Round(result.nutInOblDeg, 7)));
}
Expand All @@ -119,7 +119,7 @@ public void AtmosphericRefraction()
[Fact]
public void CorrectionsForGeocentricParallax()
{
var result = _paCoordinates.CorrectionsForGeocentricParallax(22, 35, 19, -7, 41, 13, PACoordinateType.True, 1.019167, -100, 50, 60, 0, -6, 26, 2, 1979, 10, 45, 0);
(double correctedRAHour, double correctedRAMin, double correctedRASec, double correctedDecDeg, double correctedDecMin, double correctedDecSec) result = _paCoordinates.CorrectionsForGeocentricParallax(22, 35, 19, -7, 41, 13, PACoordinateType.True, 1.019167, -100, 50, 60, 0, -6, 26, 2, 1979, 10, 45, 0);

Assert.Equal((22, 36, 43.22, -8, 32, 17.4), result);
}
Expand Down
2 changes: 1 addition & 1 deletion PALib/Data/BinaryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static BinaryInfo()
/// <returns></returns>
public static BinaryData GetBinaryInfo(string name)
{
var returnValue = _binaryData
BinaryData returnValue = _binaryData
.Where(x => x.Name == name)
.Select(x => x)
.FirstOrDefault();
Expand Down
4 changes: 2 additions & 2 deletions PALib/Data/CometData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static CometInfoElliptical()
/// </summary>
public static CometDataElliptical GetCometEllipticalInfo(string name)
{
var returnValue = _cometDataElliptical
CometDataElliptical returnValue = _cometDataElliptical
.Where(x => x.Name == name)
.Select(x => x)
.FirstOrDefault();
Expand Down Expand Up @@ -301,7 +301,7 @@ static CometInfoParabolic()
/// </summary>
public static CometDataParabolic GetCometParabolicInfo(string name)
{
var returnValue = _cometDataParabolic
CometDataParabolic returnValue = _cometDataParabolic
.Where(x => x.Name == name)
.Select(x => x)
.FirstOrDefault();
Expand Down
2 changes: 1 addition & 1 deletion PALib/Data/PlanetData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static PlanetInfo()
/// </summary>
public static PlanetData GetPlanetInfo(string name)
{
var returnValue = _planetData
PlanetData returnValue = _planetData
.Where(x => x.Name == name)
.Select(x => x)
.FirstOrDefault();
Expand Down
32 changes: 16 additions & 16 deletions PALib/PABinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ public class PABinary
/// </returns>
public (double positionAngleDeg, double separationArcsec) BinaryStarOrbit(double greenwichDateDay, int greenwichDateMonth, int greenwichDateYear, string binaryName)
{
var binaryInfo = BinaryInfo.GetBinaryInfo(binaryName);
BinaryData binaryInfo = BinaryInfo.GetBinaryInfo(binaryName);

var yYears = (greenwichDateYear + (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191) - binaryInfo.EpochPeri;
var mDeg = 360 * yYears / binaryInfo.Period;
var mRad = (mDeg - 360 * (mDeg / 360).Floor()).ToRadians();
var eccentricity = binaryInfo.Ecc;
var trueAnomalyRad = PAMacros.TrueAnomaly(mRad, eccentricity);
var rArcsec = (1 - eccentricity * (PAMacros.EccentricAnomaly(mRad, eccentricity)).Cosine()) * binaryInfo.Axis;
var taPeriRad = trueAnomalyRad + binaryInfo.LongPeri.ToRadians();
double yYears = greenwichDateYear + (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191 - binaryInfo.EpochPeri;
double mDeg = 360 * yYears / binaryInfo.Period;
double mRad = (mDeg - 360 * (mDeg / 360).Floor()).ToRadians();
double eccentricity = binaryInfo.Ecc;
double trueAnomalyRad = PAMacros.TrueAnomaly(mRad, eccentricity);
double rArcsec = (1 - eccentricity * PAMacros.EccentricAnomaly(mRad, eccentricity).Cosine()) * binaryInfo.Axis;
double taPeriRad = trueAnomalyRad + binaryInfo.LongPeri.ToRadians();

var y = (taPeriRad).Sine() * ((binaryInfo.Incl).ToRadians()).Cosine();
var x = (taPeriRad).Cosine();
var aDeg = PAMacros.Degrees(y.AngleTangent2(x));
var thetaDeg1 = aDeg + binaryInfo.PANode;
var thetaDeg2 = thetaDeg1 - 360 * (thetaDeg1 / 360).Floor();
var rhoArcsec = rArcsec * (taPeriRad).Cosine() / ((thetaDeg2 - binaryInfo.PANode).ToRadians()).Cosine();
double y = taPeriRad.Sine() * binaryInfo.Incl.ToRadians().Cosine();
double x = taPeriRad.Cosine();
double aDeg = PAMacros.Degrees(y.AngleTangent2(x));
double thetaDeg1 = aDeg + binaryInfo.PANode;
double thetaDeg2 = thetaDeg1 - 360 * (thetaDeg1 / 360).Floor();
double rhoArcsec = rArcsec * taPeriRad.Cosine() / (thetaDeg2 - binaryInfo.PANode).ToRadians().Cosine();

var positionAngleDeg = Math.Round(thetaDeg2, 1);
var separationArcsec = Math.Round(rhoArcsec, 2);
double positionAngleDeg = Math.Round(thetaDeg2, 1);
double separationArcsec = Math.Round(rhoArcsec, 2);

return (positionAngleDeg, separationArcsec);
}
Expand Down
122 changes: 61 additions & 61 deletions PALib/PAComet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,48 @@ public class PAComet
/// </returns>
public (double cometRAHour, double cometRAMin, double cometDecDeg, double cometDecMin, double cometDistEarth) PositionOfEllipticalComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName)
{
var daylightSaving = (isDaylightSaving) ? 1 : 0;
int daylightSaving = isDaylightSaving ? 1 : 0;

var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
double greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
int greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
int greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);

var cometInfo = CometInfoElliptical.GetCometEllipticalInfo(cometName);
CometDataElliptical cometInfo = CometInfoElliptical.GetCometEllipticalInfo(cometName);

var timeSinceEpochYears = (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, greenwichDateYear)) / 365.242191 + greenwichDateYear - cometInfo.epoch_EpochOfPerihelion;
var mcDeg = 360 * timeSinceEpochYears / cometInfo.period_PeriodOfOrbit;
var mcRad = (mcDeg - 360 * (mcDeg / 360).Floor()).ToRadians();
var eccentricity = cometInfo.ecc_EccentricityOfOrbit;
var trueAnomalyDeg = PAMacros.Degrees(PAMacros.TrueAnomaly(mcRad, eccentricity));
var lcDeg = trueAnomalyDeg + cometInfo.peri_LongitudeOfPerihelion;
var rAU = cometInfo.axis_SemiMajorAxisOfOrbit * (1 - eccentricity * eccentricity) / (1 + eccentricity * ((trueAnomalyDeg).ToRadians()).Cosine());
var lcNodeRad = (lcDeg - cometInfo.node_LongitudeOfAscendingNode).ToRadians();
var psiRad = ((lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Sine()).ASine();
double timeSinceEpochYears = (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, greenwichDateYear)) / 365.242191 + greenwichDateYear - cometInfo.epoch_EpochOfPerihelion;
double mcDeg = 360 * timeSinceEpochYears / cometInfo.period_PeriodOfOrbit;
double mcRad = (mcDeg - 360 * (mcDeg / 360).Floor()).ToRadians();
double eccentricity = cometInfo.ecc_EccentricityOfOrbit;
double trueAnomalyDeg = PAMacros.Degrees(PAMacros.TrueAnomaly(mcRad, eccentricity));
double lcDeg = trueAnomalyDeg + cometInfo.peri_LongitudeOfPerihelion;
double rAU = cometInfo.axis_SemiMajorAxisOfOrbit * (1 - eccentricity * eccentricity) / (1 + eccentricity * trueAnomalyDeg.ToRadians().Cosine());
double lcNodeRad = (lcDeg - cometInfo.node_LongitudeOfAscendingNode).ToRadians();
double psiRad = (lcNodeRad.Sine() * cometInfo.incl_InclinationOfOrbit.ToRadians().Sine()).ASine();

var y = (lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Cosine();
var x = (lcNodeRad).Cosine();
double y = lcNodeRad.Sine() * cometInfo.incl_InclinationOfOrbit.ToRadians().Cosine();
double x = lcNodeRad.Cosine();

var ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + cometInfo.node_LongitudeOfAscendingNode;
var rdAU = rAU * (psiRad).Cosine();
double ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + cometInfo.node_LongitudeOfAscendingNode;
double rdAU = rAU * psiRad.Cosine();

var earthLongitudeLeDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) + 180.0;
var earthRadiusVectorAU = PAMacros.SunDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
double earthLongitudeLeDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) + 180.0;
double earthRadiusVectorAU = PAMacros.SunDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);

var leLdRad = (earthLongitudeLeDeg - ldDeg).ToRadians();
var aRad = (rdAU < earthRadiusVectorAU) ? (rdAU * (leLdRad).Sine()).AngleTangent2(earthRadiusVectorAU - rdAU * (leLdRad).Cosine()) : (earthRadiusVectorAU * (-leLdRad).Sine()).AngleTangent2(rdAU - earthRadiusVectorAU * (leLdRad).Cosine());
double leLdRad = (earthLongitudeLeDeg - ldDeg).ToRadians();
double aRad = (rdAU < earthRadiusVectorAU) ? (rdAU * leLdRad.Sine()).AngleTangent2(earthRadiusVectorAU - rdAU * leLdRad.Cosine()) : (earthRadiusVectorAU * (-leLdRad).Sine()).AngleTangent2(rdAU - earthRadiusVectorAU * leLdRad.Cosine());

var cometLongDeg1 = (rdAU < earthRadiusVectorAU) ? 180.0 + earthLongitudeLeDeg + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg;
var cometLongDeg = cometLongDeg1 - 360 * (cometLongDeg1 / 360).Floor();
var cometLatDeg = PAMacros.Degrees((rdAU * (psiRad).Tangent() * ((cometLongDeg1 - ldDeg).ToRadians()).Sine() / (earthRadiusVectorAU * (-leLdRad).Sine())).AngleTangent());
var cometRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear));
var cometDecDeg1 = PAMacros.EcDec(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear);
var cometDistanceAU = (Math.Pow(earthRadiusVectorAU, 2) + Math.Pow(rAU, 2) - 2.0 * earthRadiusVectorAU * rAU * ((lcDeg - earthLongitudeLeDeg).ToRadians()).Cosine() * (psiRad).Cosine()).SquareRoot();
double cometLongDeg1 = (rdAU < earthRadiusVectorAU) ? 180.0 + earthLongitudeLeDeg + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg;
double cometLongDeg = cometLongDeg1 - 360 * (cometLongDeg1 / 360).Floor();
double cometLatDeg = PAMacros.Degrees((rdAU * psiRad.Tangent() * (cometLongDeg1 - ldDeg).ToRadians().Sine() / (earthRadiusVectorAU * (-leLdRad).Sine())).AngleTangent());
double cometRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear));
double cometDecDeg1 = PAMacros.EcDec(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear);
double cometDistanceAU = (Math.Pow(earthRadiusVectorAU, 2) + Math.Pow(rAU, 2) - 2.0 * earthRadiusVectorAU * rAU * (lcDeg - earthLongitudeLeDeg).ToRadians().Cosine() * psiRad.Cosine()).SquareRoot();

var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours1 + 0.008333);
var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours1 + 0.008333);
var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1 + 0.008333);
var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1 + 0.008333);
var cometDistEarth = Math.Round(cometDistanceAU, 2);
int cometRAHour = PAMacros.DecimalHoursHour(cometRAHours1 + 0.008333);
int cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours1 + 0.008333);
double cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1 + 0.008333);
double cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1 + 0.008333);
double cometDistEarth = Math.Round(cometDistanceAU, 2);

return (cometRAHour, cometRAMin, cometDecDeg, cometDecMin, cometDistEarth);
}
Expand All @@ -82,34 +82,34 @@ public class PAComet
/// <returns></returns>
public (double cometRAHour, double cometRAMin, double cometRASec, double cometDecDeg, double cometDecMin, double cometDecSec, double cometDistEarth) PositionOfParabolicComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName)
{
var daylightSaving = (isDaylightSaving) ? 1 : 0;

var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);

var cometInfo = CometInfoParabolic.GetCometParabolicInfo(cometName);

var perihelionEpochDay = cometInfo.EpochPeriDay;
var perihelionEpochMonth = cometInfo.EpochPeriMonth;
var perihelionEpochYear = cometInfo.EpochPeriYear;
var qAU = cometInfo.PeriDist;
var inclinationDeg = cometInfo.Incl;
var perihelionDeg = cometInfo.ArgPeri;
var nodeDeg = cometInfo.Node;

var cometLongLatDist = PAMacros.PCometLongLatDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, perihelionEpochDay, perihelionEpochMonth, perihelionEpochYear, qAU, inclinationDeg, perihelionDeg, nodeDeg);

var cometRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear));
var cometDecDeg1 = PAMacros.EcDec(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear);

var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours);
var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours);
var cometRASec = PAMacros.DecimalHoursSecond(cometRAHours);
var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1);
var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1);
var cometDecSec = PAMacros.DecimalDegreesSeconds(cometDecDeg1);
var cometDistEarth = Math.Round(cometLongLatDist.cometDistAU, 2);
int daylightSaving = isDaylightSaving ? 1 : 0;

double greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
int greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
int greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);

CometDataParabolic cometInfo = CometInfoParabolic.GetCometParabolicInfo(cometName);

double perihelionEpochDay = cometInfo.EpochPeriDay;
int perihelionEpochMonth = cometInfo.EpochPeriMonth;
int perihelionEpochYear = cometInfo.EpochPeriYear;
double qAU = cometInfo.PeriDist;
double inclinationDeg = cometInfo.Incl;
double perihelionDeg = cometInfo.ArgPeri;
double nodeDeg = cometInfo.Node;

(double cometLongDeg, double cometLatDeg, double cometDistAU) cometLongLatDist = PAMacros.PCometLongLatDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, perihelionEpochDay, perihelionEpochMonth, perihelionEpochYear, qAU, inclinationDeg, perihelionDeg, nodeDeg);

double cometRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear));
double cometDecDeg1 = PAMacros.EcDec(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear);

int cometRAHour = PAMacros.DecimalHoursHour(cometRAHours);
int cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours);
double cometRASec = PAMacros.DecimalHoursSecond(cometRAHours);
double cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1);
double cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1);
double cometDecSec = PAMacros.DecimalDegreesSeconds(cometDecDeg1);
double cometDistEarth = Math.Round(cometLongLatDist.cometDistAU, 2);

return (cometRAHour, cometRAMin, cometRASec, cometDecDeg, cometDecMin, cometDecSec, cometDistEarth);
}
Expand Down
Loading
Loading