From: johanengelen Date: Fri, 11 Jul 2008 16:25:14 +0000 (+0000) Subject: partial update of 2geom X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=adcdea28c696d67996a7dda19cf9863aee48e022;p=inkscape.git partial update of 2geom --- diff --git a/src/2geom/sbasis-to-bezier.cpp b/src/2geom/sbasis-to-bezier.cpp index cca30291d..a046d7dbe 100644 --- a/src/2geom/sbasis-to-bezier.cpp +++ b/src/2geom/sbasis-to-bezier.cpp @@ -179,35 +179,44 @@ subpath_from_sbasis_incremental(Geom::OldPathSetBuilder &pb, D2 B, doubl #endif -void build_from_sbasis(Geom::PathBuilder &pb, D2 const &B, double tol) { +/* + * If only_cubicbeziers is true, the resulting path may only contain CubicBezier curves. + */ +void build_from_sbasis(Geom::PathBuilder &pb, D2 const &B, double tol, bool only_cubicbeziers) { if (!B.isFinite()) { THROW_EXCEPTION("assertion failed: B.isFinite()"); } if(tail_error(B, 2) < tol || sbasis_size(B) == 2) { // nearly cubic enough - if(sbasis_size(B) <= 1) { + if( !only_cubicbeziers && (sbasis_size(B) <= 1) ) { pb.lineTo(B.at1()); } else { std::vector bez = sbasis_to_bezier(B, 2); pb.curveTo(bez[1], bez[2], bez[3]); } } else { - build_from_sbasis(pb, compose(B, Linear(0, 0.5)), tol); - build_from_sbasis(pb, compose(B, Linear(0.5, 1)), tol); + build_from_sbasis(pb, compose(B, Linear(0, 0.5)), tol, only_cubicbeziers); + build_from_sbasis(pb, compose(B, Linear(0.5, 1)), tol, only_cubicbeziers); } } +/* + * If only_cubicbeziers is true, the resulting path may only contain CubicBezier curves. + */ Path -path_from_sbasis(D2 const &B, double tol) { +path_from_sbasis(D2 const &B, double tol, bool only_cubicbeziers) { PathBuilder pb; pb.moveTo(B.at0()); - build_from_sbasis(pb, B, tol); + build_from_sbasis(pb, B, tol, only_cubicbeziers); pb.finish(); return pb.peek().front(); } +/* + * If only_cubicbeziers is true, the resulting path may only contain CubicBezier curves. + */ //TODO: some of this logic should be lifted into svg-path std::vector -path_from_piecewise(Geom::Piecewise > const &B, double tol) { +path_from_piecewise(Geom::Piecewise > const &B, double tol, bool only_cubicbeziers) { Geom::PathBuilder pb; if(B.size() == 0) return pb.peek(); Geom::Point start = B[0].at0(); @@ -219,7 +228,7 @@ path_from_piecewise(Geom::Piecewise > const &B, double to //last line seg already there goto no_add; } - build_from_sbasis(pb, B[i], tol); + build_from_sbasis(pb, B[i], tol, only_cubicbeziers); if(are_near(start, B[i].at1())) { //it's closed pb.closePath(); @@ -229,7 +238,7 @@ path_from_piecewise(Geom::Piecewise > const &B, double to start = B[i+1].at0(); pb.moveTo(start); } else { - build_from_sbasis(pb, B[i], tol); + build_from_sbasis(pb, B[i], tol, only_cubicbeziers); } } pb.finish(); diff --git a/src/2geom/sbasis-to-bezier.h b/src/2geom/sbasis-to-bezier.h index 046e82996..2fedb83c7 100644 --- a/src/2geom/sbasis-to-bezier.h +++ b/src/2geom/sbasis-to-bezier.h @@ -16,9 +16,11 @@ SBasis bezier_to_sbasis(Bezier const &B); std::vector sbasis_to_bezier(D2 const &B, unsigned q = 0); -std::vector path_from_piecewise(Piecewise > const &B, double tol); +std::vector path_from_piecewise(Piecewise > const &B, double tol, bool only_cubicbeziers = false); -Path path_from_sbasis(D2 const &B, double tol); +Path path_from_sbasis(D2 const &B, double tol, bool only_cubicbeziers = false); +inline Path cubicbezierpath_from_sbasis(D2 const &B, double tol) + { return path_from_sbasis(B, tol, true); } ; }; #endif