From 829472742949e9bd5b1e8a4fee2785435601beaa Mon Sep 17 00:00:00 2001 From: steve tonneau <stevetonneau@hotmail.fr> Date: Sat, 21 Dec 2013 15:10:06 +0100 Subject: [PATCH] error in cubic function t_min >= t_max --- include/spline/bezier_curve.h | 2 +- include/spline/cubic_function.h | 2 +- include/spline/exact_cubic.h | 2 +- src/tests/spline_test/Main.cpp | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/spline/bezier_curve.h b/include/spline/bezier_curve.h index e02e4fa..85b06a7 100644 --- a/include/spline/bezier_curve.h +++ b/include/spline/bezier_curve.h @@ -72,7 +72,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> num_t nT = (t - minBound_) / (maxBound_ - minBound_); if(Safe &! (0 <= nT && nT <= 1)) { - throw; // TODO + //throw; // TODO } else { diff --git a/include/spline/cubic_function.h b/include/spline/cubic_function.h index 8705375..c5acdf6 100644 --- a/include/spline/cubic_function.h +++ b/include/spline/cubic_function.h @@ -40,7 +40,7 @@ struct cubic_function : public curve_abc<Time, Numeric, Dim, Safe, Point> cubic_function(point_t const& a, point_t const& b, point_t const& c, point_t const &d, time_t min, time_t max) :a_(a), b_(b), c_(c), d_(d), t_min_(min), t_max_(max) { - if(t_min_ >= t_max_ && Safe) + if(t_min_ > t_max_ && Safe) { std::out_of_range("TODO"); } diff --git a/include/spline/exact_cubic.h b/include/spline/exact_cubic.h index 3c2e641..6958f04 100644 --- a/include/spline/exact_cubic.h +++ b/include/spline/exact_cubic.h @@ -146,7 +146,7 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point> virtual point_t operator()(time_t t) const { - if(Safe && (t < subSplines_.front()->t_min_ || t > subSplines_.back()->t_max_)){throw std::out_of_range("TODO");} + if(Safe && (t < subSplines_.front()->t_min_ || t > subSplines_.back()->t_max_)){throw std::out_of_range("TODO");} for(CIT_cubic it = subSplines_.begin(); it != subSplines_.end(); ++ it) { if(t >= ((*it)->t_min_) && t <= ((*it)->t_max_)) diff --git a/src/tests/spline_test/Main.cpp b/src/tests/spline_test/Main.cpp index 3fef0ca..0a120f6 100644 --- a/src/tests/spline_test/Main.cpp +++ b/src/tests/spline_test/Main.cpp @@ -18,6 +18,13 @@ typedef bezier_curve <double, double, 3, true, point_t> bezier_curve_t; typedef std::pair<double, point_t> Waypoint; typedef std::vector<Waypoint> T_Waypoint; + +typedef Eigen::Matrix<double,1,1> point_one; +typedef cubic_function<double, double, 1, true, point_one> cubic_function_one; +typedef exact_cubic <double, double, 1, true, point_one> exact_cubic_one; +typedef std::pair<double, point_one> WaypointOne; +typedef std::vector<WaypointOne> T_WaypointOne; + bool QuasiEqual(const double a, const double b, const float margin) { if ((a <= 0 && b <= 0) || (a >= 0 && b>= 0)) @@ -56,6 +63,15 @@ void ComparePoints(const point_t& pt1, const point_t& pt2, const std::string& er } } +void ComparePoints(const point_one& pt1, const point_one& pt2, const std::string& errmsg, bool& error) +{ + if(!(pt1 == pt2)) + { + error = true; + std::cout << errmsg << pt1 << " ; " << pt2 << "\n"; + } +} + /*Cubic Function tests*/ void CubicFunctionTest(bool& error) @@ -247,6 +263,44 @@ void ExactCubicNoErrorTest(bool& error) } } + +/*Exact Cubic Function tests*/ +void ExactCubicTwoPointsTest(bool& error) +{ + spline::T_Waypoint waypoints; + for(double i = 0; i < 2; ++i) + { + waypoints.push_back(std::make_pair(i,point_t(i,i,i))); + } + exact_cubic_t exactCubic(waypoints.begin(), waypoints.end()); + + point_t res1 = exactCubic(0); + std::string errmsg("in ExactCubic 2 points Error While checking that given wayPoints are crossed (expected / obtained)"); + ComparePoints(point_t(0,0,0), res1, errmsg, error); + + res1 = exactCubic(1); + ComparePoints(point_t(1,1,1), res1, errmsg, error); +} + +void ExactCubicOneDimTest(bool& error) +{ + spline::T_WaypointOne waypoints; + point_one zero; zero(0,0) = 9; + point_one one; one(0,0) = 14; + point_one two; two(0,0) = 25; + waypoints.push_back(std::make_pair(0., zero)); + waypoints.push_back(std::make_pair(1., one)); + waypoints.push_back(std::make_pair(2., two)); + exact_cubic_one exactCubic(waypoints.begin(), waypoints.end()); + + point_one res1 = exactCubic(0); + std::string errmsg("in ExactCubicOneDim Error While checking that given wayPoints are crossed (expected / obtained)"); + ComparePoints(zero, res1, errmsg, error); + + res1 = exactCubic(1); + ComparePoints(one, res1, errmsg, error); +} + void ExactCubicPointsCrossedTest(bool& error) { spline::T_Waypoint waypoints; @@ -271,6 +325,8 @@ int main(int argc, char *argv[]) CubicFunctionTest(error); ExactCubicNoErrorTest(error); ExactCubicPointsCrossedTest(error); // checks that given wayPoints are crossed + ExactCubicTwoPointsTest(error); + ExactCubicOneDimTest(error); //BezierCurveTest(error); if(error) { -- GitLab