1.1 --- a/gdc-broken_edge.cc Tue Nov 22 14:35:33 2005 +0000
1.2 +++ b/gdc-broken_edge.cc Wed Nov 23 16:24:59 2005 +0000
1.3 @@ -73,38 +73,49 @@
1.4 double absa=sqrt(a_v.normSquare());
1.5 double absb=sqrt(b_v.normSquare());
1.6
1.7 - //old vector from one node to the breakpoint - c
1.8 - xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
1.9 + if((absa!=0)&&(absb!=0))
1.10 + {
1.11 + //old vector from one node to the breakpoint - c
1.12 + xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
1.13
1.14 - //unit vector with the same direction to a_v
1.15 - xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
1.16 + //unit vector with the same direction to a_v
1.17 + xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
1.18
1.19 - //normal vector of unit vector with the same direction to a_v
1.20 - xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
1.21 + //normal vector of unit vector with the same direction to a_v
1.22 + xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
1.23
1.24 - //unit vector with the same direction to b_v
1.25 - xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
1.26 + //unit vector with the same direction to b_v
1.27 + xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
1.28
1.29 - //normal vector of unit vector with the same direction to b_v
1.30 - xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
1.31 + //normal vector of unit vector with the same direction to b_v
1.32 + xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
1.33
1.34 - //vector c in a_v_u and a_v_u_n co-ordinate system
1.35 - xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
1.36 + //vector c in a_v_u and a_v_u_n co-ordinate system
1.37 + xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
1.38
1.39 - //new vector from one node to the breakpoint - d - we have to calculate this one
1.40 - xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
1.41 + //new vector from one node to the breakpoint - d - we have to calculate this one
1.42 + xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
1.43
1.44 - my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
1.45 + my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
1.46
1.47 - my_points[0]=p[0];
1.48 - my_points[2]=p[1];
1.49 -
1.50 - Gnome::Canvas::Points points;
1.51 - for(int i=0;i<3;i++)
1.52 + my_points[0]=p[0];
1.53 + my_points[2]=p[1];
1.54 +
1.55 + Gnome::Canvas::Points points;
1.56 + for(int i=0;i<3;i++)
1.57 + {
1.58 + points.push_back(my_points[i]);
1.59 + }
1.60 + property_points().set_value(points);
1.61 + }
1.62 + else
1.63 {
1.64 - points.push_back(my_points[i]);
1.65 + //if distance is 0, segmentation would be occured
1.66 + //in calculations, because of division by zero
1.67 + //But we have luck: the edge cannot be seen in
1.68 + //this case, so no update needed
1.69 + set_arrow=false;
1.70 }
1.71 - property_points().set_value(points);
1.72 }
1.73 }
1.74 if(set_arrow)
1.75 @@ -115,8 +126,10 @@
1.76 xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
1.77
1.78 xy<gdouble> unit_vector_in_dir(target-center);
1.79 + double length=sqrt( unit_vector_in_dir.normSquare() );
1.80 +
1.81 // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <<unit_vector_in_dir.normSquare() ;
1.82 - unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
1.83 + unit_vector_in_dir/=length;
1.84 // std::cout << " = " << unit_vector_in_dir << std::endl;
1.85
1.86 xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
1.87 @@ -140,7 +153,7 @@
1.88 xy<gdouble> cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
1.89 xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
1.90
1.91 - // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
1.92 + //std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
1.93
1.94 Gnome::Canvas::Points arrow_points;
1.95 arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );