diff --git a/include/spline/bernstein.h b/include/spline/bernstein.h index c55afd306269ac0b64c70299c64be70deb3312bc..ac93c24855635a0e82716da78a66f548755358a6 100644 --- a/include/spline/bernstein.h +++ b/include/spline/bernstein.h @@ -25,9 +25,8 @@ namespace spline /// inline unsigned int fact(const unsigned int n) { - assert(n>=0); - int res = 1; - for (int i=2 ; i <= n ; ++i) + unsigned int res = 1; + for (unsigned int i=2 ; i <= n ; ++i) res *= i; return res; } diff --git a/include/spline/bezier_curve.h b/include/spline/bezier_curve.h index 03bbe721c7148cf1b79cff4ce525431f2854bf0c..dfdc94e058061eb6528d37b46f8a87382bfb3989 100644 --- a/include/spline/bezier_curve.h +++ b/include/spline/bezier_curve.h @@ -51,7 +51,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> , mult_T_(1.) , size_(std::distance(PointsBegin, PointsEnd)) , degree_(size_-1) - , bernstein_(spline::makeBernstein<num_t>(degree_)) + , bernstein_(spline::makeBernstein<num_t>((unsigned int)degree_)) { assert(bernstein_.size() == size_); In it(PointsBegin); @@ -70,7 +70,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> , mult_T_(1.) , size_(std::distance(PointsBegin, PointsEnd)) , degree_(size_-1) - , bernstein_(spline::makeBernstein<num_t>(degree_)) + , bernstein_(spline::makeBernstein<num_t>((unsigned int)degree_)) { assert(bernstein_.size() == size_); In it(PointsBegin); @@ -91,7 +91,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> , mult_T_(mult_T) , size_(std::distance(PointsBegin, PointsEnd)) , degree_(size_-1) - , bernstein_(spline::makeBernstein<num_t>(degree_)) + , bernstein_(spline::makeBernstein<num_t>((unsigned int)degree_)) { assert(bernstein_.size() == size_); In it(PointsBegin); @@ -113,7 +113,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> , mult_T_(1.) , size_(std::distance(PointsBegin, PointsEnd)+4) , degree_(size_-1) - , bernstein_(spline::makeBernstein<num_t>(degree_)) + , bernstein_(spline::makeBernstein<num_t>((unsigned int)degree_)) { if(Safe && (size_<1 || T_ <= 0.)) throw std::out_of_range("can't create bezier min bound is higher than max bound"); @@ -180,7 +180,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> if(order == 0) return *this; t_point_t derived_wp; for(typename t_point_t::const_iterator pit = pts_.begin(); pit != pts_.end()-1; ++pit) - derived_wp.push_back(degree_ * (*(pit+1) - (*pit))); + derived_wp.push_back((num_t)degree_ * (*(pit+1) - (*pit))); if(derived_wp.empty()) derived_wp.push_back(point_t::Zero()); bezier_curve_t deriv(derived_wp.begin(), derived_wp.end(),T_, mult_T_ * (1./T_) ); @@ -247,10 +247,10 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> bc = 1; tn = 1; point_t tmp =(*pts_it)*u; ++pts_it; - for(int i=1; i<degree_; i++, ++pts_it) + for(unsigned int i=1; i<degree_; i++, ++pts_it) { tn = tn*t; - bc = bc*(degree_-i+1)/i; + bc = bc*((num_t)(degree_-i+1))/i; tmp = (tmp + tn*bc*(*pts_it))*u; } return (tmp + tn*t*(*pts_it)); @@ -265,10 +265,10 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point> t_point_t res; point_t P0, P1, P2, P_n_2, P_n_1, PN; P0 = *PointsBegin; PN = *(PointsEnd-1); - P1 = P0+ constraints.init_vel / degree_; - P_n_1 = PN -constraints.end_vel / degree_; - P2 = constraints.init_acc / (degree_ * (degree_-1)) + 2* P1 - P0; - P_n_2 = constraints.end_acc / (degree_ * (degree_-1)) + 2* P_n_1 - PN; + P1 = P0+ constraints.init_vel / (num_t)degree_; + P_n_1 = PN -constraints.end_vel / (num_t)degree_; + P2 = constraints.init_acc / (num_t)(degree_ * (degree_-1)) + 2* P1 - P0; + P_n_2 = constraints.end_acc / (num_t)(degree_ * (degree_-1)) + 2* P_n_1 - PN; res.push_back(P0); res.push_back(P1); diff --git a/include/spline/bezier_polynom_conversion.h b/include/spline/bezier_polynom_conversion.h index 7227a91f149d9c4c21d929d38909dc22a1057671..2a4b5acc6991b98caac5ff5a2a8b317087408ac5 100644 --- a/include/spline/bezier_polynom_conversion.h +++ b/include/spline/bezier_polynom_conversion.h @@ -47,7 +47,7 @@ Polynom from_bezier(const Bezier& curve) for(std::size_t i = 1; i<= curve.degree_; ++i) { current = current.compute_derivate(1); - fact *= i; + fact *= (num_t)i; coefficients.push_back(current(0.)/fact); } return Polynom(coefficients,curve.min(),curve.max()); diff --git a/include/spline/curve_abc.h b/include/spline/curve_abc.h index 803ab9b7f48f67446d1e904ff0b78c94765bb216..7a8dccaf183075de4cde6032f475a26bad64342e 100644 --- a/include/spline/curve_abc.h +++ b/include/spline/curve_abc.h @@ -34,7 +34,7 @@ struct curve_abc : std::unary_function<Time, Point> curve_abc(){} ///\brief Destructor - ~curve_abc(){} + virtual ~curve_abc(){} /* Constructors - destructors */ /*Operations*/ diff --git a/include/spline/exact_cubic.h b/include/spline/exact_cubic.h index 354fd0bb48ffbf3da689596e453270efc4f74eae..550709c37371ac0b4ebb48eb39aa47ead8b8febe 100644 --- a/include/spline/exact_cubic.h +++ b/include/spline/exact_cubic.h @@ -71,7 +71,7 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point> : curve_abc_t(), subSplines_(other.subSplines_) {} ///\brief Destructor - ~exact_cubic(){} + virtual ~exact_cubic(){} private: template<typename In> @@ -162,12 +162,12 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point> { if(Safe && (t < subSplines_.front().min() || t > subSplines_.back().max())){throw std::out_of_range("TODO");} for(cit_spline_t it = subSplines_.begin(); it != subSplines_.end(); ++ it) - { - if(t >= (it->min()) && t <= (it->max())) - { + { + if( (t >= (it->min()) && t <= (it->max())) || it+1 == subSplines_.end()) return it->operator()(t); - } } + // this should not happen + throw std::runtime_error("Exact cubic evaluation failed; t is outside bounds"); } /// \brief Evaluation of the derivative spline at time t. @@ -179,11 +179,11 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point> if(Safe && (t < subSplines_.front().min() || t > subSplines_.back().max())){throw std::out_of_range("TODO");} for(cit_spline_t it = subSplines_.begin(); it != subSplines_.end(); ++ it) { - if(t >= (it->min()) && t <= (it->max())) - { + if( (t >= (it->min()) && t <= (it->max())) || it+1 == subSplines_.end()) return it->derivate(t, order); - } } + // this should not happen + throw std::runtime_error("Exact cubic evaluation failed; t is outside bounds"); } /*Operations*/ diff --git a/include/spline/helpers/effector_spline.h b/include/spline/helpers/effector_spline.h index 99284129799529a443c71f95929f5120b49b5b8b..11e7a2c9a3bf47fe08e1d9015808f2c74dc3e1df 100644 --- a/include/spline/helpers/effector_spline.h +++ b/include/spline/helpers/effector_spline.h @@ -68,7 +68,7 @@ spline_t make_end_spline(const Point& normal, const Point& from, const Numeric o return spline_t(points.begin(), points.end(), init_time, init_time+time_offset); } -spline_constraints_t compute_required_offset_velocity_acceleration(const spline_t& end_spline, const Time time_offset) +spline_constraints_t compute_required_offset_velocity_acceleration(const spline_t& end_spline, const Time /*time_offset*/) { //computing end velocity: along landing normal and respecting time spline_constraints_t constraints; diff --git a/include/spline/helpers/effector_spline_rotation.h b/include/spline/helpers/effector_spline_rotation.h index e9f7992639bdecbddcf4f74f478ae9c19163223f..efc007ec8eca01b63f2d02fa16cdbaa747cfd04e 100644 --- a/include/spline/helpers/effector_spline_rotation.h +++ b/include/spline/helpers/effector_spline_rotation.h @@ -61,6 +61,7 @@ class rotation_spline: public curve_abc_quat_t quat_to_ = from.quat_to_; min_ =from.min_; max_ = from.max_; time_reparam_ = spline_deriv_constraint_one_dim(from.time_reparam_); + return *this; } /* Copy Constructors / operator=*/ diff --git a/include/spline/polynom.h b/include/spline/polynom.h index 59ca0db3e09a79914289de7c7b6395c199dfe46f..32c8aad06b92769015b660ed1e85402423561d1e 100644 --- a/include/spline/polynom.h +++ b/include/spline/polynom.h @@ -52,7 +52,7 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> ///\param max: UPPER bound on interval definition of the spline polynom(const coeff_t& coefficients, const time_t min, const time_t max) : curve_abc_t(), - coefficients_(coefficients), t_min_(min), t_max_(max), dim_(Dim), order_(coefficients_.cols()-1) + coefficients_(coefficients), dim_(Dim), order_(coefficients_.cols()-1), t_min_(min), t_max_(max) { safe_check(); } @@ -66,7 +66,7 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> polynom(const T_Point& coefficients, const time_t min, const time_t max) : curve_abc_t(), coefficients_(init_coeffs(coefficients.begin(), coefficients.end())), - t_min_(min), t_max_(max), dim_(Dim), order_(coefficients_.cols()-1) + dim_(Dim), order_(coefficients_.cols()-1), t_min_(min), t_max_(max) { safe_check(); } @@ -79,8 +79,8 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> ///\param max: UPPER bound on interval definition of the spline template<typename In> polynom(In zeroOrderCoefficient, In out, const time_t min, const time_t max) - :coefficients_(init_coeffs(zeroOrderCoefficient, out)), dim_(Dim), order_(coefficients_.cols()-1), - t_min_(min), t_max_(max) + :coefficients_(init_coeffs(zeroOrderCoefficient, out)), + dim_(Dim), order_(coefficients_.cols()-1), t_min_(min), t_max_(max) { safe_check(); } @@ -93,8 +93,8 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> polynom(const polynom& other) - : coefficients_(other.coefficients_), dim_(other.dim_), order_(other.order_), - t_min_(other.t_min_), t_max_(other.t_max_){} + : coefficients_(other.coefficients_), + dim_(other.dim_), order_(other.order_), t_min_(other.t_min_), t_max_(other.t_max_){} //polynom& operator=(const polynom& other); @@ -106,7 +106,7 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> { if(t_min_ > t_max_) std::out_of_range("TODO"); - if(coefficients_.size() != order_+1) + if(coefficients_.size() != int(order_+1)) std::runtime_error("Spline order and coefficients do not match"); } } @@ -138,7 +138,7 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> if((t < t_min_ || t > t_max_) && Safe){ throw std::out_of_range("TODO");} time_t const dt (t-t_min_); point_t h = coefficients_.col(order_); - for(int i=order_-1; i>=0; i--) + for(int i=(int)(order_-1); i>=0; i--) h = dt*h + coefficients_.col(i); return h; } @@ -154,7 +154,7 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> time_t const dt (t-t_min_); time_t cdt(1); point_t currentPoint_ = point_t::Zero(); - for(int i = order; i < order_+1; ++i, cdt*=dt) + for(int i = (int)(order); i < (int)(order_+1); ++i, cdt*=dt) currentPoint_ += cdt *coefficients_.col(i) * fact(i, order); return currentPoint_; } @@ -162,9 +162,9 @@ struct polynom : public curve_abc<Time, Numeric, Dim, Safe, Point> private: num_t fact(const std::size_t n, const std::size_t order) const { - std::size_t res(1); + num_t res(1); for(std::size_t i = 0; i < order; ++i) - res *= n-i; + res *= (num_t)(n-i); return res; } diff --git a/include/spline/spline_deriv_constraint.h b/include/spline/spline_deriv_constraint.h index 304cca63b4b9fc7526a0e30954ceba15e28c0eb8..398b6973df439c672c611be3f014e424684f2812 100644 --- a/include/spline/spline_deriv_constraint.h +++ b/include/spline/spline_deriv_constraint.h @@ -67,7 +67,7 @@ struct spline_deriv_constraint : public exact_cubic<Time, Numeric, Dim, Safe, Po : exact_cubic_t(computeWayPoints<In>(wayPointsBegin, wayPointsEnd, constraints)) {} ///\brief Destructor - ~spline_deriv_constraint(){} + virtual ~spline_deriv_constraint(){} ///\brief Copy Constructor spline_deriv_constraint(const spline_deriv_constraint& other) diff --git a/src/tests/spline_test/Main.cpp b/src/tests/spline_test/Main.cpp index c77ebd319b9107428fd919f330482e64f80ca4e2..ddb35e1049a0409c26b9edef61aa46adcb8b2c8f 100644 --- a/src/tests/spline_test/Main.cpp +++ b/src/tests/spline_test/Main.cpp @@ -36,7 +36,7 @@ bool QuasiEqual(const double a, const double b, const float margin) { if ((a <= 0 && b <= 0) || (a >= 0 && b>= 0)) { - return (abs(a-b)) <= margin; + return (abs(a-b)) <= margin; } else { @@ -229,7 +229,7 @@ void BezierCurveTest(bool& error) } #include <ctime> -void BezierCurveTestCompareHornerAndBernstein(bool& error) +void BezierCurveTestCompareHornerAndBernstein(bool& /*error*/) { using namespace std; std::vector<double> values; @@ -518,7 +518,7 @@ void ExactCubicOneDimTest(bool& error) ComparePoints(one, res1, errmsg, error); } -void CheckWayPointConstraint(const std::string& errmsg, const double step, const spline::T_Waypoint& wayPoints, const exact_cubic_t* curve, bool& error ) +void CheckWayPointConstraint(const std::string& errmsg, const double step, const spline::T_Waypoint& /*wayPoints*/, const exact_cubic_t* curve, bool& error ) { point_t res1; for(double i = 0; i <= 1; i = i + step)