Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
lpe-circle_3pts.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/*
7 * Authors:
8 * Maximilian Albert
9 *
10 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
11 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
17
18// You might need to include other 2geom files. You can add them here:
19#include <2geom/circle.h>
20#include <2geom/path-sink.h>
21// TODO due to internal breakage in glibmm headers, this must be last:
22#include <glibmm/i18n.h>
23
24namespace Inkscape {
25namespace LivePathEffect {
26
28 Effect(lpeobject)
29{
30}
31
33
34static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::PathVector &path_out) {
35 using namespace Geom;
36
37 Point D = (A + B)/2;
38 Point E = (B + C)/2;
39
40 Point v = (B - A).ccw();
41 Point w = (C - B).ccw();
42
43 double det = -v[0] * w[1] + v[1] * w[0];
44
45 Point M;
46 if (!v.isZero()) {
47 Point F = E - D;
48 double lambda = det == 0 ? 0 : (-w[1] * F[0] + w[0] * F[1]) / det;
49 M = D + v * lambda;
50 } else {
51 M = E;
52 }
53
54 double radius = L2(M - A);
55
56 Geom::Circle c(M, radius);
57 path_out = Geom::Path(c);
58}
59
62{
64
65 // we assume that the path has >= 3 nodes
66 Geom::Point A = path_in[0].initialPoint();
67 Geom::Point B = path_in[0].pointAt(1);
68 Geom::Point C = path_in[0].pointAt(2);
69
70 _circle3(A, B, C, path_out);
71
72 return path_out;
73}
74
75/* ######################## */
76
77} //namespace LivePathEffect
78} /* namespace Inkscape */
79
80/*
81 Local Variables:
82 mode:c++
83 c-file-style:"stroustrup"
84 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
85 indent-tabs-mode:nil
86 fill-column:99
87 End:
88*/
89// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Circle shape.
Set of all points at a fixed distance from the center.
Definition circle.h:55
Sequence of subpaths.
Definition pathvector.h:122
Point pointAt(Coord t) const
Point initialPoint() const
Get the first point in the first path of the vector.
Definition pathvector.h:217
Sequence of contiguous curves, aka spline.
Definition path.h:353
Two-dimensional point that doubles as a vector.
Definition point.h:66
Geom::PathVector doEffect_path(Geom::PathVector const &path_in) override
LPECircle3Pts(LivePathEffectObject *lpeobject)
const double w
Definition conic-4.cpp:19
double c[8][4]
LPE "Circle through 3 points" implementation.
Various utility functions.
Definition affine.h:22
SBasis L2(D2< SBasis > const &a, unsigned k)
Definition d2-sbasis.cpp:42
static double det(Point a, Point b)
Definition conicsec.cpp:56
static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, Geom::PathVector &path_out)
Helper class to stream background task notifications as a series of messages.
callback interface for SVG path data