Shape keeping movement is implemented, at last. Many thanks to Alpar.
authorhegyi
Thu, 06 Oct 2005 12:32:06 +0000
changeset 171466c89fe52d4e
parent 1713 49d22d34d95f
child 1715 e71778873dd0
Shape keeping movement is implemented, at last. Many thanks to Alpar.
gui/broken_edge.cc
     1.1 --- a/gui/broken_edge.cc	Thu Oct 06 10:28:45 2005 +0000
     1.2 +++ b/gui/broken_edge.cc	Thu Oct 06 12:32:06 2005 +0000
     1.3 @@ -46,194 +46,66 @@
     1.4      {
     1.5        //arrow keeps its position-left button
     1.6  
     1.7 -      if(p.size()==2)
     1.8 -      	{
     1.9 -      	  Gnome::Canvas::Points points;
    1.10 -      	  my_points[0]=p[0];
    1.11 -      	  my_points[2]=p[1];
    1.12 -      	  for(int i=0;i<3;i++)
    1.13 -      	    {
    1.14 -      	      points.push_back(my_points[i]);
    1.15 -      	    }
    1.16 -      	  property_points().set_value(points);
    1.17 -      	}
    1.18 +//       if(p.size()==2)
    1.19 +//       	{
    1.20 +//       	  Gnome::Canvas::Points points;
    1.21 +//       	  my_points[0]=p[0];
    1.22 +//       	  my_points[2]=p[1];
    1.23 +//       	  for(int i=0;i<3;i++)
    1.24 +//       	    {
    1.25 +//       	      points.push_back(my_points[i]);
    1.26 +//       	    }
    1.27 +//       	  property_points().set_value(points);
    1.28 +//       	}
    1.29        set_arrow=true;
    1.30  
    1.31        //////////////////////////////////////////////////////////////////////////////////////////////////////
    1.32 -      /////////// kepps shape-with angles
    1.33 +      /////////// keeps shape-with scalar multiplication - version 2.
    1.34        //////////////////////////////////////////////////////////////////////////////////////////////////////
    1.35  
    1.36 +      if(p.size()==2)
    1.37 +      	{
    1.38 +	  //old vector from one to the other node - a
    1.39 +	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
    1.40 +	  //new vector from one to the other node - b
    1.41 +	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
    1.42  
    1.43 -//       //old vector from one to the other node
    1.44 -//       xy<double> o_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
    1.45 -//       //projection of the old vector to positive x axis
    1.46 -//       xy<double> o_x_p2p(fabs(o_p2p.x),0);
    1.47 -//       //length of p2p vector
    1.48 -//       double o_l_p2p=sqrt( o_p2p.normSquare() );
    1.49 -//       if(o_p2p.x<0)
    1.50 -// 	{
    1.51 -// 	  o_l_p2p*=-1;
    1.52 -// 	}
    1.53 -//       //length of projection of p2p vector
    1.54 -//       double o_l_x_p2p=sqrt( o_x_p2p.normSquare() );
    1.55 -//       //old angle of p2p vector to the x axis
    1.56 -//       double o_a_p2p=acos(o_l_x_p2p/o_l_p2p);
    1.57 -//       if(o_p2p.y>0)
    1.58 -// 	{
    1.59 -// 	  o_a_p2p=2*M_PI-o_a_p2p;
    1.60 -// 	}
    1.61 +	  double absa=sqrt(a_v.normSquare());
    1.62 +	  double absb=sqrt(b_v.normSquare());
    1.63  
    1.64 -//       //old vector from first node to the breakpoint
    1.65 -//       xy<double> o_1b((my_points[1].get_x()-my_points[0].get_x()),(my_points[1].get_y()-my_points[0].get_y()));
    1.66 -//       //projection of the old node-breakpoint vector to positive x axis
    1.67 -//       xy<double> o_x_1b(fabs(o_1b.x),0);
    1.68 -//       //length of 1b vector
    1.69 -//       double o_l_1b=sqrt( o_1b.normSquare() );
    1.70 -//       if(o_1b.x<0)
    1.71 -// 	{
    1.72 -// 	  o_l_1b*=-1;
    1.73 -// 	}
    1.74 -//       //length of projection of 1b vector
    1.75 -//       double o_l_x_1b=sqrt( o_x_1b.normSquare() );
    1.76 -//       //old angle of 1b vector to the x axis
    1.77 -//       double o_a_1b=acos(o_l_x_1b/o_l_1b);
    1.78 -//       if(o_1b.y>0)
    1.79 -// 	{
    1.80 -// 	  o_a_1b=2*M_PI-o_a_1b;
    1.81 -// 	}
    1.82 +	  //old vector from one node to the breakpoint - c
    1.83 +	  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.84  
    1.85 -//       if(p.size()==2)
    1.86 -//       	{
    1.87 -// 	  set_arrow=true;
    1.88 +	  //unit vector with the same direction to a_v
    1.89 +	  xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
    1.90  
    1.91 -//       	  my_points[0]=p[0];
    1.92 -//       	  my_points[2]=p[1];
    1.93 +	  //normal vector of unit vector with the same direction to a_v
    1.94 +	  xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
    1.95  
    1.96 -// 	  //new vector from one to the other node
    1.97 -// 	  xy<double> n_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
    1.98 -// 	  //projection of the new vector to positive x axis
    1.99 -// 	  xy<double> n_x_p2p(fabs(n_p2p.x),0);
   1.100 -// 	  //length of p2p vector
   1.101 -// 	  double n_l_p2p=sqrt( n_p2p.normSquare() );
   1.102 -// 	  if(n_p2p.x<0)
   1.103 -// 	    {
   1.104 -// 	      n_l_p2p*=-1;
   1.105 -// 	    }
   1.106 -// 	  //length of projection of p2p vector
   1.107 -// 	  double n_l_x_p2p=sqrt( n_x_p2p.normSquare() );
   1.108 -// 	  //new angle of p2p vector to the x axis
   1.109 -// 	  double n_a_p2p=acos(n_l_x_p2p/n_l_p2p);
   1.110 -// 	  if(n_p2p.y>0)
   1.111 -// 	    {
   1.112 -// 	      n_a_p2p=2*M_PI-n_a_p2p;
   1.113 -// 	    }
   1.114 +	  //unit vector with the same direction to b_v
   1.115 +	  xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
   1.116  
   1.117 -// 	  //new angle of 1b vector to the x axis
   1.118 -// 	  double n_a_1b=o_a_1b+n_a_p2p-o_a_p2p;
   1.119 +	  //normal vector of unit vector with the same direction to b_v
   1.120 +	  xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
   1.121  
   1.122 -// 	  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;
   1.123 -// 	  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;
   1.124 +	  //vector c in a_v_u and a_v_u_n co-ordinate system
   1.125 +	  xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
   1.126  
   1.127 -// // 	  std::cout << o_p2p << " " << n_p2p << std::endl;
   1.128 +	  //new vector from one node to the breakpoint - d - we have to calculate this one
   1.129 +	  xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
   1.130  
   1.131 -// 	  if((n_a_1b>M_PI*3/2)||(n_a_1b<M_PI/2))
   1.132 -// 	    {
   1.133 -// 	      std::cout << "jobb terfel" << std::endl;
   1.134 -// 	      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);
   1.135 -// 	    }
   1.136 -// 	  else if((n_a_1b<M_PI*3/2)&&(n_a_1b>M_PI/2))
   1.137 -// 	    {
   1.138 -// 	      std::cout << "bal terfel" << std::endl;
   1.139 -// 	      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);
   1.140 -// 	    }
   1.141 -// 	  else
   1.142 -// 	    {
   1.143 -// 	      std::cout << "y tengely" << std::endl;
   1.144 -// 	      double new_y=my_points[1].get_y();
   1.145 -// 	      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);
   1.146 -// 	    }
   1.147 +	  my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
   1.148  
   1.149 -// 	  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;
   1.150 +      	  my_points[0]=p[0];
   1.151 +      	  my_points[2]=p[1];
   1.152  
   1.153 -
   1.154 -// // 	  if(o_1b.x*o_1b.y>0)
   1.155 -// // 	    {
   1.156 -// // 	      if(n_p2p.x>0)
   1.157 -// // 		{
   1.158 -// // 		  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);
   1.159 -// // 		}
   1.160 -// // 	      else
   1.161 -// // 		{
   1.162 -// // 		  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);
   1.163 -// // 		}
   1.164 -// // 	    }
   1.165 -// // 	  else if(o_1b.x*o_1b.y<0)
   1.166 -// // 	    {
   1.167 -// // 	      if(n_p2p.x>0)
   1.168 -// // 		{
   1.169 -// // 		  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);
   1.170 -// // 		}
   1.171 -// // 	      else
   1.172 -// // 		{
   1.173 -// // 		  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);
   1.174 -// // 		}
   1.175 -// // 	    }
   1.176 -// // 	  else
   1.177 -// // 	    {
   1.178 -// // 	    }
   1.179 -
   1.180 -      //////////////////////////////////////////////////////////////////////////////////////////////////////
   1.181 -      /////////// kepps shape-with scalar multiplication
   1.182 -      //////////////////////////////////////////////////////////////////////////////////////////////////////
   1.183 -
   1.184 -//       if(p.size()==2)
   1.185 -//       	{
   1.186 -// 	  //old vector from one to the other node - a
   1.187 -// 	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
   1.188 -// 	  //new vector from one to the other node - b
   1.189 -// 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
   1.190 -
   1.191 -// 	  //old vector from one node to the breakpoint - c
   1.192 -// 	  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.193 -
   1.194 -// 	  //new vector from one node to the breakpoint - d - we have to calculate this one
   1.195 -// 	  xy<double> d_v;
   1.196 -
   1.197 -// 	  //scalar product of a and b (old and new vector from first point to the other)
   1.198 -// 	  double sab=a_v*b_v;
   1.199 -// 	  //scalar product of c and d (old and new vector from first point to breakpoint)
   1.200 -// 	  double scd=sab*c_v.normSquare()/a_v.normSquare();
   1.201 -
   1.202 -// 	  std::cout<<" a " << a_v<<" b " <<b_v<<" c " <<c_v<<" sab " <<sab<<" scd "<<scd<<std::endl;
   1.203 -
   1.204 -// 	  double a=c_v.normSquare();
   1.205 -// 	  double b=2*scd*c_v.y;
   1.206 -// 	  double c=scd*scd-b_v.normSquare()/a_v.normSquare()*c_v.normSquare()*c_v.x*c_v.x;
   1.207 -
   1.208 -// 	  std::cout<<" a " << a<<" b " <<b<<" c " <<c<<std::endl;
   1.209 -
   1.210 -// 	  d_v.y=(-b-sqrt(b*b-4*a*c))/2/a;
   1.211 -
   1.212 -// 	  if(c_v.x!=0)
   1.213 -// 	    {
   1.214 -// 	      d_v.x=(scd-c_v.y*d_v.y)/c_v.x;
   1.215 -// 	    }
   1.216 -// 	  else
   1.217 -// 	    {
   1.218 -// 	      d_v.x=my_points[1].get_x();
   1.219 -// 	    }
   1.220 -
   1.221 -// 	  std::cout<<" d " << d_v<<std::endl;
   1.222 -
   1.223 -// 	  my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
   1.224 -
   1.225 -// 	  Gnome::Canvas::Points points;
   1.226 -// 	  for(int i=0;i<3;i++)
   1.227 -// 	    {
   1.228 -// 	      points.push_back(my_points[i]);
   1.229 -// 	    }
   1.230 -// 	  property_points().set_value(points);
   1.231 -// 	}
   1.232 +	  Gnome::Canvas::Points points;
   1.233 +	  for(int i=0;i<3;i++)
   1.234 +	    {
   1.235 +	      points.push_back(my_points[i]);
   1.236 +	    }
   1.237 +	  property_points().set_value(points);
   1.238 +	}
   1.239      }
   1.240    if(set_arrow)
   1.241      {