Code

Fix snapping for constrained translation in the selector tool
authordvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 20 May 2008 20:58:56 +0000 (20:58 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 20 May 2008 20:58:56 +0000 (20:58 +0000)
src/seltrans.cpp
src/snap.cpp
src/snapper.h

index bdb0f794a84a48cc70e1dc26dddcc7da4904af04..2c021a724f98b147a25863ef38a96cbde2ec35b7 100644 (file)
@@ -1386,6 +1386,11 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
             /* Snap to things, and also constrain to horizontal or vertical movement */
 
             for (unsigned int dim = 0; dim < 2; dim++) {
+                // When doing a constrained translation, all points will move in the same direction, i.e.
+                // either horizontally or vertically. Therefore we only have to specify the direction of
+                // the constraint-line once. The constraint lines are parallel, but might not be colinear.
+                // Therefore we will have to set the point through which the constraint-line runs
+                // individually for each point to be snapped; this will be handled however by _snapTransformed()
                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                                          _bbox_points,
                                                          Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
@@ -1418,13 +1423,10 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
         g_assert(best_snapped_point.getDistance() == NR_HUGE);
         for (std::list<Inkscape::SnappedPoint>::const_iterator i = s.begin(); i != s.end(); i++) {
             if (i->getSnapped()) {
-                // std::cout << "moveTo() -> snapped to point: " << i->getPoint() << " with transformation: " << i->getTransformation();
                 if (i->getDistance() < best_snapped_point.getDistance()) {
                     best_snapped_point = *i;
                     dxy = i->getTransformation();
-                    // std::cout << " SEL";
                 }
-                //std::cout << std::endl;
             }
         }
         if (best_snapped_point.getSnapped()) {
index 46d043ec17e46b681b755268dd1a6e1883e602bc..09cdbbaba9571933b5af33eea4d3a352e8bd64f0 100644 (file)
@@ -432,7 +432,13 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
                 dedicated_constraint = Inkscape::Snapper::ConstraintLine(origin, (*i) - origin);
             } else if (transformation_type == STRETCH) { // when non-uniform stretching {
                 dedicated_constraint = Inkscape::Snapper::ConstraintLine((*i), component_vectors[dim]);
-            } // else: leave the original constraint, e.g. for constrained translation and skewing 
+            } else if (transformation_type == TRANSLATION) {
+                // When doing a constrained translation, all points will move in the same direction, i.e.
+                // either horizontally or vertically. The lines along which they move are therefore all
+                // parallel, but might not be colinear. Therefore we will have to set the point through
+                // which the constraint-line runs here, for each point individually. 
+                dedicated_constraint.setPoint(*i);
+            } // else: leave the original constraint, e.g. for skewing 
             if (transformation_type == SCALE && !uniform) {
                 g_warning("Non-uniform constrained scaling is not supported!");   
             }
index 1fb03d704b1edf8087a13e0ce4cbfd3eed7215bf..f79573990c285381b2593d84eee445099541ef68 100644 (file)
@@ -88,6 +88,11 @@ public:
         NR::Point getDirection() const {
             return _direction;
         }
+        
+        void setPoint(NR::Point const &p) {
+            _point = p;
+            _has_point = true;        
+        }
 
     private: