1 #ifndef INKSCAPE_HELPER_GEOM_CURVES_H
2 #define INKSCAPE_HELPER_GEOM_CURVES_H
4 /**
5 * Specific curve type functions for Inkscape, not provided by lib2geom.
6 *
7 * Author:
8 * Johan Engelen <goejendaagh@zonnet.nl>
9 *
10 * Copyright (C) 2008-2009 Johan Engelen
11 *
12 * Released under GNU GPL
13 */
15 #include <2geom/hvlinesegment.h>
16 #include <2geom/line.h>
17 #include <2geom/bezier-curve.h>
19 inline bool is_straight_curve(Geom::Curve const & c) {
20 if( dynamic_cast<Geom::LineSegment const*>(&c) ||
21 dynamic_cast<Geom::HLineSegment const*>(&c) ||
22 dynamic_cast<Geom::VLineSegment const*>(&c) )
23 {
24 return true;
25 }
26 // the curve can be a quad/cubic bezier, but could still be a perfect straight line
27 // if the control points are exactly on the line connecting the initial and final points.
28 else if ( Geom::QuadraticBezier const *quad = dynamic_cast<Geom::QuadraticBezier const*>(&c) ) {
29 Geom::Line line( quad->initialPoint(), quad->finalPoint() );
30 if ( are_near((*quad)[1], line) ) {
31 return true;
32 }
33 }
34 else if ( Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&c) ) {
35 Geom::Line line( cubic->initialPoint(), cubic->finalPoint() );
36 if ( are_near((*cubic)[1], line) && are_near((*cubic)[2], line) ) {
37 return true;
38 }
39 }
41 return false;
42 }
44 #endif // INKSCAPE_HELPER_GEOM_CURVES_H
46 /*
47 Local Variables:
48 mode:c++
49 c-file-style:"stroustrup"
50 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
51 indent-tabs-mode:nil
52 fill-column:99
53 End:
54 */
55 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :