From e569bdc0f6f0d101c3977d38ffa1d99012d1af40 Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Thu, 1 May 2008 18:24:38 +0000 Subject: [PATCH] Replace freeSnapSkew() by constrainedSnapSkew(). There is no such thing as freely snapping while skewing; snapping will always be constrained --- src/seltrans.cpp | 12 ++++++------ src/snap.cpp | 27 +++++++++++++++++---------- src/snap.h | 11 ++++------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/seltrans.cpp b/src/seltrans.cpp index db1135785..3c333c11b 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -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; diff --git a/src/snap.cpp b/src/snap.cpp index c9944cb04..3429dfd74 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -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 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; } diff --git a/src/snap.h b/src/snap.h index f11b7c743..f49eb7145 100644 --- a/src/snap.h +++ b/src/snap.h @@ -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 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 -- 2.30.2