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/live_effects/lpe-circle_3pts.cpp | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/live_effects/lpe-circle_3pts.cpp (limited to 'src/live_effects/lpe-circle_3pts.cpp') diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp new file mode 100644 index 0000000..7982abd --- /dev/null +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * LPE "Circle through 3 points" implementation + */ + +/* + * Authors: + * Maximilian Albert + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "live_effects/lpe-circle_3pts.h" + +// You might need to include other 2geom files. You can add them here: +#include <2geom/circle.h> +#include <2geom/path-sink.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + +namespace Inkscape { +namespace LivePathEffect { + +LPECircle3Pts::LPECircle3Pts(LivePathEffectObject *lpeobject) : + Effect(lpeobject) +{ +} + +LPECircle3Pts::~LPECircle3Pts() += default; + +static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::PathVector &path_out) { + using namespace Geom; + + Point D = (A + B)/2; + Point E = (B + C)/2; + + Point v = (B - A).ccw(); + Point w = (C - B).ccw(); + + double det = -v[0] * w[1] + v[1] * w[0]; + + Point M; + if (!v.isZero()) { + Point F = E - D; + double lambda = det == 0 ? 0 : (-w[1] * F[0] + w[0] * F[1]) / det; + M = D + v * lambda; + } else { + M = E; + } + + double radius = L2(M - A); + + Geom::Circle c(M, radius); + path_out = Geom::Path(c); +} + +Geom::PathVector +LPECircle3Pts::doEffect_path (Geom::PathVector const & path_in) +{ + Geom::PathVector path_out = Geom::PathVector(); + + // we assume that the path has >= 3 nodes + Geom::Point A = path_in[0].initialPoint(); + Geom::Point B = path_in[0].pointAt(1); + Geom::Point C = path_in[0].pointAt(2); + + _circle3(A, B, C, path_out); + + return path_out; +} + +/* ######################## */ + +} //namespace LivePathEffect +} /* namespace Inkscape */ + +/* + 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 : -- cgit v1.2.3