Unverified Commit c7a9b3db authored by Fernbach Pierre's avatar Fernbach Pierre Committed by GitHub
Browse files

Merge pull request #42 from pFernbach/topic/fix_25

Check input degree before converting curve to bezier or hermite
parents 6f2af443 39e5e9dc
......@@ -36,6 +36,8 @@ Polynomial polynomial_from_curve(const typename Polynomial::curve_abc_t& curve)
/// \return the equivalent cubic bezier curve.
template <typename Bezier>
Bezier bezier_from_curve(const typename Bezier::curve_abc_t& curve) {
if(curve.degree() > 3)
throw std::invalid_argument("bezier_from_curve is only implemented for curves of degree <= 3.");
typedef typename Bezier::point_t point_t;
typedef typename Bezier::t_point_t t_point_t;
typedef typename Bezier::num_t num_t;
......@@ -68,6 +70,8 @@ Bezier bezier_from_curve(const typename Bezier::curve_abc_t& curve) {
/// \return the equivalent cubic hermite spline.
template <typename Hermite>
Hermite hermite_from_curve(const typename Hermite::curve_abc_t& curve) {
if(curve.degree() > 3)
throw std::invalid_argument("hermite_from_curve is only implemented for curves of degree <= 3.");
typedef typename Hermite::pair_point_tangent_t pair_point_tangent_t;
typedef typename Hermite::t_pair_point_tangent_t t_pair_point_tangent_t;
typedef typename Hermite::point_t point_t;
......@@ -91,4 +95,4 @@ Hermite hermite_from_curve(const typename Hermite::curve_abc_t& curve) {
return Hermite(control_points.begin(), control_points.end(), time_control_points);
}
} // namespace curves
#endif //_CLASS_CURVE_CONVERSION
\ No newline at end of file
#endif //_CLASS_CURVE_CONVERSION
......@@ -490,6 +490,36 @@ void cubicConversionTest(bool& error) {
curve_abc_t* bc_der = bc0.compute_derivate_ptr(1);
polynomial_t pol_test = polynomial_from_curve<polynomial_t>(*bc_der);
CompareCurves<curve_abc_t, polynomial_t>(*bc_der, pol_test, errMsg1, error);
// check that an error is correctly raised when degree > 3:
point3_t a(1, 2, 3);
point3_t b(2, 3, 4);
point3_t c(3, 4, 5);
point3_t d(3, 6, 7);
point3_t e(3, 6, 7);
t_pointX_t vec;
vec.push_back(a);
vec.push_back(b);
vec.push_back(c);
vec.push_back(d);
vec.push_back(e);
polynomial_t pol_4(vec.begin(), vec.end(), 0, 1);
if(pol_4.degree() != 4){
std::cout<<"In test CubicConversionTest - Error in the creatin of the polynomial"<<std::endl;
error = true;
}
try {
cubic_hermite_spline_t chs3 = hermite_from_curve<cubic_hermite_spline_t>(pol_4);
std::cout<<"In test CubicConversionTest - Cannot convert to hermite from degree > 3, should raise an error"<<std::endl;
error = true;
} catch (std::invalid_argument e) {
}
try {
bezier_t b3 = bezier_from_curve<bezier_t>(pol_4);
std::cout<<"In test CubicConversionTest - Cannot convert to bezier from degree > 3, should raise an error"<<std::endl;
error = true;
} catch (std::invalid_argument e) {
}
}
/*Exact Cubic Function tests*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment