COIN-OR::LEMON - Graph Library

Changeset 1831:75ab76fc4bf2 in lemon-0.x for gui/gdc-broken_edge.cc


Ignore:
Timestamp:
11/23/05 17:24:59 (19 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2381
Message:

No segmentation fault caused by zero long edges.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/gdc-broken_edge.cc

    r1819 r1831  
    7474          double absb=sqrt(b_v.normSquare());
    7575
    76           //old vector from one node to the breakpoint - c
    77           xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
    78 
    79           //unit vector with the same direction to a_v
    80           xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
    81 
    82           //normal vector of unit vector with the same direction to a_v
    83           xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
    84 
    85           //unit vector with the same direction to b_v
    86           xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
    87 
    88           //normal vector of unit vector with the same direction to b_v
    89           xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
    90 
    91           //vector c in a_v_u and a_v_u_n co-ordinate system
    92           xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
    93 
    94           //new vector from one node to the breakpoint - d - we have to calculate this one
    95           xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
    96 
    97           my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
    98 
    99           my_points[0]=p[0];
    100           my_points[2]=p[1];
    101 
    102           Gnome::Canvas::Points points;
    103           for(int i=0;i<3;i++)
     76          if((absa!=0)&&(absb!=0))
    10477            {
    105               points.push_back(my_points[i]);
     78              //old vector from one node to the breakpoint - c
     79              xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
     80
     81              //unit vector with the same direction to a_v
     82              xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
     83
     84              //normal vector of unit vector with the same direction to a_v
     85              xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
     86
     87              //unit vector with the same direction to b_v
     88              xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
     89
     90              //normal vector of unit vector with the same direction to b_v
     91              xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
     92
     93              //vector c in a_v_u and a_v_u_n co-ordinate system
     94              xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
     95
     96              //new vector from one node to the breakpoint - d - we have to calculate this one
     97              xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
     98
     99              my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
     100
     101              my_points[0]=p[0];
     102              my_points[2]=p[1];
     103         
     104              Gnome::Canvas::Points points;
     105              for(int i=0;i<3;i++)
     106                {
     107                  points.push_back(my_points[i]);
     108                }
     109              property_points().set_value(points);
    106110            }
    107           property_points().set_value(points);
     111          else
     112            {
     113              //if distance is 0, segmentation would be occured
     114              //in calculations, because of division by zero
     115              //But we have luck: the edge cannot be seen in
     116              //this case, so no update needed
     117              set_arrow=false;
     118            }
    108119        }
    109120    }
     
    116127
    117128      xy<gdouble> unit_vector_in_dir(target-center);
     129      double length=sqrt( unit_vector_in_dir.normSquare() );
     130
    118131      //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
    119       unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
     132      unit_vector_in_dir/=length;
    120133      //       std::cout << " = " << unit_vector_in_dir << std::endl;
    121134
     
    141154      xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
    142155         
    143       //       std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
     156      //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
    144157
    145158      Gnome::Canvas::Points arrow_points;
Note: See TracChangeset for help on using the changeset viewer.