gui/gdc-broken_edge.cc
changeset 1854 a68d4f93b1fb
parent 1819 fd82adfbe905
child 1860 27a9a75b957b
equal deleted inserted replaced
0:3a2d772af6b6 1:92e9dab7739b
    71 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
    71 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
    72 
    72 
    73 	  double absa=sqrt(a_v.normSquare());
    73 	  double absa=sqrt(a_v.normSquare());
    74 	  double absb=sqrt(b_v.normSquare());
    74 	  double absb=sqrt(b_v.normSquare());
    75 
    75 
    76 	  //old vector from one node to the breakpoint - c
    76 	  if((absa!=0)&&(absb!=0))
    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++)
       
   104 	    {
    77 	    {
   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);
   106 	    }
   110 	    }
   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 	    }
   108 	}
   119 	}
   109     }
   120     }
   110   if(set_arrow)
   121   if(set_arrow)
   111     {
   122     {
   112       //calculating coordinates of the direction indicator arrow
   123       //calculating coordinates of the direction indicator arrow
   113 
   124 
   114       xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
   125       xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
   115       xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
   126       xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
   116 
   127 
   117       xy<gdouble> unit_vector_in_dir(target-center);
   128       xy<gdouble> unit_vector_in_dir(target-center);
       
   129       double length=sqrt( unit_vector_in_dir.normSquare() );
       
   130 
   118       //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
   131       //       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;
   120       //       std::cout << " = " << unit_vector_in_dir << std::endl;
   133       //       std::cout << " = " << unit_vector_in_dir << std::endl;
   121 
   134 
   122       xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
   135       xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
   123       //       std::cout << unit_norm_vector << std::endl;
   136       //       std::cout << unit_norm_vector << std::endl;
   124 
   137 
   138       xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
   151       xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
   139       xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
   152       xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
   140       xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
   153       xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
   141       xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
   154       xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
   142 	 
   155 	 
   143       //       std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
   156       //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
   144 
   157 
   145       Gnome::Canvas::Points arrow_points;
   158       Gnome::Canvas::Points arrow_points;
   146       arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
   159       arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
   147       arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
   160       arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
   148       arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
   161       arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );