gui/broken_edge.cc
changeset 1787 932b8490caf0
parent 1645 4a04bb856ac7
equal deleted inserted replaced
11:329d94da986f 12:c1ea19ef1021
    44     }
    44     }
    45   else
    45   else
    46     {
    46     {
    47       //arrow keeps its position-left button
    47       //arrow keeps its position-left button
    48 
    48 
       
    49 //       if(p.size()==2)
       
    50 //       	{
       
    51 //       	  Gnome::Canvas::Points points;
       
    52 //       	  my_points[0]=p[0];
       
    53 //       	  my_points[2]=p[1];
       
    54 //       	  for(int i=0;i<3;i++)
       
    55 //       	    {
       
    56 //       	      points.push_back(my_points[i]);
       
    57 //       	    }
       
    58 //       	  property_points().set_value(points);
       
    59 //       	}
       
    60       set_arrow=true;
       
    61 
       
    62       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    63       /////////// keeps shape-with scalar multiplication - version 2.
       
    64       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    65 
    49       if(p.size()==2)
    66       if(p.size()==2)
    50       	{
    67       	{
    51       	  Gnome::Canvas::Points points;
    68 	  //old vector from one to the other node - a
       
    69 	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
    70 	  //new vector from one to the other node - b
       
    71 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
       
    72 
       
    73 	  double absa=sqrt(a_v.normSquare());
       
    74 	  double absb=sqrt(b_v.normSquare());
       
    75 
       
    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 
    52       	  my_points[0]=p[0];
    99       	  my_points[0]=p[0];
    53       	  my_points[2]=p[1];
   100       	  my_points[2]=p[1];
    54       	  for(int i=0;i<3;i++)
   101 
    55       	    {
   102 	  Gnome::Canvas::Points points;
    56       	      points.push_back(my_points[i]);
   103 	  for(int i=0;i<3;i++)
    57       	    }
   104 	    {
    58       	  property_points().set_value(points);
   105 	      points.push_back(my_points[i]);
    59       	}
   106 	    }
    60       set_arrow=true;
   107 	  property_points().set_value(points);
    61 
   108 	}
    62       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    63       /////////// kepps shape-with angles
       
    64       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    65 
       
    66 
       
    67 //       //old vector from one to the other node
       
    68 //       xy<double> o_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
    69 //       //projection of the old vector to positive x axis
       
    70 //       xy<double> o_x_p2p(fabs(o_p2p.x),0);
       
    71 //       //length of p2p vector
       
    72 //       double o_l_p2p=sqrt( o_p2p.normSquare() );
       
    73 //       if(o_p2p.x<0)
       
    74 // 	{
       
    75 // 	  o_l_p2p*=-1;
       
    76 // 	}
       
    77 //       //length of projection of p2p vector
       
    78 //       double o_l_x_p2p=sqrt( o_x_p2p.normSquare() );
       
    79 //       //old angle of p2p vector to the x axis
       
    80 //       double o_a_p2p=acos(o_l_x_p2p/o_l_p2p);
       
    81 //       if(o_p2p.y>0)
       
    82 // 	{
       
    83 // 	  o_a_p2p=2*M_PI-o_a_p2p;
       
    84 // 	}
       
    85 
       
    86 //       //old vector from first node to the breakpoint
       
    87 //       xy<double> o_1b((my_points[1].get_x()-my_points[0].get_x()),(my_points[1].get_y()-my_points[0].get_y()));
       
    88 //       //projection of the old node-breakpoint vector to positive x axis
       
    89 //       xy<double> o_x_1b(fabs(o_1b.x),0);
       
    90 //       //length of 1b vector
       
    91 //       double o_l_1b=sqrt( o_1b.normSquare() );
       
    92 //       if(o_1b.x<0)
       
    93 // 	{
       
    94 // 	  o_l_1b*=-1;
       
    95 // 	}
       
    96 //       //length of projection of 1b vector
       
    97 //       double o_l_x_1b=sqrt( o_x_1b.normSquare() );
       
    98 //       //old angle of 1b vector to the x axis
       
    99 //       double o_a_1b=acos(o_l_x_1b/o_l_1b);
       
   100 //       if(o_1b.y>0)
       
   101 // 	{
       
   102 // 	  o_a_1b=2*M_PI-o_a_1b;
       
   103 // 	}
       
   104 
       
   105 //       if(p.size()==2)
       
   106 //       	{
       
   107 // 	  set_arrow=true;
       
   108 
       
   109 //       	  my_points[0]=p[0];
       
   110 //       	  my_points[2]=p[1];
       
   111 
       
   112 // 	  //new vector from one to the other node
       
   113 // 	  xy<double> n_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
   114 // 	  //projection of the new vector to positive x axis
       
   115 // 	  xy<double> n_x_p2p(fabs(n_p2p.x),0);
       
   116 // 	  //length of p2p vector
       
   117 // 	  double n_l_p2p=sqrt( n_p2p.normSquare() );
       
   118 // 	  if(n_p2p.x<0)
       
   119 // 	    {
       
   120 // 	      n_l_p2p*=-1;
       
   121 // 	    }
       
   122 // 	  //length of projection of p2p vector
       
   123 // 	  double n_l_x_p2p=sqrt( n_x_p2p.normSquare() );
       
   124 // 	  //new angle of p2p vector to the x axis
       
   125 // 	  double n_a_p2p=acos(n_l_x_p2p/n_l_p2p);
       
   126 // 	  if(n_p2p.y>0)
       
   127 // 	    {
       
   128 // 	      n_a_p2p=2*M_PI-n_a_p2p;
       
   129 // 	    }
       
   130 
       
   131 // 	  //new angle of 1b vector to the x axis
       
   132 // 	  double n_a_1b=o_a_1b+n_a_p2p-o_a_p2p;
       
   133 
       
   134 // 	  std::cout << " p2p regi: " << o_a_p2p/M_PI*180 << " uj: " << n_a_p2p/M_PI*180-(int)n_a_p2p/M_PI*180 << std::endl;
       
   135 // 	  std::cout << " 1b regi: " << o_a_1b/M_PI*180 << " uj: " << n_a_1b/M_PI*180-(int)n_a_1b/M_PI*180 << std::endl;
       
   136 
       
   137 // // 	  std::cout << o_p2p << " " << n_p2p << std::endl;
       
   138 
       
   139 // 	  if((n_a_1b>M_PI*3/2)||(n_a_1b<M_PI/2))
       
   140 // 	    {
       
   141 // 	      std::cout << "jobb terfel" << std::endl;
       
   142 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   143 // 	    }
       
   144 // 	  else if((n_a_1b<M_PI*3/2)&&(n_a_1b>M_PI/2))
       
   145 // 	    {
       
   146 // 	      std::cout << "bal terfel" << std::endl;
       
   147 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   148 // 	    }
       
   149 // 	  else
       
   150 // 	    {
       
   151 // 	      std::cout << "y tengely" << std::endl;
       
   152 // 	      double new_y=my_points[1].get_y();
       
   153 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,new_y);
       
   154 // 	    }
       
   155 
       
   156 // 	  std::cout << "alap: " << p[0] << " eredeti hossz: " << o_l_1b << " nagy uj: " << n_l_p2p << " nagy regi: " << o_l_p2p << " a*b/c " << o_l_1b*n_l_p2p/o_l_p2p << " eredmeny: " << my_points[1] << std::endl;
       
   157 
       
   158 
       
   159 // // 	  if(o_1b.x*o_1b.y>0)
       
   160 // // 	    {
       
   161 // // 	      if(n_p2p.x>0)
       
   162 // // 		{
       
   163 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   164 // // 		}
       
   165 // // 	      else
       
   166 // // 		{
       
   167 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   168 // // 		}
       
   169 // // 	    }
       
   170 // // 	  else if(o_1b.x*o_1b.y<0)
       
   171 // // 	    {
       
   172 // // 	      if(n_p2p.x>0)
       
   173 // // 		{
       
   174 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   175 // // 		}
       
   176 // // 	      else
       
   177 // // 		{
       
   178 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   179 // // 		}
       
   180 // // 	    }
       
   181 // // 	  else
       
   182 // // 	    {
       
   183 // // 	    }
       
   184 
       
   185       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   186       /////////// kepps shape-with scalar multiplication
       
   187       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   188 
       
   189 //       if(p.size()==2)
       
   190 //       	{
       
   191 // 	  //old vector from one to the other node - a
       
   192 // 	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
   193 // 	  //new vector from one to the other node - b
       
   194 // 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
       
   195 
       
   196 // 	  //old vector from one node to the breakpoint - c
       
   197 // 	  xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
       
   198 
       
   199 // 	  //new vector from one node to the breakpoint - d - we have to calculate this one
       
   200 // 	  xy<double> d_v;
       
   201 
       
   202 // 	  //scalar product of a and b (old and new vector from first point to the other)
       
   203 // 	  double sab=a_v*b_v;
       
   204 // 	  //scalar product of c and d (old and new vector from first point to breakpoint)
       
   205 // 	  double scd=sab*c_v.normSquare()/a_v.normSquare();
       
   206 
       
   207 // 	  std::cout<<" a " << a_v<<" b " <<b_v<<" c " <<c_v<<" sab " <<sab<<" scd "<<scd<<std::endl;
       
   208 
       
   209 // 	  double a=c_v.normSquare();
       
   210 // 	  double b=2*scd*c_v.y;
       
   211 // 	  double c=scd*scd-b_v.normSquare()/a_v.normSquare()*c_v.normSquare()*c_v.x*c_v.x;
       
   212 
       
   213 // 	  std::cout<<" a " << a<<" b " <<b<<" c " <<c<<std::endl;
       
   214 
       
   215 // 	  d_v.y=(-b-sqrt(b*b-4*a*c))/2/a;
       
   216 
       
   217 // 	  if(c_v.x!=0)
       
   218 // 	    {
       
   219 // 	      d_v.x=(scd-c_v.y*d_v.y)/c_v.x;
       
   220 // 	    }
       
   221 // 	  else
       
   222 // 	    {
       
   223 // 	      d_v.x=my_points[1].get_x();
       
   224 // 	    }
       
   225 
       
   226 // 	  std::cout<<" d " << d_v<<std::endl;
       
   227 
       
   228 // 	  my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
       
   229 
       
   230 // 	  Gnome::Canvas::Points points;
       
   231 // 	  for(int i=0;i<3;i++)
       
   232 // 	    {
       
   233 // 	      points.push_back(my_points[i]);
       
   234 // 	    }
       
   235 // 	  property_points().set_value(points);
       
   236 // 	}
       
   237     }
   109     }
   238   if(set_arrow)
   110   if(set_arrow)
   239     {
   111     {
   240       //calculating coordinates of the direction indicator arrow
   112       //calculating coordinates of the direction indicator arrow
   241 
   113