diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-07-14 15:02:01 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-07-14 15:02:01 +0000 |
| commit | 79b924fa7c1d0926eea44824bb5f301478480bb3 (patch) | |
| tree | 7905b3373126088df9ec828091669610abfa8cc3 /src | |
| parent | Preview emf on windows (diff) | |
| download | inkscape-79b924fa7c1d0926eea44824bb5f301478480bb3.tar.gz inkscape-79b924fa7c1d0926eea44824bb5f301478480bb3.zip | |
add geom-nodetype. helper function to determine the nodetype between two curves
(bzr r6295)
Diffstat (limited to 'src')
| -rw-r--r-- | src/helper/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/helper/geom-nodetype.cpp | 74 | ||||
| -rw-r--r-- | src/helper/geom-nodetype.h | 54 |
3 files changed, 130 insertions, 0 deletions
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 99957ab3b..20c7e6c53 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -18,6 +18,8 @@ helper_libspchelp_a_SOURCES = \ helper/action.h \ helper/geom.cpp \ helper/geom.h \ + helper/geom-nodetype.cpp \ + helper/geom-nodetype.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ helper/helper-forward.h \ diff --git a/src/helper/geom-nodetype.cpp b/src/helper/geom-nodetype.cpp new file mode 100644 index 000000000..b43c30a8f --- /dev/null +++ b/src/helper/geom-nodetype.cpp @@ -0,0 +1,74 @@ +#define INKSCAPE_HELPER_GEOM_NODETYPE_CPP + +/** + * Specific nodetype geometry functions for Inkscape, not provided my lib2geom. + * + * Author: + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 2008 Johan Engelen + * + * Released under GNU GPL + */ + +#include "helper/geom-nodetype.h" + +#include <2geom/curve.h> +#include <2geom/point.h> +#include <vector> + +namespace Geom { + +/* + * Returns the nodetype between c_incoming and c_outgoing. Location of the node is + * at c_incoming.pointAt(1) == c_outgoing.pointAt(0). If these two are unequal, + * the returned type is NODE_NONE. + * This method uses exact floating point comparison, so the final and initial points of + * the two input curves should match exactly! + */ +NodeType get_nodetype(Curve const &c_incoming, Curve const &c_outgoing) +{ + // FIXME: this should be exact floating point match, not are_near! + if ( !are_near(c_incoming.pointAt(1), c_outgoing.pointAt(0)) ) + return NODE_NONE; + + Curve * c1_reverse = c_incoming.reverse(); + std::vector<Point> deriv1 = c1_reverse->pointAndDerivatives(0, 3); + delete c1_reverse; + std::vector<Point> deriv2 = c_outgoing.pointAndDerivatives(0, 3); + + // Determine lowest derivative that is non-zero + int n1 = 1; + while ( (deriv1[n1] == Point(0,0)) && (n1 < 3) ) { + n1++; + } + int n2 = 1; + while ( (deriv2[n2] == Point(0,0)) && (n2 < 3) ) { + n2++; + } + + double const angle1 = Geom::atan2(-deriv1[n1]); + double const angle2 = Geom::atan2(deriv2[n2]); + + if ( !are_near(angle1, angle2) ) + return NODE_CUSP; // derivatives are not colinear + + // Apparently, the derivatives are colinear but does the order of the derivatives match? + if (n1 != n2) + return NODE_SMOOTH; + else + return NODE_SYMM; +} + +} + +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-nodetype.h b/src/helper/geom-nodetype.h new file mode 100644 index 000000000..932ba6d84 --- /dev/null +++ b/src/helper/geom-nodetype.h @@ -0,0 +1,54 @@ +#ifndef INKSCAPE_HELPER_GEOM_NODETYPE_H +#define INKSCAPE_HELPER_GEOM_NODETYPE_H + +/** + * Specific nodetype geometry functions for Inkscape, not provided my lib2geom. + * + * Author: + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 2008 Johan Engelen + * + * Released under GNU GPL + */ + +#include <2geom/forward.h> + +namespace Geom { + +/** + * What kind of node is this? This is the value for the node->type + * field. NodeType indicates the degree of continuity required for + * the node. I think that the corresponding integer indicates which + * derivate is connected. (Thus 2 means that the node is continuous + * to the second derivative, i.e. has matching endpoints and tangents) + */ +typedef enum { +/** Discontinuous node, usually either start or endpoint of a path */ + NODE_NONE, +/** This node continuously joins two segments, but the unit tangent is discontinuous.*/ + NODE_CUSP, +/** This node continuously joins two segments, with continuous *unit* tangent. */ + NODE_SMOOTH, +/** This node is symmetric. I.e. continously joins two segments with continuous derivative */ + NODE_SYMM +} NodeType; + + +NodeType get_nodetype(Curve const &c_incoming, Curve const &c_outgoing); + + +} // namespace Geom + +#endif // INKSCAPE_HELPER_GEOM_NODETYPE_H + +/* + 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:encoding=utf-8:textwidth=99 : |
