From 4582ff808a6776266e017cbb5df5b70c461483bc Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 11 Aug 2010 00:18:26 +0200 Subject: Implement constrained snapping to nodes (bzr r9696) --- src/draw-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/draw-context.cpp') diff --git a/src/draw-context.cpp b/src/draw-context.cpp index a531b88d1..c0ae626d5 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -511,7 +511,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, /* Snap it along best vector */ SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); - m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE, Inkscape::Snapper::SnapConstraint(best)); + m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE, Inkscape::Snapper::SnapConstraint(o, best)); } } } -- cgit v1.2.3 From 19117c36082531a00df461260f917d1207edde1f Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 11 Aug 2010 08:43:24 +0200 Subject: Clear pointers in the snapmanager if they're no longer needed. (bzr r9697) --- src/draw-context.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/draw-context.cpp') diff --git a/src/draw-context.cpp b/src/draw-context.cpp index c0ae626d5..9bd67c3dd 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -512,6 +512,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE, Inkscape::Snapper::SnapConstraint(o, best)); + m.unSetup(); } } } @@ -528,6 +529,7 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, Geom::Point& p, gu m.setup(dt, true, selection->singleItem()); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.unSetup(); } static SPCurve * -- cgit v1.2.3 From ffba6ae904deaef040defebcc0ff6f7458dbb969 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 30 Oct 2010 00:07:10 +0200 Subject: - Constrained snap: proper implementation of the preference to snap the mouse pointer or handle itself (instead of projecting it first onto the constraint) - Fix a crash in SnapManager::multipleConstrainedSnaps (bzr r9866) --- src/draw-context.cpp | 69 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'src/draw-context.cpp') diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 9bd67c3dd..ca68b3f6d 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -42,6 +42,7 @@ #include "sp-namedview.h" #include "live_effects/lpe-patternalongpath.h" #include "style.h" +#include "util/mathfns.h" static void sp_draw_context_class_init(SPDrawContextClass *klass); static void sp_draw_context_init(SPDrawContext *dc); @@ -468,7 +469,7 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/) * \param dc draw context * \param p cursor point (to be changed by snapping) * \param o origin point - * \param state keyboard state to check if ctrl was pressed + * \param state keyboard state to check if ctrl or shift was pressed */ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, Geom::Point const &o, @@ -476,43 +477,41 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); unsigned const snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12)); - /* 0 means no snapping. */ - - /* mirrored by fabs, so this corresponds to 15 degrees */ - Geom::Point best; /* best solution */ - double bn = NR_HUGE; /* best normal */ - double bdot = 0; - Geom::Point v = Geom::Point(0, 1); - double const r00 = cos(M_PI / snaps), r01 = sin(M_PI / snaps); - double const r10 = -r01, r11 = r00; - - Geom::Point delta = p - o; - - for (unsigned i = 0; i < snaps; i++) { - double const ndot = fabs(dot(v,Geom::rot90(delta))); - Geom::Point t(r00*v[Geom::X] + r01*v[Geom::Y], - r10*v[Geom::X] + r11*v[Geom::Y]); - if (ndot < bn) { - /* I think it is better numerically to use the normal, rather than the dot product - * to assess solutions, but I haven't proven it. */ - bn = ndot; - best = v; - bdot = dot(v, delta); + + if (snaps > 0) { // 0 means no snapping + // p is at an arbitrary angle. Now we should snap this angle to specific increments. + // For this we'll calculate the closest two angles, one at each side of the current angle + Geom::Line y_axis(Geom::Point(0, 0), Geom::Point(0, 1)); + Geom::Line p_line(o, p); + double angle = Geom::angle_between(y_axis, p_line); + double angle_incr = M_PI / snaps; + double angle_ceil = round_to_upper_multiple_plus(angle, angle_incr); + double angle_floor = round_to_lower_multiple_plus(angle, angle_incr); + // We have to angles now. The constrained snapper will try each of them and return the closest + // But first we should setup the snapper + + SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); + bool snap_enabled = m.snapprefs.getSnapEnabledGlobally(); + if (state & GDK_SHIFT_MASK) { + // SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular + // snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable + // the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round + // to the nearest angle increment) + m.snapprefs.setSnapEnabledGlobally(false); } - v = t; - } - if (fabs(bdot) > 0) { - p = o + bdot * best; + // Now do the snapping... + std::vector constraints; + constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_ceil - M_PI/2))); + constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_floor - M_PI/2))); + + Inkscape::SnappedPoint sp = m.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), constraints); + p = sp.getPoint(); - if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above - //After all, the user explicitly asked for angular snapping by - //pressing CTRL - /* Snap it along best vector */ - SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); - m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE, Inkscape::Snapper::SnapConstraint(o, best)); - m.unSetup(); + m.unSetup(); + if (state & GDK_SHIFT_MASK) { + m.snapprefs.setSnapEnabledGlobally(snap_enabled); // restore the original setting } } } -- cgit v1.2.3 From cd2ff7c27f5809358e151eba391b8f9d85b1eea1 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 7 Nov 2010 21:16:45 +0100 Subject: Leave constrained angular snapping to the snap manager, instead of handling it locally (bzr r9880) --- src/draw-context.cpp | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'src/draw-context.cpp') diff --git a/src/draw-context.cpp b/src/draw-context.cpp index ca68b3f6d..66a2309b2 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -42,7 +42,6 @@ #include "sp-namedview.h" #include "live_effects/lpe-patternalongpath.h" #include "style.h" -#include "util/mathfns.h" static void sp_draw_context_class_init(SPDrawContextClass *klass); static void sp_draw_context_init(SPDrawContext *dc); @@ -477,43 +476,26 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); unsigned const snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12)); + SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); - if (snaps > 0) { // 0 means no snapping - // p is at an arbitrary angle. Now we should snap this angle to specific increments. - // For this we'll calculate the closest two angles, one at each side of the current angle - Geom::Line y_axis(Geom::Point(0, 0), Geom::Point(0, 1)); - Geom::Line p_line(o, p); - double angle = Geom::angle_between(y_axis, p_line); - double angle_incr = M_PI / snaps; - double angle_ceil = round_to_upper_multiple_plus(angle, angle_incr); - double angle_floor = round_to_lower_multiple_plus(angle, angle_incr); - // We have to angles now. The constrained snapper will try each of them and return the closest - // But first we should setup the snapper - - SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - m.setup(SP_EVENT_CONTEXT_DESKTOP(ec)); - bool snap_enabled = m.snapprefs.getSnapEnabledGlobally(); - if (state & GDK_SHIFT_MASK) { - // SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular - // snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable - // the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round - // to the nearest angle increment) - m.snapprefs.setSnapEnabledGlobally(false); - } - - // Now do the snapping... - std::vector constraints; - constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_ceil - M_PI/2))); - constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_floor - M_PI/2))); + bool snap_enabled = m.snapprefs.getSnapEnabledGlobally(); + if (state & GDK_SHIFT_MASK) { + // SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular + // snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable + // the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round + // to the nearest angle increment) + m.snapprefs.setSnapEnabledGlobally(false); + } - Inkscape::SnappedPoint sp = m.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), constraints); - p = sp.getPoint(); + Inkscape::SnappedPoint dummy = m.constrainedAngularSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), boost::optional(), o, snaps); + p = dummy.getPoint(); - m.unSetup(); - if (state & GDK_SHIFT_MASK) { - m.snapprefs.setSnapEnabledGlobally(snap_enabled); // restore the original setting - } + if (state & GDK_SHIFT_MASK) { + m.snapprefs.setSnapEnabledGlobally(snap_enabled); // restore the original setting } + + m.unSetup(); } -- cgit v1.2.3 From 144819c918dc761641c3cb5a490205fb73194ee3 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 17 Nov 2010 13:12:56 +1100 Subject: Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines. The reason for this is that (a) setting the encoding isn't nice, and (b) Vim 7.3 (with modeline enabled) disallows it and pops up an error whenever you open any file with it ("invalid modeline"). Also corrected five deviant modestrings: * src/ui/widget/dock.cpp and src/ui/widget/dock.h: missing colon at the end * src/ui/dialog/tile.cpp: removed gratuitous second colon at the end * src/helper/units-test.h: removed gratuitous space before a colon * share/extensions/export_gimp_palette.py: missing textwidth=99 That's my geekiest commit yet. (bzr r9900) --- src/draw-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/draw-context.cpp') diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 66a2309b2..3f33f9499 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -855,4 +855,4 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3