From fb749ad5edae38b062e00d1593ec0d306bac4ada Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 5 Feb 2011 03:04:47 +0100 Subject: Fix node tool brokenness resulting from a switch to runtime order in 2Geom's BezierCurve (bzr r10035) --- src/helper/geom-curves.h | 18 ++++++++---------- src/helper/geom.cpp | 22 +++++++++++++--------- src/ui/tool/path-manipulator.cpp | 13 +++++++------ 3 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/helper/geom-curves.h b/src/helper/geom-curves.h index f927634d8..5b921e572 100644 --- a/src/helper/geom-curves.h +++ b/src/helper/geom-curves.h @@ -26,17 +26,15 @@ inline bool is_straight_curve(Geom::Curve const & c) { } // 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; + Geom::BezierCurve const *curve = dynamic_cast(&c); + if (curve) { + Geom::Line line(curve->initialPoint(), curve->finalPoint()); + std::vector pts = curve->points(); + for (unsigned i = 1; i < pts.size() - 1; ++i) { + if (!are_near(pts[i], line)) + return false; } + return true; } return false; diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 4bf56f6c1..2420b43b4 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -476,15 +476,19 @@ pathv_to_linear_and_cubic_beziers( Geom::PathVector const &pathv ) output.back().close( pit->closed() ); for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); ++cit) { - if( dynamic_cast(&*cit) || - is_straight_curve(*cit) ) - { - output.back().append(*cit); - } - else { - // convert all other curve types to cubicbeziers - Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1); - output.back().append(cubicbezier_path); + if (is_straight_curve(*cit)) { + Geom::LineSegment l(cit->initialPoint(), cit->finalPoint()); + output.back().append(l); + } else { + Geom::BezierCurve const *curve = dynamic_cast(&*cit); + if (curve && curve->order() == 3) { + Geom::CubicBezier b((*curve)[0], (*curve)[1], (*curve)[2], (*curve)[3]); + output.back().append(b); + } else { + // convert all other curve types to cubicbeziers + Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1); + output.back().append(cubicbezier_path); + } } } } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 47e28a788..0e5705ee4 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1039,13 +1039,14 @@ void PathManipulator::_createControlPointsFromGeometry() subpath->push_back(current_node); } // if this is a bezier segment, move handles appropriately - if (Geom::CubicBezier const *cubic_bezier = - dynamic_cast(&*cit)) + // TODO: I don't know why the dynamic cast below doesn't want to work + // when I replace BezierCurve with CubicBezier. Might be a bug + // somewhere in pathv_to_linear_and_cubic_beziers + Geom::BezierCurve const *bezier = dynamic_cast(&*cit); + if (bezier && bezier->order() == 3) { - std::vector points = cubic_bezier->points(); - - previous_node->front()->setPosition(points[1]); - current_node ->back() ->setPosition(points[2]); + previous_node->front()->setPosition((*bezier)[1]); + current_node ->back() ->setPosition((*bezier)[2]); } previous_node = current_node; } -- cgit v1.2.3