Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
geom-nodetype.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Specific nodetype geometry functions for Inkscape, not provided my lib2geom.
4 *
5 * Author:
6 * Johan Engelen <goejendaagh@zonnet.nl>
7 *
8 * Copyright (C) 2008 Johan Engelen
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
14
15#include <2geom/curve.h>
16
17namespace Geom {
18
19/*
20 * NOTE: THIS METHOD NEVER RETURNS "NODE_SYMM".
21 * Returns the nodetype between c_incoming and c_outgoing. Location of the node is
22 * at c_incoming.pointAt(1) == c_outgoing.pointAt(0). If these two are unequal,
23 * the returned type is NODE_NONE.
24 * Comparison is based on the unitTangent, does not work for NODE_SYMM!
25 */
26NodeType get_nodetype(Curve const &c_incoming, Curve const &c_outgoing)
27{
28 if ( !are_near(c_incoming.pointAt(1), c_outgoing.pointAt(0)) )
29 return NODE_NONE;
30
31 Geom::Curve *crv = c_incoming.reverse();
32 Geom::Point deriv_1 = -crv->unitTangentAt(0);
33 delete crv;
34 Geom::Point deriv_2 = c_outgoing.unitTangentAt(0);
35 double this_angle_L2 = Geom::L2(deriv_1);
36 double next_angle_L2 = Geom::L2(deriv_2);
37 double both_angles_L2 = Geom::L2(deriv_1 + deriv_2);
38 if ( (this_angle_L2 > 1e-6) &&
39 (next_angle_L2 > 1e-6) &&
40 ((this_angle_L2 + next_angle_L2 - both_angles_L2) < 1e-3) )
41 {
42 return NODE_SMOOTH;
43 }
44
45 return NODE_CUSP;
46}
47
48} // end namespace Geom
49
50/*
51 Local Variables:
52 mode:c++
53 c-file-style:"stroustrup"
54 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
55 indent-tabs-mode:nil
56 fill-column:99
57 End:
58*/
59// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Abstract curve type.
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
virtual Curve * reverse() const
Create a reversed version of this curve.
Definition curve.h:234
virtual Point unitTangentAt(Coord t, unsigned n=3) const
Compute a vector tangent to the curve.
Definition curve.cpp:201
virtual Point pointAt(Coord t) const
Evaluate the curve at a specified time value.
Definition curve.h:110
Two-dimensional point that doubles as a vector.
Definition point.h:66
Specific nodetype geometry functions for Inkscape, not provided my lib2geom.
Various utility functions.
Definition affine.h:22
NodeType
What kind of node is this? This is the value for the node->type field.
@ NODE_NONE
Discontinuous node, usually either start or endpoint of a path.
@ NODE_CUSP
This node continuously joins two segments, but the unit tangent is discontinuous.
@ NODE_SMOOTH
This node continuously joins two segments, with continuous unit tangent.
NodeType get_nodetype(Curve const &c_incoming, Curve const &c_outgoing)
SBasis L2(D2< SBasis > const &a, unsigned k)
Definition d2-sbasis.cpp:42
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)