Code

a bunch of small changes to provide a user readable explanation of filters
[inkscape.git] / src / seltrans.cpp
index f62e18ac2cbd547af4b73dfc0a33eed51463765b..a3f34384107f93300bf100471b2dcdb57dc09d0f 100644 (file)
@@ -88,11 +88,15 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
     _show(SHOW_CONTENT),
     _grabbed(false),
     _show_handles(true),
-    _box(NR::Nothing()),
+    _bbox(NR::Nothing()),
+    _approximate_bbox(NR::Nothing()),
     _chandle(NULL),
     _stamp_cache(NULL),
     _message_context(desktop->messageStack())
 {
+    gchar const *prefs_bbox = prefs_get_string_attribute("tools", "bounding_box");
+    _snap_bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
+
     g_return_if_fail(desktop != NULL);
 
     for (int i = 0; i < 8; i++) {
@@ -255,55 +259,71 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
 
     _point = p;
 
-    _snap_points = selection->getSnapPoints();
+    // The selector tool should snap the bbox, special snappoints, and path nodes
+    // (The special points are the handles, center, rotation axis, font baseline, ends of spiral, etc.)
+
+    // First, determine the bounding box for snapping ...
+    _bbox = selection->bounds(_snap_bbox_type);
+    _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX); // Used for correctly scaling the strokewidth
+
+    // Next, get all points to consider for snapping
+    SnapManager const &m = _desktop->namedview->snap_manager;
+    _snap_points = selection->getSnapPoints(m.getIncludeItemCenter());
+    std::vector<NR::Point> snap_points_hull = selection->getSnapPointsConvexHull();
     if (_snap_points.size() > 100) {
         /* Snapping a huge number of nodes will take way too long, so limit the number of snappable nodes
-        An average user would rarely ever try to snap such a large number of nodes anyway, because 
+        An average user would rarely ever try to snap such a large number of nodes anyway, because
         (s)he could hardly discern which node would be snapping */
-        _snap_points = selection->getSnapPointsConvexHull();
+        _snap_points = snap_points_hull;
         // Unfortunately, by now we will have lost the font-baseline snappoints :-(
     }
-    _box = selection->bounds();
+
+    // Find bbox hulling all special points, which excludes stroke width. Here we need to include the
+    // path nodes, for example because a rectangle which has been converted to a path doesn't have
+    // any other special points
+    NR::Rect snap_points_bbox;
+    if ( snap_points_hull.empty() == false ) {
+        std::vector<NR::Point>::iterator i = snap_points_hull.begin();
+        snap_points_bbox = NR::Rect(*i, *i);
+        i++;
+        while (i != snap_points_hull.end()) {
+            snap_points_bbox.expandTo(*i);
+            i++;
+        }
+    }
+
     _bbox_points.clear();
-    if (_box) {
+    if (_bbox) {
+        // ... and add the bbox corners to _bbox_points
         for ( unsigned i = 0 ; i < 4 ; i++ ) {
-            _bbox_points.push_back(_box->corner(i));
+            _bbox_points.push_back(_bbox->corner(i));
         }
+        // There are two separate "opposites" (i.e. opposite w.r.t. the handle being dragged):
+        //  - one for snapping the boundingbox, which can be either visual or geometric
+        //  - one for snapping the special points
+        // The "opposite" in case of a geometric boundingbox always coincides with the "opposite" for the special points
+        // These distinct "opposites" are needed in the snapmanager to avoid bugs such as #1540195 (in which
+        // a box is caught between to guides)
+        _opposite_for_bboxpoints = _bbox->min() + _bbox->dimensions() * NR::scale(1-x, 1-y);
+        _opposite_for_specpoints = (snap_points_bbox.min() + (snap_points_bbox.dimensions() * NR::scale(1-x, 1-y) ) );
+        // Only a single "opposite" can be used in calculating transformations.
+        _opposite = _opposite_for_bboxpoints;
+    }
+
+    // The lines below are usefull for debugging any snapping issues, as they'll spit out all points that are considered for snapping
+
+    /*std::cout << "Number of snap points:  " << _snap_points.size() << std::endl;
+    for (std::vector<NR::Point>::const_iterator i = _snap_points.begin(); i != _snap_points.end(); i++)
+    {
+        std::cout << "    " << *i << std::endl;
     }
 
-    gchar const *scale_origin = prefs_get_string_attribute("tools.select", "scale_origin");
-    bool const origin_on_bbox = (scale_origin == NULL || !strcmp(scale_origin, "bbox"));
+    std::cout << "Number of bbox points:  " << _bbox_points.size() << std::endl;
+    for (std::vector<NR::Point>::const_iterator i = _bbox_points.begin(); i != _bbox_points.end(); i++)
+    {
+        std::cout << "    " << *i << std::endl;
+    }*/
 
-    
-    /*Snapping will be to either nodes or to boundingbox-cornes; each will require its own origin, which 
-    is only slightly different from the other. When we would use an origin at one of the nodes while 
-    trying to snap the boundingbox, all four points of the boundingbox would be moving (e.g. during stretching),
-    and would therefore also be snapping (which is bad). This leads to bugs similar to #1540195, in which 
-    a box is caught between to guides. To solve this, we need two different points: _opposite_for_snappoints and
-    _opposite_for_boundingbox
-    */
-    
-    if (_box) {
-        _opposite_for_bboxpoints = _box->min() + _box->dimensions() * NR::scale(1-x, 1-y);
-        
-        NR::Rect op_box = *_box;
-        // FIXME: should be using ConvexHull here
-        if ( _snap_points.empty() == false) {
-            std::vector<NR::Point>::iterator i = _snap_points.begin();
-            op_box = NR::Rect(*i, *i);
-            i++;
-            while (i != _snap_points.end()) {
-                op_box.expandTo(*i);
-                i++;
-            }
-        }
-        _opposite_for_snappoints = ( op_box.min() + ( op_box.dimensions() * NR::scale(1-x, 1-y) ) );
-        //until we can kick out the old _opposite, and use _opposite_for_bboxpoints or _opposite_for_snappoints everywhere
-        //keep the old behavior for _opposite:
-        _opposite = origin_on_bbox ? _opposite_for_bboxpoints : _opposite_for_snappoints;
-        //FIXME: get rid of _opposite. Requires different handling of preferences, see Bulia Byak's comment for bug #1540195
-    }
-    
     if ((x != -1) && (y != -1)) {
         sp_canvas_item_show(_norm);
         sp_canvas_item_show(_grip);
@@ -333,11 +353,11 @@ void Inkscape::SelTrans::transform(NR::Matrix const &rel_affine, NR::Point const
             sp_item_set_i2d_affine(&item, prev_transform * affine);
         }
     } else {
-        if (_box) {
+        if (_bbox) {
             NR::Point p[4];
             /* update the outline */
             for (unsigned i = 0 ; i < 4 ; i++) {
-                p[i] = _box->corner(i) * affine;
+                p[i] = _bbox->corner(i) * affine;
             }
             for (unsigned i = 0 ; i < 4 ; i++) {
                 sp_ctrlline_set_coords(SP_CTRLLINE(_l[i]), p[i], p[(i+1)%4]);
@@ -577,8 +597,11 @@ void Inkscape::SelTrans::_updateVolatileState()
         return;
     }
 
-    _box = selection->bounds();
-    if (!_box) {
+    //Update the bboxes
+    _bbox = selection->bounds(_snap_bbox_type);
+    _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX);
+
+    if (!_bbox) {
         _empty = true;
         return;
     }
@@ -627,9 +650,9 @@ void Inkscape::SelTrans::_showHandles(SPKnot *knot[], SPSelTransHandle const han
 
         NR::Point const handle_pt(handle[i].x, handle[i].y);
         // shouldn't have nullary bbox, but knots
-        g_assert(_box);
-        NR::Point p( _box->min()
-                     + ( _box->dimensions()
+        g_assert(_bbox);
+        NR::Point p( _bbox->min()
+                     + ( _bbox->dimensions()
                          * NR::scale(handle_pt) ) );
 
         sp_knot_moveto(knot[i], &p);
@@ -643,7 +666,7 @@ static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data)
         );
 }
 
-static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, gpointer data)
+static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint /*state*/, gpointer /*data*/)
 {
     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->ungrab();
 }
@@ -669,7 +692,7 @@ static void sp_sel_trans_handle_click(SPKnot *knot, guint state, gpointer data)
         );
 }
 
-void Inkscape::SelTrans::handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle)
+void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHandle const &handle)
 {
     switch (handle.anchor) {
         case GTK_ANCHOR_CENTER:
@@ -682,7 +705,7 @@ void Inkscape::SelTrans::handleClick(SPKnot *knot, guint state, SPSelTransHandle
                     _center_is_set = false;  // center has changed
                     _updateHandles();
                 }
-                sp_document_done (sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT, 
+                sp_document_done (sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
                                         _("Reset center"));
             }
             break;
@@ -691,7 +714,7 @@ void Inkscape::SelTrans::handleClick(SPKnot *knot, guint state, SPSelTransHandle
     }
 }
 
-void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle)
+void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint /*state*/, SPSelTransHandle const &handle)
 {
     switch (handle.anchor) {
         case GTK_ANCHOR_CENTER:
@@ -742,18 +765,14 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
 
     knot->desktop->setPosition(*position);
 
-    if (state & GDK_MOD1_MASK) {
-        *position = _point + ( *position - _point ) / 10;
-    }
-
     if ((!(state & GDK_SHIFT_MASK) == !(_state == STATE_ROTATE)) && (&handle != &handle_center)) {
         _origin = _opposite;
         _origin_for_bboxpoints = _opposite_for_bboxpoints;
-        _origin_for_snappoints = _opposite_for_snappoints;
+        _origin_for_specpoints = _opposite_for_specpoints;
     } else if (_center) {
         _origin = *_center;
         _origin_for_bboxpoints = *_center;
-        _origin_for_snappoints = *_center;
+        _origin_for_specpoints = *_center;
     } else {
         // FIXME
         return TRUE;
@@ -768,9 +787,14 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
 }
 
 
-void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
+void Inkscape::SelTrans::_selChanged(Inkscape::Selection */*selection*/)
 {
     if (!_grabbed) {
+        // reread in case it changed on the fly:
+        gchar const *prefs_bbox = prefs_get_string_attribute("tools", "bounding_box");
+        _snap_bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
+        //SPItem::APPROXIMATE_BBOX will be replaced by SPItem::VISUAL_BBOX, as soon as the latter is implemented properly
+
         _updateVolatileState();
         _current.set_identity();
         _center_is_set = false; // center(s) may have changed
@@ -778,7 +802,7 @@ void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
     }
 }
 
-void Inkscape::SelTrans::_selModified(Inkscape::Selection *selection, guint flags)
+void Inkscape::SelTrans::_selModified(Inkscape::Selection */*selection*/, guint /*flags*/)
 {
     if (!_grabbed) {
         _updateVolatileState();
@@ -853,6 +877,15 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
         }
     }
 
+    if (state & GDK_MOD1_MASK) { // scale by an integer multiplier/divider
+        for ( unsigned int i = 0 ; i < 2 ; i++ ) {
+            if (fabs(s[i]) > 1)
+                s[i] = round(s[i]);
+            else
+                s[i] = 1/round(1/(MIN(s[i], 10)));
+        }
+    }
+
     SnapManager const &m = _desktop->namedview->snap_manager;
 
     /* Get a STL list of the selected items.
@@ -872,36 +905,21 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
             } else {
                 s[NR::Y] = fabs(s[NR::X]) * sign(s[NR::Y]);
             }
-            
-        // Snap along a suitable constraint vector from the origin.
-
-        // The inclination of the constraint vector is calculated from the aspect ratio
-        NR::Point bbox_dim = _box->dimensions();
-        double const aspect_ratio = bbox_dim[1] / bbox_dim[0]; // = height / width
 
-        // Determine direction of the constraint vector
-        NR::Point const cv = NR::Point(
-            pt[NR::X] > _origin[NR::X] ? 1 : -1,
-            pt[NR::Y] > _origin[NR::Y] ? aspect_ratio : -aspect_ratio
-            );
-
-        std::pair<NR::scale, bool> bb = m.constrainedSnapScale(Snapper::BBOX_POINT,
+        // Snap along a suitable constraint vector from the origin.
+        std::pair<NR::scale, bool> bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX,
                                                                _bbox_points,
                                                                it,
-                                                               Snapper::ConstraintLine(_origin_for_bboxpoints, cv),
                                                                s,
                                                                _origin_for_bboxpoints);
 
-        std::pair<NR::scale, bool> sn = m.constrainedSnapScale(Snapper::SNAP_POINT,
+        std::pair<NR::scale, bool> sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE,
                                                                _snap_points,
                                                                it,
-                                                               Snapper::ConstraintLine(_origin_for_snappoints, cv),
                                                                s,
-                                                               _origin_for_snappoints);
+                                                               _origin_for_specpoints);
 
-        if (bb.second == false && sn.second == false) {
-            /* We didn't snap, so just keep the locked aspect ratio */
-        } else {
+        if (bb.second || sn.second) { // If we snapped to something
             /* Choose the smaller difference in scale.  Since s[X] == s[Y] we can
             ** just compare difference in s[X].
             */
@@ -912,28 +930,30 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
 
     } else {
         /* Scale aspect ratio is unlocked */
-        
-        std::pair<NR::scale, bool> bb = m.freeSnapScale(Snapper::BBOX_POINT,
+
+        std::pair<NR::scale, bool> bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX,
                                                         _bbox_points,
                                                         it,
                                                         s,
                                                         _origin_for_bboxpoints);
-        std::pair<NR::scale, bool> sn = m.freeSnapScale(Snapper::SNAP_POINT,
+        std::pair<NR::scale, bool> sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE,
                                                         _snap_points,
                                                         it,
                                                         s,
-                                                        _origin_for_snappoints);
-
-       /* Pick the snap that puts us closest to the original scale */
-        NR::Coord bd = bb.second ?
-            fabs(NR::L2(NR::Point(bb.first[NR::X], bb.first[NR::Y])) -
-                 NR::L2(NR::Point(s[NR::X], s[NR::Y])))
-            : NR_HUGE;
-        NR::Coord sd = sn.second ?
-            fabs(NR::L2(NR::Point(sn.first[NR::X], sn.first[NR::Y])) -
-                 NR::L2(NR::Point(s[NR::X], s[NR::Y])))
-            : NR_HUGE;
-        s = (bd < sd) ? bb.first : sn.first;
+                                                        _origin_for_specpoints);
+
+        if (bb.second || sn.second) { // If we snapped to something
+            /* Pick the snap that puts us closest to the original scale */
+            NR::Coord bd = bb.second ?
+                fabs(NR::L2(NR::Point(bb.first[NR::X], bb.first[NR::Y])) -
+                     NR::L2(NR::Point(s[NR::X], s[NR::Y])))
+                : NR_HUGE;
+            NR::Coord sd = sn.second ?
+                fabs(NR::L2(NR::Point(sn.first[NR::X], sn.first[NR::Y])) -
+                     NR::L2(NR::Point(s[NR::X], s[NR::Y])))
+                : NR_HUGE;
+            s = (bd < sd) ? bb.first : sn.first;
+        }
     }
 
     /* Update the knot position */
@@ -981,6 +1001,13 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         s[axis] = 1e-15;
     }
 
+    if (state & GDK_MOD1_MASK) { // scale by an integer multiplier/divider
+        if (fabs(s[axis]) > 1)
+            s[axis] = round(s[axis]);
+        else
+            s[axis] = 1/round(1/(MIN(s[axis], 10)));
+    }
+
     /* Get a STL list of the selected items.
     ** FIXME: this should probably be done by Inkscape::Selection.
     */
@@ -995,8 +1022,8 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         // on ctrl, apply symmetrical scaling instead of stretching
         s[perp] = fabs(s[axis]);
 
-        std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
-            Snapper::BBOX_POINT,
+        std::pair<NR::Coord, bool> const bb = m.constrainedSnapStretch(
+            Snapper::SNAPPOINT_BBOX,
             _bbox_points,
             it,
             s[axis],
@@ -1004,25 +1031,30 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
             axis,
             true);
 
-        std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
-            Snapper::SNAP_POINT,
+        std::pair<NR::Coord, bool> const sn = m.constrainedSnapStretch(
+            Snapper::SNAPPOINT_NODE,
             _snap_points,
             it,
             s[axis],
-            _origin_for_snappoints,
+            _origin_for_specpoints,
             axis,
             true);
 
-        NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
-        NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
-        NR::Coord const ratio = (bd < sd) ? bb.first : sn.first;
-
-        s[axis] = fabs(ratio) * sign(s[axis]);
-        s[perp] = fabs(s[axis]);
+        if (bb.second || sn.second) { // If we snapped to something
+            /* Choose the smaller difference in scale */
+            NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
+            NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
+            NR::Coord const ratio = (bd < sd) ? bb.first : sn.first;
+            
+            if (fabs(ratio) < NR_HUGE) {
+                s[axis] = fabs(ratio) * sign(s[axis]);
+            }
+            s[perp] = fabs(s[axis]);
+        }
     } else {
-        
-        std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
-            Snapper::BBOX_POINT,
+
+        std::pair<NR::Coord, bool> const bb = m.constrainedSnapStretch(
+            Snapper::SNAPPOINT_BBOX,
             _bbox_points,
             it,
             s[axis],
@@ -1030,20 +1062,25 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
             axis,
             false);
 
-        std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
-            Snapper::SNAP_POINT,
+        std::pair<NR::Coord, bool> const sn = m.constrainedSnapStretch(
+            Snapper::SNAPPOINT_NODE,
             _snap_points,
             it,
             s[axis],
-            _origin_for_snappoints,
+            _origin_for_specpoints,
             axis,
             false);
 
-        /* Choose the smaller difference in scale */
-        NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
-        NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
-        s[axis] = (bd < sd) ? bb.first : sn.first;
-        s[perp] = 1;
+        if (bb.second || sn.second) { // If we snapped to something
+            /* Choose the smaller difference in scale */
+            NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
+            NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
+            NR::Coord const nw = (bd < sd) ? bb.first : sn.first; // new stretch scale
+            if (fabs(nw) < NR_HUGE) {
+                s[axis] = nw;
+            }
+            s[perp] = 1;
+        }
     }
 
     pt = ( _point - _origin ) * NR::scale(s) + _origin;
@@ -1109,22 +1146,30 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
         }
         skew[dim_a] = tan(radians) * s[dim_a];
     } else {
+        /* Get a STL list of the selected items.
+           ** FIXME: this should probably be done by Inkscape::Selection.
+           */
+           std::list<SPItem const*> it;
+           for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
+               it.push_back(reinterpret_cast<SPItem*>(i->data));
+           }
+        
         SnapManager const &m = _desktop->namedview->snap_manager;
 
-        std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::BBOX_POINT,
+        std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX,
                                                        _bbox_points,
-                                                       std::list<SPItem const *>(),
+                                                       it,
                                                        skew[dim_a],
                                                        _origin_for_bboxpoints,
                                                        dim_b);
 
-        std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAP_POINT,
+        std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE,
                                                        _snap_points,
-                                                       std::list<SPItem const *>(),
+                                                       it,
                                                        skew[dim_a],
-                                                       _origin_for_snappoints,
+                                                       _origin_for_specpoints,
                                                        dim_b);
-        
+
         if (bb.second || sn.second) {
             /* We snapped something, so change the skew to reflect it */
             NR::Coord const bd = bb.second ? bb.first : NR_HUGE;
@@ -1204,7 +1249,7 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
     using NR::Y;
 
     SnapManager const &m = _desktop->namedview->snap_manager;
-    pt = m.freeSnap(Snapper::SNAP_POINT, pt, NULL).getPoint();
+    pt = m.freeSnap(Snapper::SNAPPOINT_NODE, pt, NULL).getPoint();
 
     if (state & GDK_CONTROL_MASK) {
         if ( fabs(_point[X] - pt[X]) > fabs(_point[Y] - pt[Y]) ) {
@@ -1214,21 +1259,21 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
         }
     }
 
-    if ( !(state & GDK_SHIFT_MASK) && _box ) {
+    if ( !(state & GDK_SHIFT_MASK) && _bbox ) {
         // screen pixels to snap center to bbox
 #define SNAP_DIST 5
         // FIXME: take from prefs
         double snap_dist = SNAP_DIST / _desktop->current_zoom();
 
         for (int i = 0; i < 2; i++) {
-            if (fabs(pt[i] - _box->min()[i]) < snap_dist) {
-                pt[i] = _box->min()[i];
+            if (fabs(pt[i] - _bbox->min()[i]) < snap_dist) {
+                pt[i] = _bbox->min()[i];
             }
-            if (fabs(pt[i] - _box->midpoint()[i]) < snap_dist) {
-                pt[i] = _box->midpoint()[i];
+            if (fabs(pt[i] - _bbox->midpoint()[i]) < snap_dist) {
+                pt[i] = _bbox->midpoint()[i];
             }
-            if (fabs(pt[i] - _box->max()[i]) < snap_dist) {
-                pt[i] = _box->max()[i];
+            if (fabs(pt[i] - _bbox->max()[i]) < snap_dist) {
+                pt[i] = _bbox->max()[i];
             }
         }
     }
@@ -1308,23 +1353,30 @@ void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt,
         s[!dim] = fabs(s[dim]);
     }
 
-    if (!_box) {
+    if (!_bbox) {
         return;
     }
 
-    NR::Point new_bbox_min = _box->min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
-    NR::Point new_bbox_max = _box->max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
+    NR::Point new_bbox_min = _approximate_bbox->min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
+    NR::Point new_bbox_max = _approximate_bbox->max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
 
-    int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
-    NR::Matrix scaler = get_scale_transform_with_stroke (*_box, _strokewidth, transform_stroke,
-                   new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
+    int transform_stroke = false;
+    gdouble strokewidth = 0;
+
+    if ( _snap_bbox_type != SPItem::GEOMETRIC_BBOX) {
+        transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
+        strokewidth = _strokewidth;
+    }
+
+    NR::Matrix scaler = get_scale_transform_with_stroke (*_approximate_bbox, strokewidth, transform_stroke,
+                    new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
 
     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
 }
 
-void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
+void Inkscape::SelTrans::scale(NR::Point &pt, guint /*state*/)
 {
-    if (!_box) {
+    if (!_bbox) {
         return;
     }
 
@@ -1337,17 +1389,25 @@ void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
         if (fabs(s[i]) < 1e-9)
             s[i] = 1e-9;
     }
-    NR::Point new_bbox_min = _box->min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
-    NR::Point new_bbox_max = _box->max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
 
-    int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
-    NR::Matrix scaler = get_scale_transform_with_stroke (*_box, _strokewidth, transform_stroke,
-                   new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
+    NR::Point new_bbox_min = _approximate_bbox->min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
+    NR::Point new_bbox_max = _approximate_bbox->max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
+
+    int transform_stroke = false;
+    gdouble strokewidth = 0;
+
+    if ( _snap_bbox_type != SPItem::GEOMETRIC_BBOX) {
+        transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
+        strokewidth = _strokewidth;
+    }
+
+    NR::Matrix scaler = get_scale_transform_with_stroke (*_approximate_bbox, strokewidth, transform_stroke,
+                    new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
 
     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
 }
 
-void Inkscape::SelTrans::skew(SPSelTransHandle const &handle, NR::Point &pt, guint state)
+void Inkscape::SelTrans::skew(SPSelTransHandle const &handle, NR::Point &pt, guint /*state*/)
 {
     NR::Point const offset = _point - _origin;
 
@@ -1381,7 +1441,7 @@ void Inkscape::SelTrans::skew(SPSelTransHandle const &handle, NR::Point &pt, gui
     transform(skew, _origin);
 }
 
-void Inkscape::SelTrans::rotate(NR::Point &pt, guint state)
+void Inkscape::SelTrans::rotate(NR::Point &pt, guint /*state*/)
 {
     NR::Point const offset = _point - _origin;
 
@@ -1402,7 +1462,7 @@ void Inkscape::SelTrans::rotate(NR::Point &pt, guint state)
     transform(rotate, _origin);
 }
 
-void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
+void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint /*state*/)
 {
     seltrans->setCenter(pt);
 }
@@ -1433,7 +1493,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
         ** FIXME: this will snap to more than just the grid, nowadays.
         */
 
-        dxy = m.freeSnap(Snapper::SNAP_POINT, dxy, NULL).getPoint();
+        dxy = m.freeSnap(Snapper::SNAPPOINT_NODE, dxy, NULL).getPoint();
 
     } else if (!shift) {
 
@@ -1450,13 +1510,13 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
             /* Snap to things, and also constrain to horizontal or vertical movement */
 
             for (unsigned int dim = 0; dim < 2; dim++) {
-                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::BBOX_POINT,
+                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                                          _bbox_points,
                                                          it,
                                                          Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
                                                          dxy));
-                            
-                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAP_POINT,
+
+                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
                                                          _snap_points,
                                                          it,
                                                          Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
@@ -1465,12 +1525,20 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 
         } else {
 
-            /* Snap to things with no constraint */
+            // Let's leave this timer code here for a while. I'll probably need it in the near future (Diederik van Lierop)
+            /* GTimeVal starttime;
+            GTimeVal endtime;
+               g_get_current_time(&starttime); */
 
-            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::BBOX_POINT,
+            /* Snap to things with no constraint */
+                       s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                               _bbox_points, it, dxy));
-            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAP_POINT,
+            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
                                               _snap_points, it, dxy));
+
+               /*g_get_current_time(&endtime);
+               double elapsed = ((((double)endtime.tv_sec - starttime.tv_sec) * G_USEC_PER_SEC + (endtime.tv_usec - starttime.tv_usec))) / 1000.0;
+               std::cout << "Time spent snapping: " << elapsed << std::endl; */
         }
 
         /* Pick one */