From 000c6ddd6f2cd75b1fe653f09335d5da3307614c Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 8 Aug 2019 17:10:07 +0300 Subject: [PATCH] Convert a macro "sp_round" to a func. I hereby disclaim any implicit or explicit ownership of my changes in this changeset, and put them under a multiple licence consisting of your choice of one of more of: - The CC0 / Public Domain - https://creativecommons.org/choose/zero/ . - The MIT / Expat license - https://en.wikipedia.org/wiki/MIT_License - The default licence of your project - The https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License - version 2.1 or higher - The https://en.wikipedia.org/wiki/GNU_General_Public_License - version 2 or higher - Any licence in the 2018-Aug-27 popular licenses list of https://opensource.org/licenses - The https://en.wikipedia.org/wiki/Apache_License version 2.0 or later - The https://en.wikipedia.org/wiki/Artistic_License version 2.0 or later - The https://en.wikipedia.org/wiki/ISC_license - The https://opensource.org/licenses/BSD-2-Clause Crediting me will be nice, but not mandatory, and you can change the licence of the project without needing my permission. --- share/extensions | 2 +- src/include/macros.h | 4 +--- src/include/sp-round.h | 33 +++++++++++++++++++++++++++++ src/knot-holder-entity.cpp | 2 ++ src/ui/shape-editor-knotholders.cpp | 1 + src/ui/tools/spiral-tool.cpp | 1 + src/ui/tools/star-tool.cpp | 1 + 7 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/include/sp-round.h diff --git a/share/extensions b/share/extensions index 0cd6825e7d..ef8f034234 160000 --- a/share/extensions +++ b/share/extensions @@ -1 +1 @@ -Subproject commit 0cd6825e7dc0fb607b1f50efddc5fcc148c24ec0 +Subproject commit ef8f034234bcd036b91b8eb6b9d754d21656dc4e diff --git a/src/include/macros.h b/src/include/macros.h index 21ddaff9ee..dca5d0a036 100644 --- a/src/include/macros.h +++ b/src/include/macros.h @@ -15,12 +15,10 @@ // I'm of the opinion that this file should be removed, so I will in the future take the necessary steps to wipe it out. // Macros are not in general bad, but these particular ones are rather ugly. Especially that sp_round one. --Liam +// Note: sp_round was converted to an inline function --Shlomif #define sp_signal_disconnect_by_data(o,d) g_signal_handlers_disconnect_matched(o, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, d) -#define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m))) - - // keyboard modifiers in an event #define MOD__SHIFT(event) ((event)->key.state & GDK_SHIFT_MASK) #define MOD__CTRL(event) ((event)->key.state & GDK_CONTROL_MASK) diff --git a/src/include/sp-round.h b/src/include/sp-round.h new file mode 100644 index 0000000000..27bda609fe --- /dev/null +++ b/src/include/sp-round.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_SP_ROUND_H +#define SEEN_SP_ROUND_H + +/** + * sp_round inline function + * + * Author: + * Lauris Kaplinski + * + * Copyright (C) 2002 Lauris Kaplinski + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include + +static inline double sp_round(const double v, const double m) { + return ((v < 0.0) ? ((ceil(v / m - 0.5)) * m) : ((floor(v / m + 0.5)) * m)); +} + +#endif // SEEN_SP_ROUND_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 : diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 75f36089c9..703b874d67 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -30,6 +30,8 @@ #include "object/sp-namedview.h" #include "object/sp-pattern.h" +#include "include/sp-round.h" + int KnotHolderEntity::counter = 0; void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, Inkscape::ControlType type, diff --git a/src/ui/shape-editor-knotholders.cpp b/src/ui/shape-editor-knotholders.cpp index 11f32644db..6b759ce23f 100644 --- a/src/ui/shape-editor-knotholders.cpp +++ b/src/ui/shape-editor-knotholders.cpp @@ -33,6 +33,7 @@ #include "object/sp-star.h" #include "object/sp-text.h" #include "style.h" +#include "include/sp-round.h" #include "include/macros.h" diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index dd4a839e4d..e4d94340b4 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -30,6 +30,7 @@ #include "message-context.h" #include "ui/pixmaps/cursor-spiral.xpm" #include "selection.h" +#include "include/sp-round.h" #include "verbs.h" #include "display/sp-canvas-item.h" diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index a6a143ec0c..390fda23a9 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -29,6 +29,7 @@ #include "include/macros.h" #include "message-context.h" #include "selection.h" +#include "include/sp-round.h" #include "verbs.h" #include "display/sp-canvas.h" -- GitLab