From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/xml/repr-sorting.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/xml/repr-sorting.cpp (limited to 'src/xml/repr-sorting.cpp') diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp new file mode 100644 index 0000000..9fd3b22 --- /dev/null +++ b/src/xml/repr-sorting.cpp @@ -0,0 +1,68 @@ +// 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 "util/longest-common-suffix.h" +#include "xml/repr.h" +#include "xml/node-iterators.h" +#include "repr-sorting.h" + +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); + bool OK = false; + if (ancestor) { + if (ancestor->type() != Inkscape::XML::NodeType::DOCUMENT_NODE) { + OK = true; + } + } + if ( OK ) { + return ancestor; + } else { + return nullptr; + } +} + +Inkscape::XML::Node *LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b) +{ + Inkscape::XML::Node const *tmp = LCA(const_cast(a), const_cast(b)); + return const_cast(tmp); +} + +Inkscape::XML::Node const *AncetreFils(Inkscape::XML::Node const *descendent, Inkscape::XML::Node const *ancestor) +{ + Inkscape::XML::Node const *result = nullptr; + if ( descendent && ancestor ) { + if (descendent->parent() == ancestor) { + result = descendent; + } else { + result = AncetreFils(descendent->parent(), ancestor); + } + } + return result; +} + +Inkscape::XML::Node *AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor) +{ + Inkscape::XML::Node const * tmp = AncetreFils(const_cast(descendent), const_cast(ancestor)); + return const_cast(tmp); +} + +/* + 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 : -- cgit v1.2.3