Code

Remove some old snap code.
authorcth103 <cth103@users.sourceforge.net>
Fri, 5 May 2006 15:07:33 +0000 (15:07 +0000)
committercth103 <cth103@users.sourceforge.net>
Fri, 5 May 2006 15:07:33 +0000 (15:07 +0000)
src/seltrans.cpp
src/snap.cpp
src/snap.h

index 2d4201fac5fa3f91bc8d0bed8cfb9d02e5a215d5..70dd0d1a06b0526a032dcf5810ab5319606adfac 100644 (file)
@@ -889,6 +889,8 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         it.push_back(reinterpret_cast<SPItem*>(i->data));
     }
 
+    SnapManager const &m = _desktop->namedview->snap_manager;
+
     if ( state & GDK_CONTROL_MASK ) {
         s[perp] = fabs(s[axis]);
 
@@ -906,17 +908,27 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         s[axis] = fabs(ratio) * sign(s[axis]);
         s[perp] = fabs(s[axis]);
     } else {
-        std::pair<NR::Coord, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::BBOX_POINT,
-                                                                      _bbox_points, _origin,
-                                                                      s[axis], axis, it);
-        std::pair<NR::Coord, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::SNAP_POINT,
-                                                                      _snap_points, _origin,
-                                                                      s[axis], axis, it);
 
-        /* Pick the snap that puts us closest to the original scale */
-        NR::Coord bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
-        NR::Coord sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
-        s[axis] = (bd < sd) ? bb.first : sn.first;
+        std::pair<NR::scale, bool> const bb = m.constrainedSnapScale(
+            Snapper::BBOX_POINT,
+            _bbox_points,
+            it,
+            Inkscape::Snapper::ConstraintLine(component_vectors[axis]),
+            s,
+            _origin);
+
+        std::pair<NR::scale, bool> const sn = m.constrainedSnapScale(
+            Snapper::SNAP_POINT,
+            _snap_points,
+            it,
+            Inkscape::Snapper::ConstraintLine(component_vectors[axis]),
+            s,
+            _origin);
+
+        /* Choose the smaller difference in scale */
+        NR::Coord const bd = bb.second ? fabs(bb.first[axis] - s[axis]) : NR_HUGE;
+        NR::Coord const sd = sn.second ? fabs(sn.first[axis] - s[axis]) : NR_HUGE;
+        s = (bd < sd) ? bb.first : sn.first;
     }
 
     pt = ( _point - _origin ) * NR::scale(s) + _origin;
index 7c68ae877a481ef1ee613399805c6eabceb22001..bf5385910856db69808a2fdf67d411b9d463effa 100644 (file)
@@ -165,11 +165,15 @@ std::pair<NR::Point, bool> SnapManager::_snapTransformed(Inkscape::Snapper::Poin
                     metric = NR::L2(result);
                     break;
                 case SCALE:
+                {
                     NR::Point const a = (snapped.getPoint() - origin);
                     NR::Point const b = (*i - origin);
                     result = NR::Point(a[NR::X] / b[NR::X], a[NR::Y] / b[NR::Y]);
                     metric = std::abs(NR::L2(result) - NR::L2(transformation));
                     break;
+                }
+                default:
+                    g_assert_not_reached();
             }
 
             /* Note it if it's the best so far */
@@ -335,53 +339,6 @@ std::pair<double, bool> namedview_vector_snap_list(SPNamedView const *nv, Inksca
 }
    
 
-/**
- * Try to snap points in \a p after they have been scaled by \a sx with respect to
- * the origin \a norm.  The best snap is the one that changes the scale least.
- *
- * \return Pair containing snapped scale and a flag which is true if a snap was made.
- */
-std::pair<double, bool> namedview_dim_snap_list_scale(SPNamedView const *nv, Inkscape::Snapper::PointType t,
-                                                      const std::vector<NR::Point> &p, NR::Point const &norm,
-                                                      double const sx, NR::Dim2 dim,
-                                                      std::list<const SPItem *> const &it)
-{
-    SnapManager const &m = nv->snap_manager;
-    if (m.willSnapSomething() == false) {
-        return std::make_pair(sx, false);
-    }
-
-    g_assert(dim < 2);
-
-    NR::Coord dist = NR_HUGE;
-    double scale = sx;
-
-    for (std::vector<NR::Point>::const_iterator i = p.begin(); i != p.end(); i++) {
-        NR::Point q = *i;
-        NR::Point check = q;
-
-        /* Scaled version of the point we are looking at */
-        check[dim] = (sx * (q - norm) + norm)[dim];
-
-        if (fabs (q[dim] - norm[dim]) > MIN_DIST_NORM) {
-            /* Snap this point */
-            const NR::Coord d = namedview_dim_snap (nv, t, check, dim, it);
-            /* Work out the resulting scale factor */
-            double snapped_scale = (check[dim] - norm[dim]) / (q[dim] - norm[dim]);
-
-            if (dist == NR_HUGE || fabs(snapped_scale - sx) < fabs(scale - sx)) {
-                /* This is either the first point, or the snapped scale
-                ** is the closest yet to the original.
-                */
-                scale = snapped_scale;
-                dist = d;
-            }
-        }
-    }
-
-    return std::make_pair(scale, dist < NR_HUGE);
-}
-
 /**
  * Try to snap points after they have been skewed.
  */
index a37878f9c8ab2fd3ea1d02d3d242bc52d3ee5c2c..d7050d8229fba0b09fcbc8eadc181c953f0fc567 100644 (file)
@@ -120,12 +120,6 @@ std::pair<double, bool> namedview_vector_snap_list(SPNamedView const *nv,
                                                    );
 
 
-std::pair<double, bool> namedview_dim_snap_list_scale(SPNamedView const *nv,
-                                                      Inkscape::Snapper::PointType t, const std::vector<NR::Point> &p,
-                                                      NR::Point const &norm, double const sx,
-                                                      NR::Dim2 const dim,
-                                                      std::list<SPItem const *> const &it);
-
 NR::Coord namedview_dim_snap_list_skew(SPNamedView const *nv, Inkscape::Snapper::PointType t,
                                        const std::vector<NR::Point> &p,
                                        NR::Point const &norm, double const sx, NR::Dim2 const dim);