Code

Replace freeSnapSkew() by constrainedSnapSkew(). There is no such thing as freely...
authordvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 1 May 2008 18:24:38 +0000 (18:24 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Thu, 1 May 2008 18:24:38 +0000 (18:24 +0000)
src/seltrans.cpp
src/snap.cpp
src/snap.h

index db1135785d456a3f04be0ecccb0fc2d4720e2f1f..3c333c11bd6352f10b3f879b0bdb8750364ca34b 100644 (file)
@@ -1150,15 +1150,15 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
         SnapManager &m = _desktop->namedview->snap_manager;
         m.setup(NULL, _items_const);
 
-        //TODO: While skewing, scaling in the opposite direction by integer multiples is also allowed. This is not handled though by freeSnapSkew / _snapTransformed yet!
-        //TODO: We need a constrainedSnapSkew instead of a freeSnapSkew
-        Inkscape::SnappedPoint bb = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, skew[dim_a], _origin, dim_b);
-        Inkscape::SnappedPoint sn = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, skew[dim_a], _origin, dim_b);
+        Inkscape::Snapper::ConstraintLine const constraint(component_vectors[dim_b]);
+        NR::Point const s(skew[dim_a], scale[dim_a]);
+        Inkscape::SnappedPoint bb = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, constraint, s, _origin, dim_b);
+        Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, s, _origin, dim_b);
 
         if (bb.getSnapped() || sn.getSnapped()) {
             // We snapped something, so change the skew to reflect it
-            NR::Coord const bd = bb.getSnapped() ? bb.getTransformation()[dim_b] : NR_HUGE;
-            NR::Coord const sd = sn.getSnapped() ? sn.getTransformation()[dim_b] : NR_HUGE;
+            NR::Coord const bd = bb.getSnapped() ? bb.getTransformation()[0] : NR_HUGE;
+            NR::Coord const sd = sn.getSnapped() ? sn.getTransformation()[0] : NR_HUGE;
             if (bd < sd) {
                 _desktop->snapindicator->set_new_snappoint(bb);
                 skew[dim_a] = bd;
index c9944cb0453409889befda5ecf5571216d4a1f05..3429dfd74e72b50a15d673b03ce9abb0f05dc1c1 100644 (file)
@@ -324,7 +324,7 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
                 transformed = *i + transformation;
                 break;
             case SCALE:
-                transformed = ((*i - origin) * NR::scale(transformation[NR::X], transformation[NR::Y])) + origin;
+                transformed = (*i - origin) * NR::scale(transformation[NR::X], transformation[NR::Y]) + origin;
                 break;
             case STRETCH:
             {
@@ -339,8 +339,11 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
                 break;
             }
             case SKEW:
-                transformed = *i;
-                transformed[dim] += transformation[dim] * ((*i)[1 - dim] - origin[1 - dim]);
+                // Apply the skew factor
+                transformed[dim] = (*i)[dim] + transformation[0] * ((*i)[1 - dim] - origin[1 - dim]);
+                // While skewing, mirroring and scaling (by integer multiples) in the opposite direction is also allowed.
+                // Apply that scale factor here
+                transformed[1-dim] = (*i - origin)[1 - dim] * transformation[1] + origin[1 - dim];
                 break;
             default:
                 g_assert_not_reached();
@@ -384,9 +387,9 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
                 // running from the scaling origin to the original untransformed point. We will
                 // calculate that line here 
                 dedicated_constraint = Inkscape::Snapper::ConstraintLine(origin, (*i) - origin);
-            } else if (transformation_type == STRETCH || transformation_type == SKEW) { // when skewing or non-uniform stretching {
+            } 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 
+            } // else: leave the original constraint, e.g. for constrained translation and skewing 
             if (transformation_type == SCALE && !uniform) {
                 g_warning("Non-uniform constrained scaling is not supported!");   
             }
@@ -457,8 +460,9 @@ Inkscape::SnappedPoint SnapManager::_snapTransformed(
                     metric = std::abs(result[dim] - transformation[dim]);
                     break;
                 case SKEW:
-                    result[dim] = (snapped_point.getPoint()[dim] - (*i)[dim]) / ((*i)[1 - dim] - origin[1 - dim]);
-                    metric = std::abs(result[dim] - transformation[dim]);
+                    result[0] = (snapped_point.getPoint()[dim] - (*i)[dim]) / ((*i)[1 - dim] - origin[1 - dim]); // skew factor
+                    result[1] = transformation[1]; // scale factor
+                    metric = std::abs(result[0] - transformation[0]);
                     break;
                 default:
                     g_assert_not_reached();
@@ -648,13 +652,15 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapStretch(Inkscape::Snapper::Po
  *  \return Snapped skew, if a snap occurred, and a flag indicating whether a snap occurred.
  */
 
-Inkscape::SnappedPoint SnapManager::freeSnapSkew(Inkscape::Snapper::PointType point_type,
+Inkscape::SnappedPoint SnapManager::constrainedSnapSkew(Inkscape::Snapper::PointType point_type,
                                                  std::vector<NR::Point> const &p,
-                                                 NR::Coord const &s,
+                                                 Inkscape::Snapper::ConstraintLine const &constraint,
+                                                 NR::Point const &s,  
                                                  NR::Point const &o,
                                                  NR::Dim2 d) const
 {
-   return _snapTransformed(point_type, p, false, NR::Point(), SKEW, NR::Point(s, s), o, d, false);
+   // "s" contains skew factor in s[0], and scale factor in s[1]
+   return _snapTransformed(point_type, p, true, constraint, SKEW, s, o, d, false);
 }
 
 Inkscape::SnappedPoint SnapManager::findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const
@@ -764,6 +770,7 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(NR::Point const &p, SnappedCons
         }
     }
     
+    // std::cout << "findBestSnap = " << bestSnappedPoint.getPoint() << std::endl;
     return bestSnappedPoint;         
 }
 
index f11b7c743ad45193d5bcdf0efd5cc36f1495b2f0..f49eb7145a3c22bdf1f933119f43e6b5d099fc17 100644 (file)
@@ -90,16 +90,13 @@ public:
                                                    NR::Dim2 d,
                                                    bool uniform) const;
 
-    Inkscape::SnappedPoint freeSnapSkew(Inkscape::Snapper::PointType point_type,
+    Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::Snapper::PointType point_type,
                                         std::vector<NR::Point> const &p,
-                                        NR::Coord const &s,
+                                        Inkscape::Snapper::ConstraintLine const &constraint,
+                                        NR::Point const &s, // s[0] = skew factor, s[1] = scale factor
                                         NR::Point const &o,
                                         NR::Dim2 d) const;
-                                            
-       //Inkscape::SnappedPoint guideSnap(NR::Point const &p,
-    //                       Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
-  
-
+                                        
     Inkscape::GuideSnapper guide;      ///< guide snapper
     Inkscape::ObjectSnapper object;    ///< snapper to other objects