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 /// \todo un-inline this function
20 inline bool is_straight_curve(Geom::Curve const & c) {
21 if( dynamic_cast<Geom::LineSegment const*>(&c) ||
22 dynamic_cast<Geom::HLineSegment const*>(&c) ||
23 dynamic_cast<Geom::VLineSegment const*>(&c) )
24 {
25 return true;
26 }
27 // the curve can be a quad/cubic bezier, but could still be a perfect straight line
28 // if the control points are exactly on the line connecting the initial and final points.
29 else if ( Geom::QuadraticBezier const *quad = dynamic_cast<Geom::QuadraticBezier const*>(&c) ) {
30 Geom::Line line( quad->initialPoint(), quad->finalPoint() );
31 if ( are_near((*quad)[1], line) ) {
32 return true;
33 }
34 }
35 else if ( Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&c) ) {
36 Geom::Line line( cubic->initialPoint(), cubic->finalPoint() );
37 if ( are_near((*cubic)[1], line) && are_near((*cubic)[2], line) ) {
38 return true;
39 }
40 }
42 return false;
43 }
45 #endif // INKSCAPE_HELPER_GEOM_CURVES_H
47 /*
48 Local Variables:
49 mode:c++
50 c-file-style:"stroustrup"
51 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
52 indent-tabs-mode:nil
53 fill-column:99
54 End:
55 */
56 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :