From 36ed6b8d40b5081279067af72ee0386e8eb51b85 Mon Sep 17 00:00:00 2001 From: Sylvain Guillet Date: Fri, 15 Nov 2024 21:01:09 +0100 Subject: [PATCH] Features/celestial item factory (#225) * Create Celestial item factory * Update version --- .../IO.Astrodynamics.CLI.csproj | 2 +- .../Body/CelestialBodyTests.cs | 50 +++++++++++-------- .../IO.Astrodynamics/Body/CelestialItem.cs | 16 ++++++ .../IO.Astrodynamics/IO.Astrodynamics.nuspec | 2 +- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/IO.Astrodynamics.Net/IO.Astrodynamics.CLI/IO.Astrodynamics.CLI.csproj b/IO.Astrodynamics.Net/IO.Astrodynamics.CLI/IO.Astrodynamics.CLI.csproj index 0fd32a18..36b9ad97 100644 --- a/IO.Astrodynamics.Net/IO.Astrodynamics.CLI/IO.Astrodynamics.CLI.csproj +++ b/IO.Astrodynamics.Net/IO.Astrodynamics.CLI/IO.Astrodynamics.CLI.csproj @@ -9,7 +9,7 @@ 0.0.1 true astro - 0.6.2 + 0.6.2.1 Astrodynamics command line interface Sylvain Guillet This CLI allows end user to exploit IO.Astrodynamics framework diff --git a/IO.Astrodynamics.Net/IO.Astrodynamics.Tests/Body/CelestialBodyTests.cs b/IO.Astrodynamics.Net/IO.Astrodynamics.Tests/Body/CelestialBodyTests.cs index d8926e15..523dae40 100644 --- a/IO.Astrodynamics.Net/IO.Astrodynamics.Tests/Body/CelestialBodyTests.cs +++ b/IO.Astrodynamics.Net/IO.Astrodynamics.Tests/Body/CelestialBodyTests.cs @@ -70,12 +70,6 @@ public void CreateFromNaifObject() Assert.Equal(Frames.Frame.ECLIPTIC_J2000, moon.InitialOrbitalParameters.Frame); } - // [Fact] - // public void CreateExceptions() - // { - // Assert.Throws(() => new CelestialBody(-399)); - // } - [Fact] public void FindOccultationsEclipse() { @@ -109,22 +103,6 @@ public void FindWindowsOnDistanceConstraint() Assert.Equal(new TimeSystem.Time("2000-03-30T07:01:07.2974489 TDB"), windows.ElementAt(3).EndDate); } - // [Fact] - // public void FindWindowsOnCoordinateConstraint() - // { - // var res = TestHelpers.EarthAtJ2000.FindWindowsOnCoordinateConstraint( - // new Window(new TimeSystem.Time(DateTime.Parse("2005-10-03"), TimeFrame.TDBFrame), new TimeSystem.Time(DateTime.Parse("2005-11-03"), TimeFrame.TDBFrame)), - // TestHelpers.MoonAtJ2000, TestHelpers.MoonAtJ2000.Frame, CoordinateSystem.Latitudinal, Coordinate.Latitude, RelationnalOperator.Greater, 0.0, 0.0, Aberration.None, - // TimeSpan.FromSeconds(60.0)); - // - // var windows = res as Window[] ?? res.ToArray(); - // Assert.Equal(2, windows.Length); - // Assert.Equal("2005-10-03T17:24:29.0992341 TDB", windows[0].StartDate.ToString()); - // Assert.Equal("2005-10-16T17:50:20.7049530 TDB", windows[0].EndDate.ToString()); - // Assert.Equal("2005-10-31T00:27:02.6705884 TDB", windows[1].StartDate.ToString()); - // Assert.Equal("2005-11-03T00:00:00.0000000 TDB", windows[1].EndDate.ToString()); - // } - [Fact] public void AngularSize() { @@ -527,4 +505,32 @@ public void FindCenterOfMotionId_ReturnsTen_ForLagrangePoint394() var celestialItem = new LagrangePoint(LagrangePoints.L4); Assert.Equal(10, celestialItem.CenterOfMotionId); } + + [Fact] + public void Create_ReturnsBarycenter_ForNaifIdLessThan10() + { + var result = CelestialItem.Create(5); + Assert.IsType(result); + } + + [Fact] + public void Create_ReturnsLagrangePoint_ForNaifIdBetweenL1AndL5() + { + var result = CelestialItem.Create(391); + Assert.IsType(result); + } + + [Fact] + public void Create_ReturnsCelestialBody_ForNaifIdGreaterThan10AndNotLagrangePoint() + { + var result = CelestialItem.Create(199); + Assert.IsType(result); + } + + [Fact] + public void Create_ReturnsLagrangePoint_WithCorrectName() + { + var result = (LagrangePoint)CelestialItem.Create(392); + Assert.Equal("L2", result.Name); + } } \ No newline at end of file diff --git a/IO.Astrodynamics.Net/IO.Astrodynamics/Body/CelestialItem.cs b/IO.Astrodynamics.Net/IO.Astrodynamics/Body/CelestialItem.cs index ff3a4d6f..f0eb0741 100644 --- a/IO.Astrodynamics.Net/IO.Astrodynamics/Body/CelestialItem.cs +++ b/IO.Astrodynamics.Net/IO.Astrodynamics/Body/CelestialItem.cs @@ -12,6 +12,7 @@ using IO.Astrodynamics.OrbitalParameters; using IO.Astrodynamics.SolarSystemObjects; using IO.Astrodynamics.TimeSystem; +using MathNet.Numerics.LinearAlgebra; using Window = IO.Astrodynamics.TimeSystem.Window; namespace IO.Astrodynamics.Body; @@ -192,6 +193,21 @@ protected CelestialItem(int naifId, string name, double mass, OrbitalParameters. : new GravitationalField(); } + public static CelestialItem Create(int naifId) + { + if (naifId < 10) + { + return new Barycenter(naifId); + } + + if (LagrangePoints.L1.NaifId <= naifId && naifId <= LagrangePoints.L5.NaifId) + { + return new LagrangePoint(new NaifObject(naifId, $"L{naifId - 390}", null)); + } + + return new CelestialBody(naifId); + } + internal void AddSatellite(CelestialItem celestialItem) { _satellites.Add(celestialItem); diff --git a/IO.Astrodynamics.Net/IO.Astrodynamics/IO.Astrodynamics.nuspec b/IO.Astrodynamics.Net/IO.Astrodynamics/IO.Astrodynamics.nuspec index 7e3c1aae..c45c24e4 100644 --- a/IO.Astrodynamics.Net/IO.Astrodynamics/IO.Astrodynamics.nuspec +++ b/IO.Astrodynamics.Net/IO.Astrodynamics/IO.Astrodynamics.nuspec @@ -4,7 +4,7 @@ IO.Astrodynamics Sylvain Guillet Sylvain Guillet - 6.1.2 + 6.2.0 Astrodynamics framework images\dragonfly-dark-trans.png docs\README.md