From f6562a00dd80b77c5bebefea752ab2959245087c Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Sat, 20 Mar 2021 00:15:05 +0200 Subject: [PATCH 01/11] Moved sp-item-update-cns.h function into SPItem. The function sp_item_update_cns(SPItem &item, SPDesktop const &desktop) is now SPItem::updateCns(SPDesktop const &desktop). --- src/object/CMakeLists.txt | 2 -- src/object/sp-item-update-cns.cpp | 50 ------------------------------- src/object/sp-item-update-cns.h | 32 -------------------- src/object/sp-item.cpp | 24 +++++++++++++++ src/object/sp-item.h | 6 ++++ src/selection-chemistry.cpp | 2 +- 6 files changed, 31 insertions(+), 85 deletions(-) delete mode 100644 src/object/sp-item-update-cns.cpp delete mode 100644 src/object/sp-item-update-cns.h diff --git a/src/object/CMakeLists.txt b/src/object/CMakeLists.txt index e44d56f581..b10019bc06 100644 --- a/src/object/CMakeLists.txt +++ b/src/object/CMakeLists.txt @@ -35,7 +35,6 @@ set(object_SRC sp-item-group.cpp sp-item-rm-unsatisfied-cns.cpp sp-item-transform.cpp - sp-item-update-cns.cpp sp-item.cpp sp-line.cpp sp-linear-gradient.cpp @@ -124,7 +123,6 @@ set(object_SRC sp-item-group.h sp-item-rm-unsatisfied-cns.h sp-item-transform.h - sp-item-update-cns.h sp-item.h sp-line.h sp-linear-gradient.h diff --git a/src/object/sp-item-update-cns.cpp b/src/object/sp-item-update-cns.cpp deleted file mode 100644 index 516fb67c7c..0000000000 --- a/src/object/sp-item-update-cns.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include "satisfied-guide-cns.h" - -#include "sp-item-update-cns.h" -#include "sp-guide.h" - -void sp_item_update_cns(SPItem &item, SPDesktop const &desktop) -{ - std::vector snappoints; - item.getSnappoints(snappoints, nullptr); - /* TODO: Implement the ordering. */ - std::vector found_cns; - satisfied_guide_cns(desktop, snappoints, found_cns); - /* effic: It might be nice to avoid an n^2 algorithm, but in practice n will be - small enough that it's still usually more efficient. */ - - for (auto cn : found_cns) - { - if ( std::find(item.constraints.begin(), - item.constraints.end(), - cn) - == item.constraints.end() ) - { - item.constraints.push_back(cn); - cn.g->attached_items.emplace_back(&item, cn.snappoint_ix); - } - } -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/object/sp-item-update-cns.h b/src/object/sp-item-update-cns.h deleted file mode 100644 index 3ff0d62622..0000000000 --- a/src/object/sp-item-update-cns.h +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SP_ITEM_UPDATE_CNS_H -#define SEEN_SP_ITEM_UPDATE_CNS_H - -#include <2geom/forward.h> - -class SPDesktop; -class SPItem; - -void sp_item_update_cns(SPItem &item, SPDesktop const &desktop); - - -#endif // SEEN_SP_ITEM_UPDATE_CNS_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 19e7f0e878..4c5b7588b4 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -36,6 +36,7 @@ #include "sp-guide.h" #include "sp-hatch.h" #include "sp-item-rm-unsatisfied-cns.h" +#include "satisfied-guide-cns.h" #include "sp-mask.h" #include "sp-pattern.h" #include "sp-rect.h" @@ -130,6 +131,29 @@ SPAvoidRef &SPItem::getAvoidRef() return *avoidRef; } +void SPItem::updateCns(SPDesktop const &desktop) +{ + std::vector snappoints; + this->getSnappoints(snappoints, nullptr); + /* TODO: Implement the ordering. */ + std::vector found_cns; + satisfied_guide_cns(desktop, snappoints, found_cns); + /* effic: It might be nice to avoid an n^2 algorithm, but in practice n will be + small enough that it's still usually more efficient. */ + + for (auto cn : found_cns) + { + if ( std::find(this->constraints.begin(), + this->constraints.end(), + cn) + == this->constraints.end() ) + { + this->constraints.push_back(cn); + cn.g->attached_items.emplace_back(this, cn.snappoint_ix); + } + } +} + bool SPItem::isVisibleAndUnlocked() const { return (!isHidden() && !isLocked()); } diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 08b45f1b00..2c1a810893 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -40,6 +40,7 @@ class SPMask; class SPMaskReference; class SPAvoidRef; class SPPattern; +class SPDesktop; struct SPPrintContext; typedef unsigned int guint32; @@ -164,6 +165,11 @@ public: SPAvoidRef &getAvoidRef(); +#ifndef SEEN_SP_ITEM_UPDATE_CNS_H +#define SEEN_SP_ITEM_UPDATE_CNS_H + void updateCns(SPDesktop const &desktop); +#endif + private: SPClipPathReference *clip_ref; SPMaskReference *mask_ref; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 5b66fdcdce..01eaa9e453 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1664,7 +1664,7 @@ void ObjectSet::applyAffine(Geom::Affine const &affine, bool set_i2d, bool compe #if 0 /* Re-enable this once persistent guides have a graphical indication. At the time of writing, this is the only place to re-enable. */ - sp_item_update_cns(*item, desktop()); + item->updateCns(*desktop()); #endif // we're moving both a clone and its original or any ancestor in clone chain? -- GitLab From e8d26cdab1cd88f6f442279154f0d874a5d61c39 Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Sat, 20 Mar 2021 12:08:03 +0200 Subject: [PATCH 02/11] Moved sp-item-rm-unsatisfied-cns.h function into SPItem. sp_item_rm_unsatisfied_cns(SPItem &item) is now SPItem::rmUnsatisfiedCns(). --- src/doxygen-main.dox | 2 +- src/object/CMakeLists.txt | 2 - src/object/README | 2 - src/object/sp-item-rm-unsatisfied-cns.cpp | 53 ----------------------- src/object/sp-item-rm-unsatisfied-cns.h | 29 ------------- src/object/sp-item.cpp | 30 +++++++++++-- src/object/sp-item.h | 5 +++ src/sp-item-notify-moveto.cpp | 3 +- 8 files changed, 34 insertions(+), 92 deletions(-) delete mode 100644 src/object/sp-item-rm-unsatisfied-cns.cpp delete mode 100644 src/object/sp-item-rm-unsatisfied-cns.h diff --git a/src/doxygen-main.dox b/src/doxygen-main.dox index 6d31f1fadb..9209fc6cfd 100644 --- a/src/doxygen-main.dox +++ b/src/doxygen-main.dox @@ -201,7 +201,7 @@ namespace XML {} * - SPFlowline [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowregionbreak [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPGuide [\ref sp-guide.cpp, \ref sp-guide.h] - * - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-notify-moveto.cpp, \ref sp-item-rm-unsatisfied-cns.cpp, \ref sp-item-transform.cpp, \ref sp-item-update-cns.cpp, ] + * - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-notify-moveto.cpp, \ref sp-item-transform.cpp, ] * - SPFlowdiv [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowpara [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowregion [\ref sp-flowregion.cpp, \ref sp-flowregion.h] diff --git a/src/object/CMakeLists.txt b/src/object/CMakeLists.txt index b10019bc06..c9fabbd6ae 100644 --- a/src/object/CMakeLists.txt +++ b/src/object/CMakeLists.txt @@ -33,7 +33,6 @@ set(object_SRC sp-hatch.cpp sp-image.cpp sp-item-group.cpp - sp-item-rm-unsatisfied-cns.cpp sp-item-transform.cpp sp-item.cpp sp-line.cpp @@ -121,7 +120,6 @@ set(object_SRC sp-hatch.h sp-image.h sp-item-group.h - sp-item-rm-unsatisfied-cns.h sp-item-transform.h sp-item.h sp-line.h diff --git a/src/object/README b/src/object/README index aded8d607e..207c265758 100644 --- a/src/object/README +++ b/src/object/README @@ -102,9 +102,7 @@ Other related files: sp-gradient-spread.h sp-gradient-units.h sp-gradient-vector.h - sp-item-rm-unsatisfied-cns.h sp-item-transform.h - sp-item-update-cns.h sp-marker-loc.h sp-mesh-array.h sp-paint-server-reference.h diff --git a/src/object/sp-item-rm-unsatisfied-cns.cpp b/src/object/sp-item-rm-unsatisfied-cns.cpp deleted file mode 100644 index 3b476e20d0..0000000000 --- a/src/object/sp-item-rm-unsatisfied-cns.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include <2geom/coord.h> -#include - -#include "remove-last.h" -#include "sp-guide.h" -#include "sp-item-rm-unsatisfied-cns.h" - -void sp_item_rm_unsatisfied_cns(SPItem &item) -{ - if (item.constraints.empty()) { - return; - } - std::vector snappoints; - item.getSnappoints(snappoints, nullptr); - for (unsigned i = item.constraints.size(); i--;) { - g_assert( i < item.constraints.size() ); - SPGuideConstraint const &cn = item.constraints[i]; - int const snappoint_ix = cn.snappoint_ix; - g_assert( snappoint_ix < int(snappoints.size()) ); - - if (!Geom::are_near(cn.g->getDistanceFrom(snappoints[snappoint_ix].getPoint()), 0, 1e-2)) { - - remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix)); - - g_assert( i < item.constraints.size() ); - - item.constraints.erase(item.constraints.begin() + i); - } - } -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/object/sp-item-rm-unsatisfied-cns.h b/src/object/sp-item-rm-unsatisfied-cns.h deleted file mode 100644 index ac03b74251..0000000000 --- a/src/object/sp-item-rm-unsatisfied-cns.h +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H -#define SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H - -class SPItem; - -void sp_item_rm_unsatisfied_cns(SPItem &item); - - -#endif // SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 4c5b7588b4..b4277c7851 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -31,12 +31,12 @@ #include "conditions.h" #include "filter-chemistry.h" +#include "remove-last.h" +#include "satisfied-guide-cns.h" #include "sp-clippath.h" #include "sp-desc.h" #include "sp-guide.h" #include "sp-hatch.h" -#include "sp-item-rm-unsatisfied-cns.h" -#include "satisfied-guide-cns.h" #include "sp-mask.h" #include "sp-pattern.h" #include "sp-rect.h" @@ -154,6 +154,30 @@ void SPItem::updateCns(SPDesktop const &desktop) } } +void SPItem::rmUnsatisfiedCns() +{ + if (this->constraints.empty()) { + return; + } + std::vector snappoints; + this->getSnappoints(snappoints, nullptr); + for (unsigned i = this->constraints.size(); i--;) { + g_assert( i < this->constraints.size() ); + SPGuideConstraint const &cn = this->constraints[i]; + int const snappoint_ix = cn.snappoint_ix; + g_assert( snappoint_ix < int(snappoints.size()) ); + + if (!Geom::are_near(cn.g->getDistanceFrom(snappoints[snappoint_ix].getPoint()), 0, 1e-2)) { + + remove_last(cn.g->attached_items, SPGuideAttachment(this, cn.snappoint_ix)); + + g_assert( i < this->constraints.size() ); + + this->constraints.erase(this->constraints.begin() + i); + } + } +} + bool SPItem::isVisibleAndUnlocked() const { return (!isHidden() && !isLocked()); } @@ -1617,7 +1641,7 @@ void SPItem::set_item_transform(Geom::Affine const &transform_matrix) /* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a transformation. It's apparently not used anywhere else. */ requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_USER_MODIFIED_FLAG_B); - sp_item_rm_unsatisfied_cns(*this); + this->rmUnsatisfiedCns(); } } diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 2c1a810893..8d0355b967 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -170,6 +170,11 @@ public: void updateCns(SPDesktop const &desktop); #endif +#ifndef SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H +#define SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H + void rmUnsatisfiedCns(); +#endif + private: SPClipPathReference *clip_ref; SPMaskReference *mask_ref; diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp index 57e44f45aa..d62336e472 100644 --- a/src/sp-item-notify-moveto.cpp +++ b/src/sp-item-notify-moveto.cpp @@ -18,7 +18,6 @@ #include "object/sp-guide.h" #include "object/sp-item.h" -#include "object/sp-item-rm-unsatisfied-cns.h" #define return_if_fail(test) if (!(test)) { printf("WARNING: assertion '%s' failed", #test); return; } @@ -65,7 +64,7 @@ void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoin item.doWriteTransform(item.transform); } - sp_item_rm_unsatisfied_cns(item); + item.rmUnsatisfiedCns(); #if 0 /* nyi */ move_cn_to_front(mv_g, snappoint_ix, item.constraints); /** \note If the guideline is connected to multiple snappoints of -- GitLab From 5042ecfd66e41686fa831b6d99d120f2c95f53ee Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Sun, 21 Mar 2021 11:45:01 +0200 Subject: [PATCH 03/11] Removed satisfied-guide-cns.h and the unnecessary guards. Since satisfied-guide-cns.h only contained one function that was being called only once in SPItem, the function is moved to SPItem as a private static function and satisfied-guide-cns.h is removed. Also, the unnecessary guards around updateCns and rmUnsatisfiedCns was removed as well. --- src/CMakeLists.txt | 2 -- src/doxygen-main.dox | 2 +- src/object/sp-item.cpp | 18 +++++++++++++-- src/object/sp-item.h | 11 ++++----- src/satisfied-guide-cns.cpp | 45 ------------------------------------- src/satisfied-guide-cns.h | 37 ------------------------------ 6 files changed, 21 insertions(+), 94 deletions(-) delete mode 100644 src/satisfied-guide-cns.cpp delete mode 100644 src/satisfied-guide-cns.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55ad77e912..e7f70d6879 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,6 @@ set(inkscape_SRC rdf.cpp removeoverlap.cpp rubberband.cpp - satisfied-guide-cns.cpp selcue.cpp selection-chemistry.cpp selection-describer.cpp @@ -164,7 +163,6 @@ set(inkscape_SRC remove-last.h removeoverlap.h rubberband.h - satisfied-guide-cns.h selcue.h selection-chemistry.h selection-describer.h diff --git a/src/doxygen-main.dox b/src/doxygen-main.dox index 9209fc6cfd..cf1b8bd02f 100644 --- a/src/doxygen-main.dox +++ b/src/doxygen-main.dox @@ -295,7 +295,7 @@ namespace XML {} * * Snapper, GridSnapper, GuideSnapper [\ref snap.cpp, \ref snap.h] * - * SPGuide [\ref sp-guide.cpp, \ref sp-guide.h, \ref satisfied-guide-cns.cpp, \ref sp-guide-attachment.h, \ref sp-guide-constraint.h] + * SPGuide [\ref sp-guide.cpp, \ref sp-guide.h, \ref sp-guide-attachment.h, \ref sp-guide-constraint.h] * * [\ref help.cpp] [\ref inkscape.cpp] [\ref inkscape-stock.cpp] * [\ref interface.cpp] [\ref main.cpp, \ref winmain.cpp] diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index b4277c7851..966a30a6ee 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -32,7 +32,6 @@ #include "filter-chemistry.h" #include "remove-last.h" -#include "satisfied-guide-cns.h" #include "sp-clippath.h" #include "sp-desc.h" #include "sp-guide.h" @@ -137,7 +136,7 @@ void SPItem::updateCns(SPDesktop const &desktop) this->getSnappoints(snappoints, nullptr); /* TODO: Implement the ordering. */ std::vector found_cns; - satisfied_guide_cns(desktop, snappoints, found_cns); + satisfiedGuideCns(desktop, snappoints, found_cns); /* effic: It might be nice to avoid an n^2 algorithm, but in practice n will be small enough that it's still usually more efficient. */ @@ -698,6 +697,21 @@ void SPItem::stroke_ps_ref_changed(SPObject *old_ps, SPObject *ps, SPItem *item) } } +void SPItem::satisfiedGuideCns(SPDesktop const &desktop, + std::vector const &snappoints, + std::vector &cns) +{ + SPNamedView const &nv = *desktop.getNamedView(); + for(auto guide : nv.guides) { + SPGuide &g = *guide; + for (unsigned int i = 0; i < snappoints.size(); ++i) { + if (Geom::are_near(g.getDistanceFrom(snappoints[i].getPoint()), 0, 1e-2)) { + cns.emplace_back(&g, i); + } + } + } +} + void SPItem::update(SPCtx* ctx, guint flags) { SPItemCtx const *ictx = reinterpret_cast(ctx); diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 8d0355b967..0e26fee1c2 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -165,15 +165,8 @@ public: SPAvoidRef &getAvoidRef(); -#ifndef SEEN_SP_ITEM_UPDATE_CNS_H -#define SEEN_SP_ITEM_UPDATE_CNS_H void updateCns(SPDesktop const &desktop); -#endif - -#ifndef SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H -#define SEEN_SP_ITEM_RM_UNSATISFIED_CNS_H void rmUnsatisfiedCns(); -#endif private: SPClipPathReference *clip_ref; @@ -423,6 +416,10 @@ private: static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); static void fill_ps_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); static void stroke_ps_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); + static void satisfiedGuideCns(SPDesktop const &desktop, + std::vector const &snappoints, + std::vector &cns); + public: void rotate_rel(Geom::Rotate const &rotation); diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp deleted file mode 100644 index 5eb2a1dfbc..0000000000 --- a/src/satisfied-guide-cns.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include <2geom/coord.h> - -#include "satisfied-guide-cns.h" - -#include "desktop.h" - -#include "object/sp-guide.h" -#include "object/sp-namedview.h" - -void satisfied_guide_cns(SPDesktop const &desktop, - std::vector const &snappoints, - std::vector &cns) -{ - SPNamedView const &nv = *desktop.getNamedView(); - for(auto guide : nv.guides) { - SPGuide &g = *guide; - for (unsigned int i = 0; i < snappoints.size(); ++i) { - if (Geom::are_near(g.getDistanceFrom(snappoints[i].getPoint()), 0, 1e-2)) { - cns.emplace_back(&g, i); - } - } - } -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/satisfied-guide-cns.h b/src/satisfied-guide-cns.h deleted file mode 100644 index 575009ffb5..0000000000 --- a/src/satisfied-guide-cns.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SATISFIED_GUIDE_CNS_H -#define SEEN_SATISFIED_GUIDE_CNS_H - -#include <2geom/forward.h> -#include - -#include "snap-candidate.h" - -class SPDesktop; -class SPGuideConstraint; - -void satisfied_guide_cns(SPDesktop const &desktop, - std::vector const &snappoints, - std::vector &cns); - - -#endif // SEEN_SATISFIED_GUIDE_CNS_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- GitLab From 1cb12534b6615af608764bdcdd6cacd65c0b784f Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Sun, 21 Mar 2021 14:38:27 +0200 Subject: [PATCH 04/11] Removed the functions SPItem::updateCns and SPItem::satisfiedGuideCns The two functions have no use in the code. The only use of them is disabled. Thus deleted along with the disabled reference to them. --- src/object/sp-item.cpp | 38 ------------------------------------- src/object/sp-item.h | 5 ----- src/selection-chemistry.cpp | 5 ----- 3 files changed, 48 deletions(-) diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 966a30a6ee..79b8541f03 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -130,29 +130,6 @@ SPAvoidRef &SPItem::getAvoidRef() return *avoidRef; } -void SPItem::updateCns(SPDesktop const &desktop) -{ - std::vector snappoints; - this->getSnappoints(snappoints, nullptr); - /* TODO: Implement the ordering. */ - std::vector found_cns; - satisfiedGuideCns(desktop, snappoints, found_cns); - /* effic: It might be nice to avoid an n^2 algorithm, but in practice n will be - small enough that it's still usually more efficient. */ - - for (auto cn : found_cns) - { - if ( std::find(this->constraints.begin(), - this->constraints.end(), - cn) - == this->constraints.end() ) - { - this->constraints.push_back(cn); - cn.g->attached_items.emplace_back(this, cn.snappoint_ix); - } - } -} - void SPItem::rmUnsatisfiedCns() { if (this->constraints.empty()) { @@ -697,21 +674,6 @@ void SPItem::stroke_ps_ref_changed(SPObject *old_ps, SPObject *ps, SPItem *item) } } -void SPItem::satisfiedGuideCns(SPDesktop const &desktop, - std::vector const &snappoints, - std::vector &cns) -{ - SPNamedView const &nv = *desktop.getNamedView(); - for(auto guide : nv.guides) { - SPGuide &g = *guide; - for (unsigned int i = 0; i < snappoints.size(); ++i) { - if (Geom::are_near(g.getDistanceFrom(snappoints[i].getPoint()), 0, 1e-2)) { - cns.emplace_back(&g, i); - } - } - } -} - void SPItem::update(SPCtx* ctx, guint flags) { SPItemCtx const *ictx = reinterpret_cast(ctx); diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 0e26fee1c2..25047f7c71 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -165,7 +165,6 @@ public: SPAvoidRef &getAvoidRef(); - void updateCns(SPDesktop const &desktop); void rmUnsatisfiedCns(); private: @@ -416,10 +415,6 @@ private: static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); static void fill_ps_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); static void stroke_ps_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); - static void satisfiedGuideCns(SPDesktop const &desktop, - std::vector const &snappoints, - std::vector &cns); - public: void rotate_rel(Geom::Rotate const &rotation); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 01eaa9e453..43340594f3 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1662,11 +1662,6 @@ void ObjectSet::applyAffine(Geom::Affine const &affine, bool set_i2d, bool compe if (set_i2d && item->isCenterSet()) old_center = item->getCenter(); -#if 0 /* Re-enable this once persistent guides have a graphical indication. - At the time of writing, this is the only place to re-enable. */ - item->updateCns(*desktop()); -#endif - // we're moving both a clone and its original or any ancestor in clone chain? bool transform_clone_with_original = object_set_contains_original(item, this); -- GitLab From ae8acd4822f42354f09bf5996e5fd21f19ef8f74 Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Mon, 22 Mar 2021 11:59:51 +0200 Subject: [PATCH 05/11] Removed sp-item-notify-moveto.h since it's never used. --- src/CMakeLists.txt | 2 - src/doxygen-main.dox | 2 +- src/object/sp-guide.cpp | 1 - src/sp-item-notify-moveto.cpp | 88 ----------------------------------- src/sp-item-notify-moveto.h | 32 ------------- 5 files changed, 1 insertion(+), 124 deletions(-) delete mode 100644 src/sp-item-notify-moveto.cpp delete mode 100644 src/sp-item-notify-moveto.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7f70d6879..d1c28104a1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,7 +75,6 @@ set(inkscape_SRC snapped-line.cpp snapped-point.cpp snapper.cpp - sp-item-notify-moveto.cpp style-internal.cpp style.cpp text-chemistry.cpp @@ -179,7 +178,6 @@ set(inkscape_SRC snapper.h sp-guide-attachment.h sp-guide-constraint.h - sp-item-notify-moveto.h streq.h strneq.h style-enums.h diff --git a/src/doxygen-main.dox b/src/doxygen-main.dox index cf1b8bd02f..30e7402992 100644 --- a/src/doxygen-main.dox +++ b/src/doxygen-main.dox @@ -201,7 +201,7 @@ namespace XML {} * - SPFlowline [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowregionbreak [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPGuide [\ref sp-guide.cpp, \ref sp-guide.h] - * - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-notify-moveto.cpp, \ref sp-item-transform.cpp, ] + * - SPItem [\ref sp-item.cpp, \ref sp-item.h, \ref sp-item-transform.cpp, ] * - SPFlowdiv [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowpara [\ref sp-flowdiv.cpp, \ref sp-flowdiv.h] * - SPFlowregion [\ref sp-flowregion.cpp, \ref sp-flowregion.h] diff --git a/src/object/sp-guide.cpp b/src/object/sp-guide.cpp index 406f615b53..55cf863171 100644 --- a/src/object/sp-guide.cpp +++ b/src/object/sp-guide.cpp @@ -31,7 +31,6 @@ #include "verbs.h" #include "sp-guide.h" -#include "sp-item-notify-moveto.h" #include "sp-namedview.h" #include "sp-root.h" diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp deleted file mode 100644 index d62336e472..0000000000 --- a/src/sp-item-notify-moveto.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -/** \file - * Implementation of sp_item_notify_moveto(). - */ - -#include <2geom/transforms.h> -#include - -#include "sp-item-notify-moveto.h" - -#include "object/sp-guide.h" -#include "object/sp-item.h" - -#define return_if_fail(test) if (!(test)) { printf("WARNING: assertion '%s' failed", #test); return; } - -/** - * Called by sp_guide_moveto to indicate that the guide line corresponding to g has been moved, and - * that consequently this item should move with it. - * - * \pre exist [cn in item.constraints] g eq cn.g. - */ -void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoint_ix, - double const position, bool const commit) -{ - return_if_fail(SP_IS_ITEM(&item)); - return_if_fail( unsigned(snappoint_ix) < 8 ); - Geom::Point const dir( mv_g.getNormal() ); - double const dir_lensq(dot(dir, dir)); - return_if_fail( dir_lensq != 0 ); - - std::vector snappoints; - item.getSnappoints(snappoints, nullptr); - return_if_fail( snappoint_ix < int(snappoints.size()) ); - - double const pos0 = dot(dir, snappoints[snappoint_ix].getPoint()); - /// \todo effic: skip if mv_g is already satisfied. - - /* Translate along dir to make dot(dir, snappoints(item)[snappoint_ix]) == position. */ - - /* Calculation: - dot(dir, snappoints[snappoint_ix] + s * dir) = position. - dot(dir, snappoints[snappoint_ix]) + dot(dir, s * dir) = position. - pos0 + s * dot(dir, dir) = position. - s * lensq(dir) = position - pos0. - s = (position - pos0) / dot(dir, dir). */ - Geom::Translate const tr( ( position - pos0 ) - * ( dir / dir_lensq ) ); - item.set_i2d_affine(item.i2dt_affine() * tr); - /// \todo Reget snappoints, check satisfied. - - if (commit) { - /// \todo Consider maintaining a set of dirty items. - - /* Commit repr. */ - { - item.doWriteTransform(item.transform); - } - - item.rmUnsatisfiedCns(); -#if 0 /* nyi */ - move_cn_to_front(mv_g, snappoint_ix, item.constraints); - /** \note If the guideline is connected to multiple snappoints of - * this item, then keeping those cns in order requires that the - * guide send notifications in order of increasing importance. - */ -#endif - } -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-item-notify-moveto.h b/src/sp-item-notify-moveto.h deleted file mode 100644 index d256f39e8e..0000000000 --- a/src/sp-item-notify-moveto.h +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2011 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SP_ITEM_NOTIFY_MOVETO_H -#define SEEN_SP_ITEM_NOTIFY_MOVETO_H - -class SPItem; -class SPGuide; - -void sp_item_notify_moveto(SPItem &item, SPGuide const &g, int const snappoint_ix, - double position, bool const commit); - - -#endif // SEEN_SP_ITEM_NOTIFY_MOVETO_H - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- GitLab From 4041385a5ca7294fd4483e5be0083a0d3c43f6b5 Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Mon, 22 Mar 2021 20:26:25 +0200 Subject: [PATCH 06/11] Removed SPItem::rmUnsatisfiedCns. SPItem::rmUnsatisfiedCns would remove elements from SPGuideAttachment::attached_items and SPGuideConstraint::constraints, but only if those containers are not empty and there is no place in the code which would add elements to those containers. --- src/object/sp-item.cpp | 25 ------------------------- src/object/sp-item.h | 2 -- 2 files changed, 27 deletions(-) diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 79b8541f03..5c209fb2b7 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -130,30 +130,6 @@ SPAvoidRef &SPItem::getAvoidRef() return *avoidRef; } -void SPItem::rmUnsatisfiedCns() -{ - if (this->constraints.empty()) { - return; - } - std::vector snappoints; - this->getSnappoints(snappoints, nullptr); - for (unsigned i = this->constraints.size(); i--;) { - g_assert( i < this->constraints.size() ); - SPGuideConstraint const &cn = this->constraints[i]; - int const snappoint_ix = cn.snappoint_ix; - g_assert( snappoint_ix < int(snappoints.size()) ); - - if (!Geom::are_near(cn.g->getDistanceFrom(snappoints[snappoint_ix].getPoint()), 0, 1e-2)) { - - remove_last(cn.g->attached_items, SPGuideAttachment(this, cn.snappoint_ix)); - - g_assert( i < this->constraints.size() ); - - this->constraints.erase(this->constraints.begin() + i); - } - } -} - bool SPItem::isVisibleAndUnlocked() const { return (!isHidden() && !isLocked()); } @@ -1617,7 +1593,6 @@ void SPItem::set_item_transform(Geom::Affine const &transform_matrix) /* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a transformation. It's apparently not used anywhere else. */ requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_USER_MODIFIED_FLAG_B); - this->rmUnsatisfiedCns(); } } diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 25047f7c71..c74f68a40b 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -165,8 +165,6 @@ public: SPAvoidRef &getAvoidRef(); - void rmUnsatisfiedCns(); - private: SPClipPathReference *clip_ref; SPMaskReference *mask_ref; -- GitLab From ab8ec7127697472f549759ab6466d6f49437cf2a Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Tue, 23 Mar 2021 12:13:18 +0200 Subject: [PATCH 07/11] Deleted some of the unused includes and functions. --- src/object/sp-guide.cpp | 40 ++++++++-------------------------------- src/object/sp-guide.h | 2 -- src/object/sp-item.cpp | 16 ++-------------- src/object/sp-item.h | 2 -- 4 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/object/sp-guide.cpp b/src/object/sp-guide.cpp index 55cf863171..3eebce2d2f 100644 --- a/src/object/sp-guide.cpp +++ b/src/object/sp-guide.cpp @@ -16,7 +16,6 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include #include #include #include @@ -252,7 +251,14 @@ SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::P } SPGuide *SPGuide::duplicate(){ - return SPGuide::createSPGuide(document, point_on_line, Geom::Point(point_on_line[Geom::X] + normal_to_line[Geom::Y],point_on_line[Geom::Y] - normal_to_line[Geom::X])); + return SPGuide::createSPGuide( + document, + point_on_line, + Geom::Point( + point_on_line[Geom::X] + normal_to_line[Geom::Y], + point_on_line[Geom::Y] - normal_to_line[Geom::X] + ) + ); } void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list > &pts) @@ -351,16 +357,6 @@ void SPGuide::sensitize(Inkscape::UI::Widget::Canvas *canvas, bool sensitive) assert(false); } -Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const -{ - return -(pt - point_on_line); -} - -double SPGuide::getDistanceFrom(Geom::Point const &pt) const -{ - return Geom::dot(pt - point_on_line, normal_to_line); -} - /** * \arg commit False indicates temporary moveto in response to motion event while dragging, * true indicates a "committing" version: in response to button release event after @@ -404,16 +400,6 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) //XML Tree being used here directly while it shouldn't be. sp_repr_set_point(getRepr(), "position", Geom::Point(newx, newy) ); } - -/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) - for (std::vector::const_iterator i(attached_items.begin()), - iEnd(attached_items.end()); - i != iEnd; ++i) - { - SPGuideAttachment const &att = *i; - sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit); - } -*/ } /** @@ -443,16 +429,6 @@ void SPGuide::set_normal(Geom::Point const normal_to_line, bool const commit) sp_repr_set_point(getRepr(), "orientation", normal); } - -/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) - for (std::vector::const_iterator i(attached_items.begin()), - iEnd(attached_items.end()); - i != iEnd; ++i) - { - SPGuideAttachment const &att = *i; - sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit); - } -*/ } void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bool const commit) diff --git a/src/object/sp-guide.h b/src/object/sp-guide.h index 7f2bb8d40b..22f8214bed 100644 --- a/src/object/sp-guide.h +++ b/src/object/sp-guide.h @@ -82,8 +82,6 @@ public: char* description(bool const verbose = true) const; double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); } - double getDistanceFrom(Geom::Point const &pt) const; - Geom::Point getPositionFrom(Geom::Point const &pt) const; protected: void build(SPDocument* doc, Inkscape::XML::Node* repr) override; diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 5c209fb2b7..f045ad986c 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -31,7 +31,6 @@ #include "conditions.h" #include "filter-chemistry.h" -#include "remove-last.h" #include "sp-clippath.h" #include "sp-desc.h" #include "sp-guide.h" @@ -47,7 +46,6 @@ #include "sp-use.h" #include "style.h" -#include "uri.h" #include "util/find-last-if.h" @@ -897,8 +895,6 @@ Geom::OptRect SPItem::documentPreferredBounds() const } } - - Geom::OptRect SPItem::documentGeometricBounds() const { return geometricBounds(i2doc_affine()); @@ -1087,15 +1083,6 @@ bool SPItem::isFiltered() const { return (style && style->filter.href && style->filter.href->getObject()); } - -SPObject* SPItem::isInMask() const { - SPObject* parent = this->parent; - while (parent && !dynamic_cast(parent)) { - parent = parent->parent; - } - return parent; -} - SPObject* SPItem::isInClipPath() const { SPObject* parent = this->parent; while (parent && !dynamic_cast(parent)) { @@ -1538,7 +1525,8 @@ void SPItem::doWriteTransform(Geom::Affine const &transform, Geom::Affine const (!preserve && // user did not chose to preserve all transforms (!clip_ref || !clip_ref->getObject()) && // the object does not have a clippath (!mask_ref || !mask_ref->getObject()) && // the object does not have a mask - !(!transform.isTranslation() && style && style->getFilter())) // the object does not have a filter, or the transform is translation (which is supposed to not affect filters) + !(!transform.isTranslation() && style && style->getFilter())) + // the object does not have a filter, or the transform is translation (which is supposed to not affect filters) ) { transform_attr = this->set_transform(transform); diff --git a/src/object/sp-item.h b/src/object/sp-item.h index c74f68a40b..62f931d10b 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -30,7 +30,6 @@ #include "snap-preferences.h" #include "snap-candidate.h" -//class SPGuideConstraint; #include "sp-guide-constraint.h" #include "xml/repr.h" @@ -40,7 +39,6 @@ class SPMask; class SPMaskReference; class SPAvoidRef; class SPPattern; -class SPDesktop; struct SPPrintContext; typedef unsigned int guint32; -- GitLab From 31f3049a78baf4b76a04d66d72c8e33fc76c397a Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Tue, 23 Mar 2021 13:25:39 +0200 Subject: [PATCH 08/11] Brought SPItem::isInMask back since it might be needed. --- src/object/sp-item.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index f045ad986c..8bcd62a7a4 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -1083,6 +1083,14 @@ bool SPItem::isFiltered() const { return (style && style->filter.href && style->filter.href->getObject()); } +SPObject* SPItem::isInMask() const { + SPObject* parent = this->parent; + while (parent && !dynamic_cast(parent)) { + parent = parent->parent; + } + return parent; +} + SPObject* SPItem::isInClipPath() const { SPObject* parent = this->parent; while (parent && !dynamic_cast(parent)) { -- GitLab From ffd488ca96edd9f65424ea9c91de2fc7ced4518c Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Tue, 23 Mar 2021 15:40:50 +0200 Subject: [PATCH 09/11] Removed the last references to SPGuideAttachment and SPGuideConstraint from sp_guide_remove. SPGuideAttachment and SPGuideConstraint were only being used in in containers that are only used in sp_guide_remove. There were no place where the containers get filled. Thus, it's safe to remove the reference from sp_guide_remove. By removing the last reference for them, it's possible now to completely get rid of sp_guide_remove.h, sp-guide-attachment.h and sp-guide-constraint.h. --- src/CMakeLists.txt | 3 --- src/doxygen-main.dox | 2 +- src/object/sp-guide.cpp | 10 -------- src/object/sp-guide.h | 5 ---- src/object/sp-item.h | 3 --- src/remove-last.h | 38 ---------------------------- src/sp-guide-attachment.h | 52 --------------------------------------- src/sp-guide-constraint.h | 52 --------------------------------------- 8 files changed, 1 insertion(+), 164 deletions(-) delete mode 100644 src/remove-last.h delete mode 100644 src/sp-guide-attachment.h delete mode 100644 src/sp-guide-constraint.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1c28104a1..05cb321608 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,7 +159,6 @@ set(inkscape_SRC proj_pt.h pure-transform.h rdf.h - remove-last.h removeoverlap.h rubberband.h selcue.h @@ -176,8 +175,6 @@ set(inkscape_SRC snapped-line.h snapped-point.h snapper.h - sp-guide-attachment.h - sp-guide-constraint.h streq.h strneq.h style-enums.h diff --git a/src/doxygen-main.dox b/src/doxygen-main.dox index 30e7402992..0780525851 100644 --- a/src/doxygen-main.dox +++ b/src/doxygen-main.dox @@ -295,7 +295,7 @@ namespace XML {} * * Snapper, GridSnapper, GuideSnapper [\ref snap.cpp, \ref snap.h] * - * SPGuide [\ref sp-guide.cpp, \ref sp-guide.h, \ref sp-guide-attachment.h, \ref sp-guide-constraint.h] + * SPGuide [\ref sp-guide.cpp, \ref sp-guide.h] * * [\ref help.cpp] [\ref inkscape.cpp] [\ref inkscape-stock.cpp] * [\ref interface.cpp] [\ref main.cpp, \ref winmain.cpp] diff --git a/src/object/sp-guide.cpp b/src/object/sp-guide.cpp index 3eebce2d2f..6110a4485b 100644 --- a/src/object/sp-guide.cpp +++ b/src/object/sp-guide.cpp @@ -26,7 +26,6 @@ #include "document-undo.h" #include "helper-fns.h" #include "inkscape.h" -#include "remove-last.h" #include "verbs.h" #include "sp-guide.h" @@ -526,15 +525,6 @@ void sp_guide_remove(SPGuide *guide) { g_assert(SP_IS_GUIDE(guide)); - for (std::vector::const_iterator i(guide->attached_items.begin()), - iEnd(guide->attached_items.end()); - i != iEnd; ++i) - { - SPGuideAttachment const &att = *i; - remove_last(att.item->constraints, SPGuideConstraint(guide, att.snappoint_ix)); - } - guide->attached_items.clear(); - //XML Tree being used directly while it shouldn't be. sp_repr_unparent(guide->getRepr()); } diff --git a/src/object/sp-guide.h b/src/object/sp-guide.h index 22f8214bed..dfcd6b722f 100644 --- a/src/object/sp-guide.h +++ b/src/object/sp-guide.h @@ -18,7 +18,6 @@ #include #include "sp-object.h" -#include "sp-guide-attachment.h" typedef unsigned int guint32; extern "C" { @@ -26,8 +25,6 @@ extern "C" { } class SPDesktop; -struct SPCanvasGroup; -struct SPGuideLine; #define SP_GUIDE(obj) (dynamic_cast((SPObject*)obj)) #define SP_IS_GUIDE(obj) (dynamic_cast((SPObject*)obj) != NULL) @@ -96,8 +93,6 @@ protected: guint32 color; guint32 hicolor; -public: - std::vector attached_items; // unused }; // These functions rightfully belong to SPDesktop. What gives?! diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 62f931d10b..437b41f6b5 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -30,7 +30,6 @@ #include "snap-preferences.h" #include "snap-candidate.h" -#include "sp-guide-constraint.h" #include "xml/repr.h" class SPClipPath; @@ -173,8 +172,6 @@ public: public: SPItemView *display; - std::vector constraints; - sigc::signal _transformed_signal; bool isLocked() const; diff --git a/src/remove-last.h b/src/remove-last.h deleted file mode 100644 index b67721d351..0000000000 --- a/src/remove-last.h +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2013 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef __REMOVE_LAST_H__ -#define __REMOVE_LAST_H__ - -#include -#include -#include - -template -inline void remove_last(std::vector &seq, T const &elem) -{ - typename std::vector::reverse_iterator i(find(seq.rbegin(), seq.rend(), elem)); - g_assert( i != seq.rend() ); - seq.erase(i.base()); -} - - -#endif /* !__REMOVE_LAST_H__ */ - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-guide-attachment.h b/src/sp-guide-attachment.h deleted file mode 100644 index 05d43a270a..0000000000 --- a/src/sp-guide-attachment.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SP_GUIDE_ATTACHMENT_H -#define SEEN_SP_GUIDE_ATTACHMENT_H - -#include "object/sp-item.h" - -class SPGuideAttachment { -public: - SPItem *item; - int snappoint_ix; - -public: - SPGuideAttachment() : - item(static_cast(nullptr)), - snappoint_ix(0) - { } - - SPGuideAttachment(SPItem *i, int s) : - item(i), - snappoint_ix(s) - { } - - bool operator==(SPGuideAttachment const &o) const { - return ( ( item == o.item ) - && ( snappoint_ix == o.snappoint_ix ) ); - } - - bool operator!=(SPGuideAttachment const &o) const { - return !(*this == o); - } -}; - -#endif // SEEN_SP_GUIDE_ATTACHMENT_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-guide-constraint.h b/src/sp-guide-constraint.h deleted file mode 100644 index 578f392fb7..0000000000 --- a/src/sp-guide-constraint.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2018 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#ifndef SEEN_SP_GUIDE_CONSTRAINT_H -#define SEEN_SP_GUIDE_CONSTRAINT_H - -class SPGuide; - -class SPGuideConstraint { -public: - SPGuide *g; - int snappoint_ix; - -public: - explicit SPGuideConstraint() : - g(static_cast(nullptr)), - snappoint_ix(0) - { } - - explicit SPGuideConstraint(SPGuide *g, int snappoint_ix) : - g(g), - snappoint_ix(snappoint_ix) - { } - - bool operator==(SPGuideConstraint const &o) const { - return ( ( g == o.g ) - && ( snappoint_ix == o.snappoint_ix ) ); - } - - bool operator!=(SPGuideConstraint const &o) const { - return !( *this == o ); - } -}; - -#endif // SEEN_SP_GUIDE_CONSTRAINT_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- GitLab From 764955856e5951f01028cb388d76d63b91a41c79 Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Wed, 24 Mar 2021 03:29:32 +0200 Subject: [PATCH 10/11] Renamed Inkscape::Algorithms::longest_common_suffix to nearest_common_ancestor. The name is misleading, it only operates on trees to find the nearest common ancestor. It can't for example find the longest common suffix of two strings. It should be renamed to nearest_common_ancestor. --- src/object/sp-object.cpp | 4 ++-- src/util/longest-common-suffix.h | 16 ++++++++-------- src/xml/repr-sorting.cpp | 4 ++-- testfiles/src/util-test.cpp | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/object/sp-object.cpp b/src/object/sp-object.cpp index e49f0f3672..2019042b50 100644 --- a/src/object/sp-object.cpp +++ b/src/object/sp-object.cpp @@ -332,8 +332,8 @@ bool same_objects(SPObject const &a, SPObject const &b) { SPObject const *SPObject::nearestCommonAncestor(SPObject const *object) const { g_return_val_if_fail(object != nullptr, NULL); - using Inkscape::Algorithms::longest_common_suffix; - return longest_common_suffix(this, object, nullptr, &same_objects); + using Inkscape::Algorithms::nearest_common_ancestor; + return nearest_common_ancestor(this, object, nullptr, &same_objects); } static SPObject const *AncestorSon(SPObject const *obj, SPObject const *ancestor) { diff --git a/src/util/longest-common-suffix.h b/src/util/longest-common-suffix.h index 351595ba2a..9f2cbeeb80 100644 --- a/src/util/longest-common-suffix.h +++ b/src/util/longest-common-suffix.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Inkscape::Algorithms::longest_common_suffix + * Inkscape::Algorithms::nearest_common_ancestor * * Authors: * MenTaLguY @@ -10,8 +10,8 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#ifndef SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H -#define SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H +#ifndef SEEN_INKSCAPE_ALGORITHMS_NEAREST_COMMON_ANCESTOR_H +#define SEEN_INKSCAPE_ALGORITHMS_NEAREST_COMMON_ANCESTOR_H #include #include @@ -25,21 +25,21 @@ namespace Algorithms { * * The case of sharing a common successor is handled in O(1) time. * - * If \a a is the longest common suffix, then runs in O(len(rest of b)) time. + * If \a a is the nearest common ancestor, then runs in O(len(rest of b)) time. * * Otherwise, runs in O(len(a) + len(b)) time. */ template -ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b, +ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, ForwardIterator end) { typedef typename std::iterator_traits::value_type value_type; - return longest_common_suffix(a, b, end, std::equal_to()); + return nearest_common_ancestor(a, b, end, std::equal_to()); } template -ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b, +ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, ForwardIterator end, BinaryPredicate pred) { if ( a == end || b == end ) { @@ -97,7 +97,7 @@ ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b, } -#endif /* !SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H */ +#endif /* !SEEN_INKSCAPE_ALGORITHMS_NEAREST_COMMON_ANCESTOR_H */ /* Local Variables: diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp index ffea0aab03..a5e6081907 100644 --- a/src/xml/repr-sorting.cpp +++ b/src/xml/repr-sorting.cpp @@ -21,8 +21,8 @@ static bool same_repr(Inkscape::XML::Node const &a, Inkscape::XML::Node const &b Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b) { - using Inkscape::Algorithms::longest_common_suffix; - Inkscape::XML::Node const *ancestor = longest_common_suffix( + using Inkscape::Algorithms::nearest_common_ancestor; + Inkscape::XML::Node const *ancestor = nearest_common_ancestor( a, b, nullptr, &same_repr); bool OK = false; if (ancestor) { diff --git a/testfiles/src/util-test.cpp b/testfiles/src/util-test.cpp index 5ee4b3cb6d..c91cddc40e 100644 --- a/testfiles/src/util-test.cpp +++ b/testfiles/src/util-test.cpp @@ -17,10 +17,9 @@ TEST(UtilTest, NearestCommonAncestor) { - // TODO change name of implementation to `nearest_common_ancestor` // TODO remove `pred` argument #define nearest_common_ancestor(a, b, c) \ - Inkscape::Algorithms::longest_common_suffix(a, b, c, [](Node const &lhs, Node const &rhs) { return &lhs == &rhs; }) + Inkscape::Algorithms::nearest_common_ancestor(a, b, c, [](Node const &lhs, Node const &rhs) { return &lhs == &rhs; }) // simple node with a parent struct Node -- GitLab From 9c6f3370b2aafa89340eaa1dfadced4b427248cb Mon Sep 17 00:00:00 2001 From: Osama Ahmad Date: Wed, 24 Mar 2021 08:19:10 +0200 Subject: [PATCH 11/11] Improved Inkscape::Algorithms::nearest_common_ancestor Problems: - The template has a BinaryPredicate pred parameter, which compares dereferenced iterators by value. This is an odd pattern and not needed by the two places which currently make use of this function (they both simply compare addresses, which should be identical to comparing iterators). - The implementation also checks several special cases where it directly compares iterators, and only uses pred in the final non-specialized case. Also, the 3-argument version of the implementation (used std::equal_to) is defined before the 4-argument version which makes it currently unusable. In this commit: - removed the 3-arguments version - removed the predicate from the 4-arguments version - always comparing iterators using == (which is equal to comparing addresses) - changed the two places in the code to be not be passing a predicate as well as the tests --- src/object/sp-object.cpp | 10 +--------- src/util/longest-common-suffix.h | 13 ++----------- src/xml/repr-sorting.cpp | 10 ++-------- testfiles/src/util-test.cpp | 3 +-- 4 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/object/sp-object.cpp b/src/object/sp-object.cpp index 2019042b50..194a0cc13d 100644 --- a/src/object/sp-object.cpp +++ b/src/object/sp-object.cpp @@ -321,19 +321,11 @@ bool SPObject::isAncestorOf(SPObject const *object) const { return false; } -namespace { - -bool same_objects(SPObject const &a, SPObject const &b) { - return &a == &b; -} - -} - SPObject const *SPObject::nearestCommonAncestor(SPObject const *object) const { g_return_val_if_fail(object != nullptr, NULL); using Inkscape::Algorithms::nearest_common_ancestor; - return nearest_common_ancestor(this, object, nullptr, &same_objects); + return nearest_common_ancestor(this, object, nullptr); } static SPObject const *AncestorSon(SPObject const *obj, SPObject const *ancestor) { diff --git a/src/util/longest-common-suffix.h b/src/util/longest-common-suffix.h index 9f2cbeeb80..1f7b228aca 100644 --- a/src/util/longest-common-suffix.h +++ b/src/util/longest-common-suffix.h @@ -31,16 +31,7 @@ namespace Algorithms { */ template -ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, - ForwardIterator end) -{ - typedef typename std::iterator_traits::value_type value_type; - return nearest_common_ancestor(a, b, end, std::equal_to()); -} - -template -ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, - ForwardIterator end, BinaryPredicate pred) +ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, ForwardIterator end) { if ( a == end || b == end ) { return end; @@ -83,7 +74,7 @@ ForwardIterator nearest_common_ancestor(ForwardIterator a, ForwardIterator b, ForwardIterator longest_common(end); while ( !suffixes[0].empty() && !suffixes[1].empty() && - pred(*(suffixes[0].back()), *(suffixes[1].back())) ) + suffixes[0].back() == suffixes[1].back() ) { longest_common = suffixes[0].back(); suffixes[0].pop_back(); diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp index a5e6081907..9fd3b2289e 100644 --- a/src/xml/repr-sorting.cpp +++ b/src/xml/repr-sorting.cpp @@ -13,17 +13,11 @@ #include "xml/node-iterators.h" #include "repr-sorting.h" -static bool same_repr(Inkscape::XML::Node const &a, Inkscape::XML::Node const &b) -{ - /* todo: I'm not certain that it's legal to take the address of a reference. Check the exact wording of the spec on this matter. */ - return &a == &b; -} - Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b) { using Inkscape::Algorithms::nearest_common_ancestor; - Inkscape::XML::Node const *ancestor = nearest_common_ancestor( - a, b, nullptr, &same_repr); + Inkscape::XML::Node const *ancestor = + nearest_common_ancestor(a, b, nullptr); bool OK = false; if (ancestor) { if (ancestor->type() != Inkscape::XML::NodeType::DOCUMENT_NODE) { diff --git a/testfiles/src/util-test.cpp b/testfiles/src/util-test.cpp index c91cddc40e..785e3d3164 100644 --- a/testfiles/src/util-test.cpp +++ b/testfiles/src/util-test.cpp @@ -17,9 +17,8 @@ TEST(UtilTest, NearestCommonAncestor) { - // TODO remove `pred` argument #define nearest_common_ancestor(a, b, c) \ - Inkscape::Algorithms::nearest_common_ancestor(a, b, c, [](Node const &lhs, Node const &rhs) { return &lhs == &rhs; }) + Inkscape::Algorithms::nearest_common_ancestor(a, b, c) // simple node with a parent struct Node -- GitLab