1 #define INKSCAPE_HELPER_GEOM_NODETYPE_CPP
3 /**
4 * Specific nodetype geometry functions for Inkscape, not provided my lib2geom.
5 *
6 * Author:
7 * Johan Engelen <goejendaagh@zonnet.nl>
8 *
9 * Copyright (C) 2008 Johan Engelen
10 *
11 * Released under GNU GPL
12 */
14 #include "helper/geom-nodetype.h"
16 #include <2geom/curve.h>
17 #include <2geom/point.h>
18 #include <vector>
20 namespace Geom {
22 /*
23 * NOTE: THIS METHOD NEVER RETURNS "NODE_SYMM".
24 * Returns the nodetype between c_incoming and c_outgoing. Location of the node is
25 * at c_incoming.pointAt(1) == c_outgoing.pointAt(0). If these two are unequal,
26 * the returned type is NODE_NONE.
27 * Comparison is based on the unitTangent, does not work for NODE_SYMM!
28 */
29 NodeType get_nodetype(Curve const &c_incoming, Curve const &c_outgoing)
30 {
31 if ( !are_near(c_incoming.pointAt(1), c_outgoing.pointAt(0)) )
32 return NODE_NONE;
34 Geom::Curve *crv = c_incoming.reverse();
35 Geom::Point deriv_1 = -crv->unitTangentAt(0);
36 delete crv;
37 Geom::Point deriv_2 = c_outgoing.unitTangentAt(0);
38 double this_angle_L2 = Geom::L2(deriv_1);
39 double next_angle_L2 = Geom::L2(deriv_2);
40 double both_angles_L2 = Geom::L2(deriv_1 + deriv_2);
41 if ( (this_angle_L2 > 1e-6) &&
42 (next_angle_L2 > 1e-6) &&
43 ((this_angle_L2 + next_angle_L2 - both_angles_L2) < 1e-3) )
44 {
45 return NODE_SMOOTH;
46 }
48 return NODE_CUSP;
49 }
51 } // end namespace Geom
53 /*
54 Local Variables:
55 mode:c++
56 c-file-style:"stroustrup"
57 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
58 indent-tabs-mode:nil
59 fill-column:99
60 End:
61 */
62 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :