From d3b89857bf4d795b5238f0a1c5a2d68de8eaaf14 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Tue, 7 Apr 2009 22:58:28 +0000 Subject: [PATCH] is_straight_curve now also returns true for straight line quadratic and cubic curves. this fixes spiro LPE behavior --- src/helper/geom-curves.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/helper/geom-curves.h b/src/helper/geom-curves.h index f3dc364f2..bc5a8213a 100644 --- a/src/helper/geom-curves.h +++ b/src/helper/geom-curves.h @@ -7,12 +7,14 @@ * Author: * Johan Engelen * - * Copyright (C) 2008 Johan Engelen + * Copyright (C) 2008-2009 Johan Engelen * * Released under GNU GPL */ #include <2geom/hvlinesegment.h> +#include <2geom/line.h> +#include <2geom/bezier-curve.h> inline bool is_straight_curve(Geom::Curve const & c) { if( dynamic_cast(&c) || @@ -20,9 +22,23 @@ inline bool is_straight_curve(Geom::Curve const & c) { dynamic_cast(&c) ) { return true; - } else { - return false; } + // the curve can be a quad/cubic bezier, but could still be a perfect straight line + // if the control points are exactly on the line connecting the initial and final points. + else if ( Geom::QuadraticBezier const *quad = dynamic_cast(&c) ) { + Geom::Line line( quad->initialPoint(), quad->finalPoint() ); + if ( are_near((*quad)[1], line) ) { + return true; + } + } + else if ( Geom::CubicBezier const *cubic = dynamic_cast(&c) ) { + Geom::Line line( cubic->initialPoint(), cubic->finalPoint() ); + if ( are_near((*cubic)[1], line) && are_near((*cubic)[2], line) ) { + return true; + } + } + + return false; } #endif // INKSCAPE_HELPER_GEOM_CURVES_H -- 2.30.2