Skip to content
Snippets Groups Projects
Commit 11b9ff81 authored by Kristin's avatar Kristin Committed by Jesse Mapel
Browse files

Adds a "convenience constructor" to States (#362)

* Update format of range conversion coefficients isd output to include a separate list for times. Also update driver, test data, and remove unneeded semicolons

* Fix documentaion error

* fix other documentation error

* Added convenience constructor for states

* Remove comments
parent a5e6c480
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,9 @@ namespace ale { ...@@ -45,6 +45,9 @@ namespace ale {
States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions, States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions,
int refFrame=1); int refFrame=1);
States(const std::vector<double>& ephemTimes, const std::vector<std::vector<double>>& positions,
int refFrame=1);
States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions, States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions,
const std::vector<Vec3d>& velocities, int refFrame=1); const std::vector<Vec3d>& velocities, int refFrame=1);
......
...@@ -18,7 +18,6 @@ namespace ale { ...@@ -18,7 +18,6 @@ namespace ale {
int refFrame) : int refFrame) :
m_ephemTimes(ephemTimes), m_refFrame(refFrame) { m_ephemTimes(ephemTimes), m_refFrame(refFrame) {
// Construct State vector from position and velocity vectors // Construct State vector from position and velocity vectors
if (positions.size() != ephemTimes.size()) { if (positions.size() != ephemTimes.size()) {
throw std::invalid_argument("Length of times must match number of positions"); throw std::invalid_argument("Length of times must match number of positions");
} }
...@@ -28,6 +27,19 @@ namespace ale { ...@@ -28,6 +27,19 @@ namespace ale {
} }
} }
States::States(const std::vector<double>& ephemTimes, const std::vector<std::vector<double>>& positions,
int refFrame) :
m_ephemTimes(ephemTimes), m_refFrame(refFrame) {
// Construct State vector from position and velocity vectors
if (positions.size() != ephemTimes.size()) {
throw std::invalid_argument("Length of times must match number of positions");
}
for (Vec3d position : positions) {
m_states.push_back(State(position));
}
}
States::States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions, States::States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions,
const std::vector<Vec3d>& velocities, int refFrame) : const std::vector<Vec3d>& velocities, int refFrame) :
......
...@@ -35,6 +35,23 @@ TEST(StatesTest, ConstructorPositionNoVelocity) { ...@@ -35,6 +35,23 @@ TEST(StatesTest, ConstructorPositionNoVelocity) {
EXPECT_FALSE(noVelocityState.hasVelocity()); EXPECT_FALSE(noVelocityState.hasVelocity());
} }
TEST(StatesTest, ConstructorPositionNoVelocityStdVector) {
std::vector<double> ephemTimes = {0.0, 1.0};
std::vector<double> position = {4.0, 1.0, 4.0};
std::vector<std::vector<double>> positions = {position, position};
States noVelocityState(ephemTimes, positions);
vector<State> states = noVelocityState.getStates();
EXPECT_EQ(states.size(), 2);
EXPECT_NEAR(states[0].position.x, 4.0, 1e-10);
EXPECT_NEAR(states[0].position.y, 1.0, 1e-10);
EXPECT_NEAR(states[0].position.z, 4.0, 1e-10);
EXPECT_NEAR(states[1].position.x, 4.0, 1e-10);
EXPECT_NEAR(states[1].position.y, 1.0, 1e-10);
EXPECT_NEAR(states[1].position.z, 4.0, 1e-10);
EXPECT_FALSE(noVelocityState.hasVelocity());
}
TEST(StatesTest, ConstructorPositionAndVelocity) { TEST(StatesTest, ConstructorPositionAndVelocity) {
std::vector<double> ephemTimes = {0.0, 1.0, 2.0, 3.0}; std::vector<double> ephemTimes = {0.0, 1.0, 2.0, 3.0};
std::vector<Vec3d> positions = { std::vector<Vec3d> positions = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment