Commit 8d5e628d authored by Steve T's avatar Steve T
Browse files

addition / subtraction possible for bezier curves of different degrees

parent 9384d0d1
......@@ -448,9 +448,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Safe, Point> {
bezier_curve_t& operator+=(const bezier_curve_t& other) {
assert_operator_compatible(other);
if(fabs(mult_T_ - other.mult_T_) > bezier_curve_t::MARGIN)
throw std::runtime_error("addition not implemented yet for curves of different mult");
bezier_curve_t other_elevated = other;
bezier_curve_t other_elevated = other * (other.mult_T_ / this->mult_T_); // TODO remove mult_T_ from Bezier
if(other.degree() > degree()){
elevate_self(other.degree() - degree());
}
......@@ -466,9 +464,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Safe, Point> {
bezier_curve_t& operator-=(const bezier_curve_t& other) {
assert_operator_compatible(other);
if(fabs(mult_T_ - other.mult_T_) > bezier_curve_t::MARGIN)
throw std::runtime_error("addition not implemented yet for curves of different mult");
bezier_curve_t other_elevated = other;
bezier_curve_t other_elevated = other * (other.mult_T_ / this->mult_T_);
if(other.degree() > degree()){
elevate_self(other.degree() - degree());
}
......
......@@ -56,14 +56,15 @@ BOOST_AUTO_TEST_CASE(bezierOperations, * boost::unit_test::tolerance(0.001)) {
vec1.push_back(Eigen::Vector3d::Random());
vec2.push_back(Eigen::Vector3d::Random());
}
for (int i =0; i<2; ++i)
for (int i =0; i<4; ++i)
{
vec1.push_back(Eigen::Vector3d::Random());
}
bezier_t p1(vec1.begin(),vec1.end(),0.,1.);
bezier_t p2(vec2.begin(),vec2.end(),0.,1.);
bezier_t p3(vec2.begin(),vec2.end(),0.,0.5);
bezier_t p4(vec2.begin(),vec2.end(),0.1,1.);
bezier_t p1(vec1.begin(),vec1.end(),0.2,.8);
bezier_t p2(vec2.begin(),vec2.end(),0.2,.8);
bezier_t p1Dev = p1.compute_derivate(2);
bezier_t p3(vec2.begin(),vec2.end(),0.2,0.5);
bezier_t p4(vec2.begin(),vec2.end(),0.1,.8);
bezier_t p5(vec2.begin(),vec2.end(),0.1,.5);
double k = 10.2;
......@@ -76,29 +77,37 @@ BOOST_AUTO_TEST_CASE(bezierOperations, * boost::unit_test::tolerance(0.001)) {
bezier_t pSum = p1 + p2;
bezier_t pSumR = p2 + p1;
bezier_t pSumDev = p1Dev + p2;
bezier_t pSumRDev = p2 + p1Dev;
bezier_t pSub = p1 - p2;
bezier_t pSubR = p2 - p1;
bezier_t pSubDev = p1Dev - p2;
bezier_t pSubRDev = p2 - p1Dev;
bezier_t pdiv = p1 / k;
bezier_t pMul = p1 * k;
bezier_t pMulR = k * p1;
bezier_t pNeg = -p1;
for (double i = 0.; i <=100.; ++i ){
for (double i = 20; i <=80.; ++i ){
double dt = i / 100.;
BOOST_TEST(( pSum(dt) - (p1(dt)+p2(dt))).norm()==0.);
BOOST_TEST((pSumR(dt) - (p1(dt)+p2(dt))).norm()==0.);
BOOST_TEST(( pSub(dt) - (p1(dt)-p2(dt))).norm()==0.);
BOOST_TEST((pSubR(dt) - (p2(dt)-p1(dt))).norm()==0.);
BOOST_TEST(( pMul(dt) - p1(dt)*k).norm()==0.);
BOOST_TEST((pMulR(dt) - p1(dt)*k).norm()==0.);
BOOST_TEST(( pdiv(dt) - p1(dt)/k).norm()==0.);
BOOST_TEST(( pNeg(dt) + p1(dt)).norm() == 0);
BOOST_TEST(( pSum(dt) - (p1(dt)+p2(dt))).norm()==0.);
BOOST_TEST((pSumR(dt) - (p1(dt)+p2(dt))).norm()==0.);
BOOST_TEST(( pSumDev(dt) - (p1Dev(dt)+p2(dt))).norm()==0.);
BOOST_TEST((pSumRDev(dt) - (p1Dev(dt)+p2(dt))).norm()==0.);
BOOST_TEST((pSub(dt) - (p1(dt)-p2(dt))).norm()==0.);
BOOST_TEST((pSubR(dt) - (p2(dt)-p1(dt))).norm()==0.);
BOOST_TEST((pSubDev(dt) - (p1Dev(dt)-p2(dt))).norm()==0.);
BOOST_TEST((pSubRDev(dt) - (p2(dt)-p1Dev(dt))).norm()==0.);
BOOST_TEST((pMul(dt) - p1(dt)*k).norm()==0.);
BOOST_TEST((pMulR(dt) - p1(dt)*k).norm()==0.);
BOOST_TEST(( pdiv(dt) - p1(dt)/k).norm()==0.);
BOOST_TEST(( pNeg(dt) + p1(dt)).norm() == 0);
}
pSum = bezier_t(p1); pSum += p2;
pSub = p1; pSub -= p2;
pdiv = p1; pdiv /= k;
pMul = p1; pMul *= k;
for (double i = 0.; i <=100.; ++i ){
for (double i = 20; i <=80.; ++i ){
double dt = i / 100.;
BOOST_TEST(( pSum(dt) - (p1(dt)+p2(dt))).norm()==0.);
BOOST_TEST(( pSub(dt) - (p1(dt)-p2(dt))).norm()==0.);
......
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