From: cth103 Date: Fri, 5 May 2006 15:07:33 +0000 (+0000) Subject: Remove some old snap code. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c3fab1b28454fe4b855580cfa3d6339528df292a;p=inkscape.git Remove some old snap code. --- diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 2d4201fac..70dd0d1a0 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -889,6 +889,8 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR:: it.push_back(reinterpret_cast(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 bb = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::BBOX_POINT, - _bbox_points, _origin, - s[axis], axis, it); - std::pair 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 const bb = m.constrainedSnapScale( + Snapper::BBOX_POINT, + _bbox_points, + it, + Inkscape::Snapper::ConstraintLine(component_vectors[axis]), + s, + _origin); + + std::pair 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; diff --git a/src/snap.cpp b/src/snap.cpp index 7c68ae877..bf5385910 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -165,11 +165,15 @@ std::pair 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 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 namedview_dim_snap_list_scale(SPNamedView const *nv, Inkscape::Snapper::PointType t, - const std::vector &p, NR::Point const &norm, - double const sx, NR::Dim2 dim, - std::list 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::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. */ diff --git a/src/snap.h b/src/snap.h index a37878f9c..d7050d822 100644 --- a/src/snap.h +++ b/src/snap.h @@ -120,12 +120,6 @@ std::pair namedview_vector_snap_list(SPNamedView const *nv, ); -std::pair namedview_dim_snap_list_scale(SPNamedView const *nv, - Inkscape::Snapper::PointType t, const std::vector &p, - NR::Point const &norm, double const sx, - NR::Dim2 const dim, - std::list const &it); - NR::Coord namedview_dim_snap_list_skew(SPNamedView const *nv, Inkscape::Snapper::PointType t, const std::vector &p, NR::Point const &norm, double const sx, NR::Dim2 const dim);