Skip to content

Commit

Permalink
Features/celestial item factory (#225)
Browse files Browse the repository at this point in the history
* Create Celestial item factory

* Update version
  • Loading branch information
sylvain-guillet authored Nov 15, 2024
1 parent 12dbc43 commit 36ed6b8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FileVersion>0.0.1</FileVersion>
<PackAsTool>true</PackAsTool>
<ToolCommandName>astro</ToolCommandName>
<Version>0.6.2</Version>
<Version>0.6.2.1</Version>
<Title>Astrodynamics command line interface</Title>
<Authors>Sylvain Guillet</Authors>
<Description>This CLI allows end user to exploit IO.Astrodynamics framework </Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ public void CreateFromNaifObject()
Assert.Equal(Frames.Frame.ECLIPTIC_J2000, moon.InitialOrbitalParameters.Frame);
}

// [Fact]
// public void CreateExceptions()
// {
// Assert.Throws<InvalidOperationException>(() => new CelestialBody(-399));
// }

[Fact]
public void FindOccultationsEclipse()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<Barycenter>(result);
}

[Fact]
public void Create_ReturnsLagrangePoint_ForNaifIdBetweenL1AndL5()
{
var result = CelestialItem.Create(391);
Assert.IsType<LagrangePoint>(result);
}

[Fact]
public void Create_ReturnsCelestialBody_ForNaifIdGreaterThan10AndNotLagrangePoint()
{
var result = CelestialItem.Create(199);
Assert.IsType<CelestialBody>(result);
}

[Fact]
public void Create_ReturnsLagrangePoint_WithCorrectName()
{
var result = (LagrangePoint)CelestialItem.Create(392);
Assert.Equal("L2", result.Name);
}
}
16 changes: 16 additions & 0 deletions IO.Astrodynamics.Net/IO.Astrodynamics/Body/CelestialItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<id>IO.Astrodynamics</id>
<authors>Sylvain Guillet</authors>
<copyright>Sylvain Guillet</copyright>
<version>6.1.2</version>
<version>6.2.0</version>
<title>Astrodynamics framework</title>
<icon>images\dragonfly-dark-trans.png</icon>
<readme>docs\README.md</readme>
Expand Down

0 comments on commit 36ed6b8

Please sign in to comment.