Skip to content
Snippets Groups Projects
Commit 6d4676fc authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Stop the spline generation if the number of points gets too big (generation...

Stop the spline generation if the number of points gets too big (generation diverges for some reason)
parent 133742d6
No related branches found
No related tags found
1 merge request!2Solved a bug when creating a new geometry object: the sale factor is...
...@@ -587,14 +587,16 @@ void CG2Spline::generate(double resolution,unsigned int iterations) ...@@ -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 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 n2_c_end,n2_2_k_s_end,n2_s_end,n2_2_k_c_end;
double u,pow_u,new_length,last_length; double u,pow_u,new_length,last_length;
unsigned int i; unsigned int i,max_num_points;
this->resolution=resolution; this->resolution=resolution;
last_length=0.0; last_length=0.0;
new_length=sqrt(pow(this->end.x-this->start.x,2)+pow(this->end.y-this->start.y,2)); 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) 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; last_length=new_length;
this->num_points=ceil(last_length/resolution); this->num_points=ceil(last_length/resolution);
...@@ -680,14 +682,16 @@ void CG2Spline::generate(double resolution,double length,unsigned int iterations ...@@ -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 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 n2_c_end,n2_2_k_s_end,n2_s_end,n2_2_k_c_end;
double u,pow_u,new_length,last_length; double u,pow_u,new_length,last_length;
unsigned int i; unsigned int i,max_num_points;
this->resolution=resolution; this->resolution=resolution;
last_length=0.0; last_length=0.0;
new_length=length; new_length=length;
max_num_points=10.0*(length/resolution);
this->num_points=0;
if(new_length>this->resolution) 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; last_length=new_length;
this->num_points=ceil(last_length/resolution); this->num_points=ceil(last_length/resolution);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment