# HG changeset patch # User hegyi # Date 1128601926 0 # Node ID 66c89fe52d4e5326d2624b7cd79b67da2ac78c67 # Parent 49d22d34d95f975d0c634e3c60819b502f44e0d7 Shape keeping movement is implemented, at last. Many thanks to Alpar. diff -r 49d22d34d95f -r 66c89fe52d4e gui/broken_edge.cc --- a/gui/broken_edge.cc Thu Oct 06 10:28:45 2005 +0000 +++ b/gui/broken_edge.cc Thu Oct 06 12:32:06 2005 +0000 @@ -46,194 +46,66 @@ { //arrow keeps its position-left button - if(p.size()==2) - { - Gnome::Canvas::Points points; - my_points[0]=p[0]; - my_points[2]=p[1]; - for(int i=0;i<3;i++) - { - points.push_back(my_points[i]); - } - property_points().set_value(points); - } +// if(p.size()==2) +// { +// Gnome::Canvas::Points points; +// my_points[0]=p[0]; +// my_points[2]=p[1]; +// for(int i=0;i<3;i++) +// { +// points.push_back(my_points[i]); +// } +// property_points().set_value(points); +// } set_arrow=true; ////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////// kepps shape-with angles + /////////// keeps shape-with scalar multiplication - version 2. ////////////////////////////////////////////////////////////////////////////////////////////////////// + if(p.size()==2) + { + //old vector from one to the other node - a + xy a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); + //new vector from one to the other node - b + xy b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y()); -// //old vector from one to the other node -// xy o_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); -// //projection of the old vector to positive x axis -// xy o_x_p2p(fabs(o_p2p.x),0); -// //length of p2p vector -// double o_l_p2p=sqrt( o_p2p.normSquare() ); -// if(o_p2p.x<0) -// { -// o_l_p2p*=-1; -// } -// //length of projection of p2p vector -// double o_l_x_p2p=sqrt( o_x_p2p.normSquare() ); -// //old angle of p2p vector to the x axis -// double o_a_p2p=acos(o_l_x_p2p/o_l_p2p); -// if(o_p2p.y>0) -// { -// o_a_p2p=2*M_PI-o_a_p2p; -// } + double absa=sqrt(a_v.normSquare()); + double absb=sqrt(b_v.normSquare()); -// //old vector from first node to the breakpoint -// xy o_1b((my_points[1].get_x()-my_points[0].get_x()),(my_points[1].get_y()-my_points[0].get_y())); -// //projection of the old node-breakpoint vector to positive x axis -// xy o_x_1b(fabs(o_1b.x),0); -// //length of 1b vector -// double o_l_1b=sqrt( o_1b.normSquare() ); -// if(o_1b.x<0) -// { -// o_l_1b*=-1; -// } -// //length of projection of 1b vector -// double o_l_x_1b=sqrt( o_x_1b.normSquare() ); -// //old angle of 1b vector to the x axis -// double o_a_1b=acos(o_l_x_1b/o_l_1b); -// if(o_1b.y>0) -// { -// o_a_1b=2*M_PI-o_a_1b; -// } + //old vector from one node to the breakpoint - c + xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); -// if(p.size()==2) -// { -// set_arrow=true; + //unit vector with the same direction to a_v + xy 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 a_v_u_n(((-1)*a_v_u.y),a_v_u.x); -// //new vector from one to the other node -// xy n_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); -// //projection of the new vector to positive x axis -// xy n_x_p2p(fabs(n_p2p.x),0); -// //length of p2p vector -// double n_l_p2p=sqrt( n_p2p.normSquare() ); -// if(n_p2p.x<0) -// { -// n_l_p2p*=-1; -// } -// //length of projection of p2p vector -// double n_l_x_p2p=sqrt( n_x_p2p.normSquare() ); -// //new angle of p2p vector to the x axis -// double n_a_p2p=acos(n_l_x_p2p/n_l_p2p); -// if(n_p2p.y>0) -// { -// n_a_p2p=2*M_PI-n_a_p2p; -// } + //unit vector with the same direction to b_v + xy b_v_u(b_v.x/absb,b_v.y/absb); -// //new angle of 1b vector to the x axis -// double n_a_1b=o_a_1b+n_a_p2p-o_a_p2p; + //normal vector of unit vector with the same direction to b_v + xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); -// 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; -// 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; + //vector c in a_v_u and a_v_u_n co-ordinate system + xy c_a(c_v*a_v_u,c_v*a_v_u_n); -// // std::cout << o_p2p << " " << n_p2p << std::endl; + //new vector from one node to the breakpoint - d - we have to calculate this one + xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); -// if((n_a_1b>M_PI*3/2)||(n_a_1bM_PI/2)) -// { -// std::cout << "bal terfel" << std::endl; -// 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); -// } -// else -// { -// std::cout << "y tengely" << std::endl; -// double new_y=my_points[1].get_y(); -// 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); -// } + my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); -// 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; + my_points[0]=p[0]; + my_points[2]=p[1]; - -// // if(o_1b.x*o_1b.y>0) -// // { -// // if(n_p2p.x>0) -// // { -// // 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); -// // } -// // else -// // { -// // 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); -// // } -// // } -// // else if(o_1b.x*o_1b.y<0) -// // { -// // if(n_p2p.x>0) -// // { -// // 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); -// // } -// // else -// // { -// // 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); -// // } -// // } -// // else -// // { -// // } - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////// kepps shape-with scalar multiplication - ////////////////////////////////////////////////////////////////////////////////////////////////////// - -// if(p.size()==2) -// { -// //old vector from one to the other node - a -// xy a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); -// //new vector from one to the other node - b -// xy b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y()); - -// //old vector from one node to the breakpoint - c -// xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); - -// //new vector from one node to the breakpoint - d - we have to calculate this one -// xy d_v; - -// //scalar product of a and b (old and new vector from first point to the other) -// double sab=a_v*b_v; -// //scalar product of c and d (old and new vector from first point to breakpoint) -// double scd=sab*c_v.normSquare()/a_v.normSquare(); - -// std::cout<<" a " << a_v<<" b " <