[Lemon-commits] [lemon_svn] hegyi: r2381 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:52:14 CET 2006
Author: hegyi
Date: Wed Nov 23 17:24:59 2005
New Revision: 2381
Modified:
hugo/trunk/gui/gdc-broken_edge.cc
Log:
No segmentation fault caused by zero long edges.
Modified: hugo/trunk/gui/gdc-broken_edge.cc
==============================================================================
--- hugo/trunk/gui/gdc-broken_edge.cc (original)
+++ hugo/trunk/gui/gdc-broken_edge.cc Wed Nov 23 17:24:59 2005
@@ -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<double> 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<double> a_v_u(a_v.x/absa,a_v.y/absa);
-
- //normal vector of unit vector with the same direction to a_v
- xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
-
- //unit vector with the same direction to b_v
- xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
-
- //normal vector of unit vector with the same direction to b_v
- xy<double> 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<double> 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<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
+ if((absa!=0)&&(absb!=0))
+ {
+ //old vector from one node to the breakpoint - c
+ xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
- my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
+ //unit vector with the same direction to a_v
+ xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
- my_points[0]=p[0];
- my_points[2]=p[1];
+ //normal vector of unit vector with the same direction to a_v
+ xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
- Gnome::Canvas::Points points;
- for(int i=0;i<3;i++)
+ //unit vector with the same direction to b_v
+ xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
+
+ //normal vector of unit vector with the same direction to b_v
+ xy<double> 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<double> 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<double> 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[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<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
xy<gdouble> unit_vector_in_dir(target-center);
+ double length=sqrt( unit_vector_in_dir.normSquare() );
+
// std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <<unit_vector_in_dir.normSquare() ;
- unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
+ unit_vector_in_dir/=length;
// std::cout << " = " << unit_vector_in_dir << std::endl;
xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
@@ -140,7 +153,7 @@
xy<gdouble> cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
- // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
+ //std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
Gnome::Canvas::Points arrow_points;
arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );
More information about the Lemon-commits
mailing list