# HG changeset patch # User hegyi # Date 1132763099 0 # Node ID 56eb90299693297a1fe02c175d7746635ebc4ef2 # Parent ee2bd58fdc30b87a0fe2ad8507fb845c31d4439e No segmentation fault caused by zero long edges. diff -r ee2bd58fdc30 -r 56eb90299693 gdc-broken_edge.cc --- a/gdc-broken_edge.cc Tue Nov 22 14:35:33 2005 +0000 +++ b/gdc-broken_edge.cc Wed Nov 23 16:24:59 2005 +0000 @@ -73,38 +73,49 @@ double absa=sqrt(a_v.normSquare()); double absb=sqrt(b_v.normSquare()); - //old vector from one node to the breakpoint - c - xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); + if((absa!=0)&&(absb!=0)) + { + //old vector from one node to the breakpoint - c + xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); - //unit vector with the same direction to a_v - xy a_v_u(a_v.x/absa,a_v.y/absa); + //unit vector with the same direction to a_v + xy a_v_u(a_v.x/absa,a_v.y/absa); - //normal vector of unit vector with the same direction to a_v - xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); + //normal vector of unit vector with the same direction to a_v + xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); - //unit vector with the same direction to b_v - xy b_v_u(b_v.x/absb,b_v.y/absb); + //unit vector with the same direction to b_v + xy b_v_u(b_v.x/absb,b_v.y/absb); - //normal vector of unit vector with the same direction to b_v - xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); + //normal vector of unit vector with the same direction to b_v + xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); - //vector c in a_v_u and a_v_u_n co-ordinate system - xy c_a(c_v*a_v_u,c_v*a_v_u_n); + //vector c in a_v_u and a_v_u_n co-ordinate system + xy c_a(c_v*a_v_u,c_v*a_v_u_n); - //new vector from one node to the breakpoint - d - we have to calculate this one - xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); + //new vector from one node to the breakpoint - d - we have to calculate this one + xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); - my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); + my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); - my_points[0]=p[0]; - my_points[2]=p[1]; - - Gnome::Canvas::Points points; - for(int i=0;i<3;i++) + my_points[0]=p[0]; + my_points[2]=p[1]; + + Gnome::Canvas::Points points; + for(int i=0;i<3;i++) + { + points.push_back(my_points[i]); + } + property_points().set_value(points); + } + else { - points.push_back(my_points[i]); + //if distance is 0, segmentation would be occured + //in calculations, because of division by zero + //But we have luck: the edge cannot be seen in + //this case, so no update needed + set_arrow=false; } - property_points().set_value(points); } } if(set_arrow) @@ -115,8 +126,10 @@ xy center( my_points[1].get_x(), my_points[1].get_y() ); xy unit_vector_in_dir(target-center); + double length=sqrt( unit_vector_in_dir.normSquare() ); + // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <