diff --git a/src/g2_spline.cpp b/src/g2_spline.cpp index f3cdbd9e857e5072815f787d6531ec401260e63d..2cd609be84289562c88e05ca1f9b157439572157 100644 --- a/src/g2_spline.cpp +++ b/src/g2_spline.cpp @@ -587,14 +587,16 @@ void CG2Spline::generate(double resolution,unsigned int iterations) double n1_c_start,n1_2_k_s_start,n1_s_start,n1_2_k_c_start; double n2_c_end,n2_2_k_s_end,n2_s_end,n2_2_k_c_end; double u,pow_u,new_length,last_length; - unsigned int i; + unsigned int i,max_num_points; this->resolution=resolution; last_length=0.0; new_length=sqrt(pow(this->end.x-this->start.x,2)+pow(this->end.y-this->start.y,2)); + max_num_points=10.0*(new_length/resolution); + this->num_points=0; if(new_length>this->resolution) { - while(iterations>0 && fabs(new_length-last_length)>this->resolution) + while(iterations>0 && fabs(new_length-last_length)>this->resolution && this->num_points<max_num_points) { last_length=new_length; this->num_points=ceil(last_length/resolution); @@ -680,14 +682,16 @@ void CG2Spline::generate(double resolution,double length,unsigned int iterations double n1_c_start,n1_2_k_s_start,n1_s_start,n1_2_k_c_start; double n2_c_end,n2_2_k_s_end,n2_s_end,n2_2_k_c_end; double u,pow_u,new_length,last_length; - unsigned int i; + unsigned int i,max_num_points; this->resolution=resolution; last_length=0.0; new_length=length; + max_num_points=10.0*(length/resolution); + this->num_points=0; if(new_length>this->resolution) { - while(iterations>0 && fabs(new_length-last_length)>this->resolution) + while(iterations>0 && fabs(new_length-last_length)>this->resolution && this->num_points<max_num_points) { last_length=new_length; this->num_points=ceil(last_length/resolution);