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
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ namespace ale {
      States(const std::vector<double>& ephemTimes, const std::vector<Vec3d>& positions,
             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,
             const std::vector<Vec3d>& velocities, int refFrame=1);

+13 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ namespace ale {
                 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");
    }
@@ -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,
                 const std::vector<Vec3d>& velocities, int refFrame) :
+17 −0
Original line number Diff line number Diff line
@@ -35,6 +35,23 @@ TEST(StatesTest, ConstructorPositionNoVelocity) {
  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) {
  std::vector<double> ephemTimes = {0.0, 1.0, 2.0, 3.0};
  std::vector<Vec3d> positions = {