Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapCandidatePoint const &p, Inkscape::Snapper::SnapConstraint const &constraint, Geom::OptRect const &bbox_to_snap) const { // First project the mouse pointer onto the constraint Geom::Point pp = constraint.projection(p.getPoint()); Inkscape::SnappedPoint no_snap = Inkscape::SnappedPoint(pp, p.getSourceType(), p.getSourceNum(), Inkscape::SNAPTARGET_CONSTRAINT, Geom::infinity(), 0, false, true, false); if (!someSnapperMightSnap()) { // Always return point on constraint return no_snap; } Inkscape::SnappedPoint result = no_snap; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if ((prefs->getBool("/options/snapmousepointer/value", false)) && p.isSingleHandle()) { // Snapping the mouse pointer instead of the constrained position of the knot allows // to snap to things which don't intersect with the constraint line; this is basically // then just a freesnap with the constraint applied afterwards // We'll only do this if we're dragging a single handle, and for example not when transforming an object in the selector tool result = freeSnap(p, bbox_to_snap); if (result.getSnapped()) { // only change the snap indicator if we really snapped to something if (_snapindicator && _desktop) { _desktop->snapindicator->set_new_snaptarget(result); } // Apply the constraint result.setPoint(constraint.projection(result.getPoint())); return result; } return no_snap; } IntermSnapResults isr; SnapperList const snappers = getSnappers(); for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); ++i) { (*i)->constrainedSnap(isr, p, bbox_to_snap, constraint, &_items_to_ignore, _unselected_nodes); } result = findBestSnap(p, isr, true); if (result.getSnapped()) { // only change the snap indicator if we really snapped to something if (_snapindicator && _desktop) { _desktop->snapindicator->set_new_snaptarget(result); } return result; } return no_snap; }
Inkscape::SnappedPoint SnapManager::multipleConstrainedSnaps(Inkscape::SnapCandidatePoint const &p, std::vector<Inkscape::Snapper::SnapConstraint> const &constraints, bool dont_snap, Geom::OptRect const &bbox_to_snap) const { Inkscape::SnappedPoint no_snap = Inkscape::SnappedPoint(p.getPoint(), p.getSourceType(), p.getSourceNum(), Inkscape::SNAPTARGET_CONSTRAINT, Geom::infinity(), 0, false, true, false); if (constraints.size() == 0) { return no_snap; } // We haven't tried to snap yet; we will first determine which constraint is closest to where we are now, // i.e. lets find out which of the constraints yields the closest projection of point p // Project the mouse pointer on each of the constraints std::vector<Geom::Point> projections; for (std::vector<Inkscape::Snapper::SnapConstraint>::const_iterator c = constraints.begin(); c != constraints.end(); ++c) { // Project the mouse pointer onto the constraint; In case we don't snap then we will // return the projection onto the constraint, such that the constraint is always enforced Geom::Point pp = (*c).projection(p.getPoint()); projections.push_back(pp); } // Select the closest constraint no_snap.setPoint(projections.front()); Inkscape::Snapper::SnapConstraint cc = constraints.front(); //closest constraint std::vector<Inkscape::Snapper::SnapConstraint>::const_iterator c = constraints.begin(); std::vector<Geom::Point>::iterator pp = projections.begin(); for (; pp != projections.end(); ++pp) { if (Geom::L2(*pp - p.getPoint()) < Geom::L2(no_snap.getPoint() - p.getPoint())) { no_snap.setPoint(*pp); // Remember the projection onto the closest constraint cc = *c; // Remember the closest constraint itself } ++c; } if (!someSnapperMightSnap() || dont_snap) { return no_snap; } IntermSnapResults isr; SnapperList const snappers = getSnappers(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool snap_mouse = prefs->getBool("/options/snapmousepointer/value", false); Inkscape::SnappedPoint result = no_snap; if (snap_mouse && p.isSingleHandle()) { // Snapping the mouse pointer instead of the constrained position of the knot allows // to snap to things which don't intersect with the constraint line; this is basically // then just a freesnap with the constraint applied afterwards // We'll only to this if we're dragging a single handle, and for example not when transforming an object in the selector tool result = freeSnap(p, bbox_to_snap); // Now apply the constraint afterwards result.setPoint(cc.projection(result.getPoint())); } else { // Try to snap along the closest constraint for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); ++i) { (*i)->constrainedSnap(isr, p, bbox_to_snap, cc, &_items_to_ignore,_unselected_nodes); } result = findBestSnap(p, isr, true); } return result.getSnapped() ? result : no_snap; }