Commit a4a418cb authored by JasonChmn's avatar JasonChmn
Browse files

[Bezier curve] Add tests in c++ for extract function => OK

parent 4087266f
......@@ -333,9 +333,9 @@ namespace curves
}
t_point_t wps_first(size_),wps_second(size_);
const Numeric u = (t-T_min_)/(T_max_-T_min_);
wps_first[0] = control_points_.front();
wps_second[degree_] = control_points_.back();
t_point_t casteljau_pts = waypoints();
wps_first[0] = casteljau_pts.front();
wps_second[degree_] = casteljau_pts.back();
size_t id = 1;
while(casteljau_pts.size() > 1)
{
......@@ -355,20 +355,21 @@ namespace curves
/// \param t2 : end time of bezier curve extracted.
/// \return bezier curve extract defined between \f$[t_1,t_2]\f$.
///
bezier_curve_t extract(const Numeric t1, const Numeric t2){
bezier_curve_t extract(const Numeric t1, const Numeric t2)
{
if(t1 < T_min_ || t1 > T_max_ || t2 < T_min_ || t2 > T_max_)
{
throw std::out_of_range("In Extract curve : times out of bounds");
}
if (fabs(t1-T_min_)<MARGIN && fabs(t2-T_max_)<MARGIN)
if (fabs(t1-T_min_)<MARGIN && fabs(t2-T_max_)<MARGIN) // t1=T_min and t2=T_max
{
return bezier_curve_t(waypoints().begin(), waypoints().end(), T_min_, T_max_, mult_T_);
}
if (fabs(t1-T_min_)<MARGIN)
if (fabs(t1-T_min_)<MARGIN) // t1=T_min
{
return split(t2).first;
}
if (fabs(t2-T_max_)<MARGIN)
if (fabs(t2-T_max_)<MARGIN) // t2=T_max
{
return split(t1).second;
}
......
......@@ -976,10 +976,25 @@ void BezierSplitCurve(bool& error)
ti += 0.01;
}
// Test extract function
bezier_curve_t bezier_extracted = c.extract(t0+0.01,t1-0.01);
for(double t=bezier_extracted.min(); t<bezier_extracted.max(); t+=0.01)
bezier_curve_t bezier_extracted0 = c.extract(t0+0.01,t1-0.01); // T_min < t0 < t1 < T_max
for(double t=bezier_extracted0.min(); t<bezier_extracted0.max(); t+=0.01)
{
ComparePoints(bezier_extracted(t),c(t),errMsg6, error);
ComparePoints(bezier_extracted0(t),c(t),errMsg6, error);
}
bezier_curve_t bezier_extracted1 = c.extract(t0,t1-0.01); // T_min = t0 < t1 < T_max
for(double t=bezier_extracted1.min(); t<bezier_extracted1.max(); t+=0.01)
{
ComparePoints(bezier_extracted1(t),c(t),errMsg6, error);
}
bezier_curve_t bezier_extracted2 = c.extract(t0+0.01,t1); // T_min < t0 < t1 = T_max
for(double t=bezier_extracted2.min(); t<bezier_extracted2.max(); t+=0.01)
{
ComparePoints(bezier_extracted2(t),c(t),errMsg6, error);
}
bezier_curve_t bezier_extracted3 = c.extract(t0,t1); // T_min = t0 < t1 = T_max
for(double t=bezier_extracted3.min(); t<bezier_extracted3.max(); t+=0.01)
{
ComparePoints(bezier_extracted3(t),c(t),errMsg6, error);
}
}
}
......
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