From ae9bb17bcf65f0e053c0b292a0b53f4a1435eb5c Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sun, 29 Jun 2008 12:37:25 +0000 Subject: [PATCH] recognize HLineSegment and VLineSegment while looping through curves --- src/display/inkscape-cairo.cpp | 5 +++-- src/helper/geom.cpp | 29 +++++++++++++++++------------ src/livarot/Path.h | 2 +- src/livarot/PathCutting.cpp | 21 ++++++++++++--------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/display/inkscape-cairo.cpp b/src/display/inkscape-cairo.cpp index 69e766ce8..2ca6cb91d 100644 --- a/src/display/inkscape-cairo.cpp +++ b/src/display/inkscape-cairo.cpp @@ -10,6 +10,7 @@ #include +#include #ifdef HAVE_CONFIG_H # include #endif @@ -159,8 +160,8 @@ feed_curve_to_cairo (cairo_t *ct, NArtBpath const *bpath, NR::Matrix trans, NR:: static void feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix & trans, Geom::Rect view, bool optimize_stroke) { - if( typeid(c) == typeid(Geom::LineSegment) || - typeid(c) == typeid(Geom::HLineSegment) || + if( typeid(c) == typeid(Geom::LineSegment) || + typeid(c) == typeid(Geom::HLineSegment) || typeid(c) == typeid(Geom::VLineSegment) ) { Geom::Point end_tr = c.finalPoint() * trans; diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 283e4a3b2..9ec21a44d 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -12,7 +12,7 @@ */ #include "helper/geom.h" - +#include #include <2geom/pathvector.h> #include <2geom/path.h> #include <2geom/transforms.h> @@ -158,13 +158,15 @@ bounds_exact_transformed(Geom::PathVector const & pv, Geom::Matrix const & t) // don't loop including closing segment, since that segment can never increase the bbox for (Geom::Path::const_iterator cit = it->begin(); cit != it->end_open(); ++cit) { - Geom::Curve const *c = &*cit; + Geom::Curve const &c = *cit; - if(Geom::LineSegment const *line_segment = dynamic_cast(c)) + if( typeid(c) == typeid(Geom::LineSegment) || + typeid(c) == typeid(Geom::HLineSegment) || + typeid(c) == typeid(Geom::VLineSegment) ) { - bbox.expandTo( (*line_segment)[1] * t ); + bbox.expandTo( c.finalPoint() * t ); } - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { Geom::Point c0 = (*cubic_bezier)[0] * t; Geom::Point c1 = (*cubic_bezier)[1] * t; @@ -342,14 +344,17 @@ geom_cubic_bbox_wind_distance (Geom::Coord x000, Geom::Coord y000, } static void -geom_curve_bbox_wind_distance(Geom::Curve const * c, Geom::Matrix const &m, +geom_curve_bbox_wind_distance(Geom::Curve const & c, Geom::Matrix const &m, Geom::Point const &pt, Geom::Rect *bbox, int *wind, Geom::Coord *dist, Geom::Coord tolerance, Geom::Rect const *viewbox, Geom::Point &p0) // pass p0 through as it represents the last endpoint added (the finalPoint of last curve) { - if(Geom::LineSegment const *line_segment = dynamic_cast(c)) { // TODO: make it work for HLineSegment too! (use finalPoint) - Geom::Point pe = (*line_segment)[1] * m; + if( typeid(c) == typeid(Geom::LineSegment) || + typeid(c) == typeid(Geom::HLineSegment) || + typeid(c) == typeid(Geom::VLineSegment) ) + { + Geom::Point pe = c.finalPoint() * m; if (bbox) { bbox->expandTo(pe); } @@ -364,7 +369,7 @@ geom_curve_bbox_wind_distance(Geom::Curve const * c, Geom::Matrix const &m, } p0 = pe; } - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) { + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { Geom::Point p1 = (*cubic_bezier)[1] * m; Geom::Point p2 = (*cubic_bezier)[2] * m; Geom::Point p3 = (*cubic_bezier)[3] * m; @@ -390,11 +395,11 @@ geom_curve_bbox_wind_distance(Geom::Curve const * c, Geom::Matrix const &m, p0 = p3; } else { //this case handles sbasis as well as all other curve types - Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); + Geom::Path sbasis_path = Geom::path_from_sbasis(c.toSBasis(), 0.1); //recurse to convert the new path resulting from the sbasis to svgd for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { - geom_curve_bbox_wind_distance(&(*iter), m, pt, bbox, wind, dist, tolerance, viewbox, p0); + geom_curve_bbox_wind_distance(*iter, m, pt, bbox, wind, dist, tolerance, viewbox, p0); } } } @@ -436,7 +441,7 @@ pathv_matrix_point_bbox_wind_distance (Geom::PathVector const & pathv, Geom::Mat // loop including closing segment if path is closed for (Geom::Path::const_iterator cit = it->begin(); cit != it->end_default(); ++cit) { - geom_curve_bbox_wind_distance(&*cit, m, pt, bbox, wind, dist, tolerance, viewbox, p0); + geom_curve_bbox_wind_distance(*cit, m, pt, bbox, wind, dist, tolerance, viewbox, p0); } } diff --git a/src/livarot/Path.h b/src/livarot/Path.h index adc26c169..9ba365f6e 100644 --- a/src/livarot/Path.h +++ b/src/livarot/Path.h @@ -386,7 +386,7 @@ public: void FlushPendingAddition(Path* dest,PathDescr *lastAddition,PathDescrCubicTo &lastCubic,int lastAD); private: - void AddCurve(Geom::Curve const *c); + void AddCurve(Geom::Curve const &c); }; #endif diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp index 2987536c3..718017851 100644 --- a/src/livarot/PathCutting.cpp +++ b/src/livarot/PathCutting.cpp @@ -16,7 +16,7 @@ #include #include #include - +#include #include "Path.h" #include "style.h" #include "livarot/path-description.h" @@ -409,34 +409,37 @@ void* Path::MakeArtBPath(void) return bpath; } -void Path::AddCurve(Geom::Curve const *c) +void Path::AddCurve(Geom::Curve const &c) { - if(Geom::LineSegment const *line_segment = dynamic_cast(c)) { - LineTo( NR::Point((*line_segment)[1][0], (*line_segment)[1][1]) ); + if( typeid(c) == typeid(Geom::LineSegment) || + typeid(c) == typeid(Geom::HLineSegment) || + typeid(c) == typeid(Geom::VLineSegment) ) + { + LineTo( to_2geom(c.finalPoint()) ); } /* else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(c)) { ... } */ - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) { + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { Geom::Point tmp = (*cubic_bezier)[3]; Geom::Point tms = 3 * ((*cubic_bezier)[1] - (*cubic_bezier)[0]); Geom::Point tme = 3 * ((*cubic_bezier)[3] - (*cubic_bezier)[2]); CubicTo (from_2geom(tmp), from_2geom(tms), from_2geom(tme)); } - else if(Geom::EllipticalArc const *svg_elliptical_arc = dynamic_cast(c)) { + else if(Geom::EllipticalArc const *svg_elliptical_arc = dynamic_cast(&c)) { ArcTo( from_2geom(svg_elliptical_arc->finalPoint()), svg_elliptical_arc->ray(0), svg_elliptical_arc->ray(1), svg_elliptical_arc->rotation_angle(), svg_elliptical_arc->large_arc_flag(), svg_elliptical_arc->sweep_flag() ); } else { //this case handles sbasis as well as all other curve types - Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); + Geom::Path sbasis_path = Geom::path_from_sbasis(c.toSBasis(), 0.1); //recurse to convert the new path resulting from the sbasis to svgd for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { - AddCurve(&*iter); + AddCurve(*iter); } } } @@ -459,7 +462,7 @@ void Path::LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTran MoveTo( from_2geom(pathtr.initialPoint()) ); for(Geom::Path::const_iterator cit = pathtr.begin(); cit != pathtr.end_open(); ++cit) { - AddCurve(&*cit); + AddCurve(*cit); } if (pathtr.closed()) { -- 2.30.2