From: speleo3 Date: Sat, 20 Dec 2008 10:12:04 +0000 (+0000) Subject: object-snapper.cpp X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e8f467c9c30a028b10ca166c02e49df62bf753c2;p=inkscape.git object-snapper.cpp * fix snapping to clip/mask with parent transform * replace matrix_to_desktop call sp-item.h sp-item.cpp * improve snapping to clip/mask with parent transform * remove matrix_to_desktop/matrix_from_desktop * use desktop->doc2dt() with sp_item_i2d_affine(...) desktop.h desktop.cpp * new method: dt2doc() selection-chemistry.cpp * remove awkward matrix_to_desktop(matrix_from_desktop(...)) calls --- diff --git a/src/desktop.cpp b/src/desktop.cpp index cd39e77ae..85c53be6f 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1806,6 +1806,12 @@ Geom::Matrix SPDesktop::doc2dt() const return _doc2dt; } +Geom::Matrix SPDesktop::dt2doc() const +{ + // doc2dt is its own inverse + return _doc2dt; +} + Geom::Point SPDesktop::doc2dt(Geom::Point const &p) const { return p * _doc2dt; @@ -1813,7 +1819,7 @@ Geom::Point SPDesktop::doc2dt(Geom::Point const &p) const Geom::Point SPDesktop::dt2doc(Geom::Point const &p) const { - return p * _doc2dt.inverse(); + return p * dt2doc(); } diff --git a/src/desktop.h b/src/desktop.h index ce82f4ea6..b55d9da01 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -310,6 +310,7 @@ struct SPDesktop : public Inkscape::UI::View::View Geom::Point w2d(Geom::Point const &p) const; Geom::Point d2w(Geom::Point const &p) const; Geom::Matrix doc2dt() const; + Geom::Matrix dt2doc() const; Geom::Point doc2dt(Geom::Point const &p) const; Geom::Point dt2doc(Geom::Point const &p) const; diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 922c35bcb..cf10ab5e2 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -112,25 +112,19 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, if (it == NULL || i == it->end()) { SPItem *item = SP_ITEM(o); - Geom::Matrix transform = Geom::identity(); if (item) { SPObject *obj = NULL; - if (clip_or_mask) { // If the current item is a clipping path or a mask - // then store the transformation of the clipped path or mask itself - // but also take into account the additional affine of the object - // being clipped / masked - transform = to_2geom(item->transform) * additional_affine; - } else { // cannot clip or mask more than once + if (!clip_or_mask) { // cannot clip or mask more than once // The current item is not a clipping path or a mask, but might // still be the subject of clipping or masking itself ; if so, then // we should also consider that path or mask for snapping to obj = SP_OBJECT(item->clip_ref->getObject()); if (obj) { - _findCandidates(obj, it, false, bbox_to_snap, snap_dim, true, item->transform); + _findCandidates(obj, it, false, bbox_to_snap, snap_dim, true, sp_item_i2doc_affine(item)); } obj = SP_OBJECT(item->mask_ref->getObject()); if (obj) { - _findCandidates(obj, it, false, bbox_to_snap, snap_dim, true, item->transform); + _findCandidates(obj, it, false, bbox_to_snap, snap_dim, true, sp_item_i2doc_affine(item)); } } } @@ -144,7 +138,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // insert an additional transformation in document coordinates (code copied from sp_item_i2d_affine) sp_item_invoke_bbox(item, bbox_of_item, - sp_item_i2doc_affine(item) * matrix_to_desktop(additional_affine, item), + sp_item_i2doc_affine(item) * additional_affine * _snapmanager->getDesktop()->doc2dt(), true); } else { sp_item_invoke_bbox(item, bbox_of_item, sp_item_i2d_affine(item), true); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index b6a194d9a..92f751e85 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1216,9 +1216,9 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Matrix cons sp_object_read_attr (SP_OBJECT (item), "transform"); // calculate the matrix we need to apply to the clone to cancel its induced transform from its original - Geom::Matrix parent_transform = sp_item_i2doc_affine(SP_ITEM(SP_OBJECT_PARENT (item))); - Geom::Matrix t = parent_transform * matrix_to_desktop (matrix_from_desktop (affine, item), item) * parent_transform.inverse(); - Geom::Matrix t_inv =parent_transform * matrix_to_desktop (matrix_from_desktop (affine.inverse(), item), item) * parent_transform.inverse(); + Geom::Matrix parent2dt = sp_item_i2d_affine(SP_ITEM(SP_OBJECT_PARENT (item))); + Geom::Matrix t = parent2dt * affine * parent2dt.inverse(); + Geom::Matrix t_inv = t.inverse(); Geom::Matrix result = t_inv * item->transform * t; if ((prefs_parallel || prefs_unmoved) && affine.isTranslation()) { diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 519ed2a45..fb13b1770 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -33,6 +33,7 @@ #include "document.h" #include "uri.h" #include "inkscape.h" +#include "desktop.h" #include "desktop-handles.h" #include "style.h" @@ -978,6 +979,7 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPref clips_and_masks.push_back(SP_OBJECT(item->clip_ref->getObject())); clips_and_masks.push_back(SP_OBJECT(item->mask_ref->getObject())); + SPDesktop *desktop = inkscape_active_desktop(); for (std::list::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) { if (*o) { // obj is a group object, the children are the actual clippers @@ -990,7 +992,7 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPref for (std::vector::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) { // All snappoints are in desktop coordinates, but the item's transformation is // in document coordinates. Hence the awkward construction below - *p = (*p_orig) * matrix_to_desktop (matrix_from_desktop (item->transform, item), item); + *p = desktop->dt2doc(*p_orig) * sp_item_i2d_affine(item); } } } @@ -1551,34 +1553,8 @@ Geom::Matrix sp_item_i2d_affine(SPItem const *item) g_assert(item != NULL); g_assert(SP_IS_ITEM(item)); - Geom::Matrix const ret( sp_item_i2doc_affine(item) - * Geom::Scale(1, -1) - * Geom::Translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item))) ); - return ret; -} - -/** - * Converts a matrix \a m into the desktop coords of the \a item. - * Will become a noop when we eliminate the coordinate flipping. - */ -Geom::Matrix matrix_to_desktop(Geom::Matrix const m, SPItem const *item) -{ - Geom::Matrix const ret(m - * Geom::Translate(0, -sp_document_height(SP_OBJECT_DOCUMENT(item))) - * Geom::Scale(1, -1)); - return ret; -} - -/** - * Converts a matrix \a m from the desktop coords of the \a item. - * Will become a noop when we eliminate the coordinate flipping. - */ -Geom::Matrix matrix_from_desktop(Geom::Matrix const m, SPItem const *item) -{ - Geom::Matrix const ret(Geom::Scale(1, -1) - * Geom::Translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item))) - * m); - return ret; + SPDesktop *desktop = inkscape_active_desktop(); + return sp_item_i2doc_affine(item) * desktop->doc2dt(); } void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt) diff --git a/src/sp-item.h b/src/sp-item.h index 03fec93e6..f1ec6f434 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -258,9 +258,6 @@ Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest); Geom::Matrix sp_item_i2doc_affine(SPItem const *item); -Geom::Matrix matrix_to_desktop (Geom::Matrix m, SPItem const *item); -Geom::Matrix matrix_from_desktop (Geom::Matrix m, SPItem const *item); - /* fixme: - these are evil, but OK */ /* Fill *TRANSFORM with the item-to-desktop transform. See doc/coordinates.txt