diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
commit | 35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch) | |
tree | 657d15a03cc46bd099fc2c6546a7a4ad43815d9f /src/sp-item-notify-moveto.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip |
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/sp-item-notify-moveto.cpp')
-rw-r--r-- | src/sp-item-notify-moveto.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp new file mode 100644 index 0000000..57e44f4 --- /dev/null +++ b/src/sp-item-notify-moveto.cpp @@ -0,0 +1,89 @@ +// 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 <vector> + +#include "sp-item-notify-moveto.h" + +#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; } + +/** + * 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<Inkscape::SnapCandidatePoint> 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); + } + + sp_item_rm_unsatisfied_cns(item); +#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 : |