Skip to content

Commit

Permalink
cleaned up polyxd code (restricted access, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Winkler committed Apr 6, 2017
1 parent 16cc975 commit 14c8c06
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
29 changes: 9 additions & 20 deletions include/xpp/opt/impl/polynomial_xd-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,23 @@ namespace xpp {
namespace opt {

template<typename PolynomialType, typename PointType>
PolynomialXd<PolynomialType, PointType>::PolynomialXd (int id,
double duration)
PolynomialXd<PolynomialType, PointType>::PolynomialXd (int id, double duration)
{
SetDuration(duration);
SetId(id);
SetBoundary(duration, Point(), Point());
}

template<typename PolynomialType, typename PointType>
PolynomialXd<PolynomialType, PointType>::~PolynomialXd ()
{
// TODO Auto-generated destructor stub
}

template<typename PolynomialType, typename PointType>
void
PolynomialXd<PolynomialType, PointType>::SetDuration (double _duration)
{
for (int dim=X; dim<kNumDim; ++dim)
polynomials_.at(dim).duration = _duration;
}

template<typename PolynomialType, typename PointType>
double
PolynomialXd<PolynomialType, PointType>::GetDuration () const
{
// all polynomials have same duration, so just return duration of X
return polynomials_.at(X).duration;
return polynomials_.at(X).GetDuration();
}

template<typename PolynomialType, typename PointType>
Expand All @@ -54,22 +44,21 @@ template<typename PolynomialType, typename PointType>
double
PolynomialXd<PolynomialType, PointType>::GetCoefficient (int dim, PolyCoeff coeff) const
{
return polynomials_.at(dim).c[coeff];
return polynomials_.at(dim).GetCoefficient(coeff);
}

template<typename PolynomialType, typename PointType>
void
PolynomialXd<PolynomialType, PointType>::SetCoefficients (int dim,
PolyCoeff coeff,
double value)
PolynomialXd<PolynomialType, PointType>::SetCoefficients (int dim, PolyCoeff coeff,
double value)
{
polynomials_.at(dim).c[coeff] = value;
polynomials_.at(dim).SetCoefficient(coeff,value);
}

template<typename PolynomialType, typename PointType>
void PolynomialXd<PolynomialType, PointType>::SetBoundary(double T,
const Point& start,
const Point& end)
const Point& start,
const Point& end)
{
for (int dim=X; dim<kNumDim; ++dim)
polynomials_.at(dim).SetBoundary(T, start.Get1d(dim), end.Get1d(dim));
Expand Down
11 changes: 8 additions & 3 deletions include/xpp/opt/polynomial.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ class Polynomial {
*/
bool GetPoint(const double dt, StateLin1d& point) const;

double GetCoefficient(PolynomialCoeff coeff) const;
void SetCoefficient(PolynomialCoeff coeff, double value);

double GetDuration() const;

protected:
std::array< double, AllSplineCoeff.size() > c; //!< coefficients of spline
double duration;

private:
double duration;
/**
* @brief Calculates all spline coeff of current spline.
*
* params are the same as @ref getPoint.
* This is the only function that must be implemented by the child classes.
*/
virtual void SetPolynomialCoefficients(double T, const StateLin1d& start_p, const StateLin1d& end_p) = 0;

protected:
};

inline Polynomial::Polynomial()
Expand Down
1 change: 0 additions & 1 deletion include/xpp/opt/polynomial_xd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PolynomialXd {

static int GetNumCoeff() { return PolynomialType::GetNumCoeff(); };

void SetDuration(double duration);
double GetDuration() const;

uint GetId() const { return id_; };
Expand Down
15 changes: 15 additions & 0 deletions src/polynomial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ bool Polynomial::GetPoint(const double dt, StateLin1d& out) const
return true;
}

double Polynomial::GetCoefficient(PolynomialCoeff coeff) const
{
return c[coeff];
}

void Polynomial::SetCoefficient(PolynomialCoeff coeff, double value)
{
c[coeff] = value;
}

double Polynomial::GetDuration() const
{
return duration;
}

void LinearPolynomial::SetPolynomialCoefficients(double T, const StateLin1d& start, const StateLin1d& end)
{
c[F] = start.p;
Expand Down

0 comments on commit 14c8c06

Please sign in to comment.