From 40a366a1a0656e7fc4c50460021a3061dd038cbb Mon Sep 17 00:00:00 2001 From: JasonChmn <jason.chemin@hotmail.fr> Date: Thu, 6 Jun 2019 15:04:33 +0200 Subject: [PATCH] Add test and some doc for piecewise polynomial curve, all tests are working --- include/curves/piecewise_polynomial_curve.h | 19 +++++++++++++++-- tests/Main.cpp | 23 +++++++++------------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/curves/piecewise_polynomial_curve.h b/include/curves/piecewise_polynomial_curve.h index f1b80e2..bec4433 100644 --- a/include/curves/piecewise_polynomial_curve.h +++ b/include/curves/piecewise_polynomial_curve.h @@ -15,7 +15,14 @@ namespace curves { /// \class PiecewiseCurve. -/// +/// \brief Represent a piecewise polynomial curve. We can add some new polynomials to the curve, +/// but the starting time of the polynomial to add should be equal to the ending time of the +/// piecewise_polynomial_curve.\n +/// Example : A piecewise polynomial curve composed of three polynomials pol_0, pol_1 and pol_2 +/// where pol_0 is defined between \f$[T0_{min},T0_{max}]\f$, pol_1 between \f$[T0_{max},T1_{max}]\f$ +/// and pol_2 between \f$[T1_{max},T2_{max}]\f$. +/// On the piecewise polynomial curve, pol_0 is located between \f$[T0_{min},T0_{max}[\f$, +/// pol_1 between \f$[T0_{max},T1_{max}[\f$ and pol_2 between \f$[T1_{max},T2_{max}]\f$. /// template<typename Time= double, typename Numeric=Time, std::size_t Dim=3, bool Safe=false, typename Point= Eigen::Matrix<Numeric, Dim, 1>, @@ -75,9 +82,13 @@ struct piecewise_polynomial_curve : public curve_abc<Time, Numeric, Dim, Safe, P return (polynomial_curves_.at(find_interval(t))).derivate(t, order); } + /// \brief Add a new polynomial to piecewise curve, which should be defined in \f$[T_{min},T_{max}]\f$ where \f$T_{min}\f$ + /// is equal to \f$T_{max}\f$ of the actual piecewise curve. + /// \param pol : polynomial to add. + /// void add_polynomial_curve(polynomial_t pol) { - // Check time continuity : Begin time of pol must be equal to T_max_ of actual piecewise curve. + // Check time continuity : Beginning time of pol must be equal to T_max_ of actual piecewise curve. if (size_!=0 && pol.min()!=T_max_) { throw std::out_of_range("Can not add new Polynom to PiecewiseCurve : time discontinuity between T_max_ and pol.min()"); @@ -88,6 +99,10 @@ struct piecewise_polynomial_curve : public curve_abc<Time, Numeric, Dim, Safe, P time_polynomial_curves_.push_back(T_max_); } + /// \brief Check if the curve is continuous of order given. + /// \param order : order of continuity we want to check. + /// \return True if the curve is continuous of order given. + /// bool is_continuous(const std::size_t order) { bool isContinuous = true; diff --git a/tests/Main.cpp b/tests/Main.cpp index 9e40fac..0cd8630 100644 --- a/tests/Main.cpp +++ b/tests/Main.cpp @@ -1120,7 +1120,6 @@ void CubicHermitePairsPositionDerivativeTest(bool& error) ComparePoints(t2, res1, errmsg3, error); } -/* void piecewisePolynomialCurveTest(bool& error) { @@ -1133,6 +1132,7 @@ void piecewisePolynomialCurveTest(bool& error) vec1.push_back(a); // x=1, y=1, z=1 vec2.push_back(b); // x=2, y=1, z=1 vec3.push_back(c); // x=3, y=1, z=1 + // Create three polynomials of constant value in the interval of definition polynomial_t pol1(vec1.begin(), vec1.end(), 0, 1); polynomial_t pol2(vec2.begin(), vec2.end(), 1, 2); polynomial_t pol3(vec3.begin(), vec3.end(), 2, 3); @@ -1147,20 +1147,23 @@ void piecewisePolynomialCurveTest(bool& error) ppc.add_polynomial_curve(pol3); // Check values on piecewise curve + // t in [0,1[ -> res=a res = ppc(0.); ComparePoints(a,res,errmsg1,error); res = ppc(0.5); ComparePoints(a,res,errmsg1,error); + // t in [1,2[ -> res=b res = ppc(1.0); ComparePoints(b,res,errmsg1,error); res = ppc(1.5); ComparePoints(b,res,errmsg1,error); - res = ppc(2.5); + // t in [2,3] -> res=c + res = ppc(2.0); ComparePoints(c,res,errmsg1,error); res = ppc(3.0); ComparePoints(c,res,errmsg1,error); - // piecewise curve C0 + // Create piecewise curve C0 point_t a1(1,1,1); t_point_t vec_C0; vec_C0.push_back(a); @@ -1174,7 +1177,7 @@ void piecewisePolynomialCurveTest(bool& error) res = ppc_C0(1.5); ComparePoints(point_t(1.5,1.5,1.5),res,errmsg1,error); - // piecewise curve C1 from Hermite + // Create piecewise curve C1 from Hermite point_t p0(0.,0.,0.); point_t p1(1.,2.,3.); point_t p2(4.,4.,4.); @@ -1200,7 +1203,7 @@ void piecewisePolynomialCurveTest(bool& error) piecewise_polynomial_curve_t ppc_C1(pol_chs0); ppc_C1.add_polynomial_curve(pol_chs1); - // piecewise curve C2 + // Create piecewise curve C2 point_t a0(0,0,0); point_t b0(1,1,1); t_point_t veca, vecb; @@ -1263,7 +1266,6 @@ void piecewisePolynomialCurveTest(bool& error) error = true; } } -*/ int main(int /*argc*/, char** /*argv[]*/) { @@ -1289,14 +1291,9 @@ int main(int /*argc*/, char** /*argv[]*/) BezierEvalDeCasteljau(error); BezierSplitCurve(error); CubicHermitePairsPositionDerivativeTest(error); - - //piecewisePolynomialCurveTest(error); - - //toPolynomialConversionTest(error); - + piecewisePolynomialCurveTest(error); + toPolynomialConversionTest(error); cubicConversionTest(error); - - if(error) { -- GitLab