From 6177de61cec9a47677b076ffee4dd56d445f6c13 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 18 Mar 2015 21:41:26 -0400 Subject: Let's hope the world doesn't end Native 2geom path outliner, still buggy (bzr r14014) --- src/helper/geom-pathstroke.cpp | 505 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 505 insertions(+) create mode 100644 src/helper/geom-pathstroke.cpp (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp new file mode 100644 index 000000000..f41732a51 --- /dev/null +++ b/src/helper/geom-pathstroke.cpp @@ -0,0 +1,505 @@ +/* Author: + * Liam P. White + * + * Copyright (C) 2014-2015 Author + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <2geom/path-sink.h> +#include <2geom/point.h> +#include <2geom/bezier-curve.h> +#include <2geom/svg-elliptical-arc.h> +#include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis + +#include "helper/geom-pathstroke.h" + +namespace Geom { +// 2geom/circle-circle.cpp, no header +int circle_circle_intersection(Point X0, double r0, Point X1, double r1, Point &p0, Point &p1); + +static Point intersection_point(Point origin_a, Point vector_a, Point origin_b, Point vector_b) +{ + Coord denom = cross(vector_b, vector_a); + if (!are_near(denom,0.)) { + Coord t = (cross(origin_a,vector_b) + cross(vector_b,origin_b)) / denom; + return origin_a + vector_a*t; + } + return Point(infinity(), infinity()); +} + +/** +* Find circle that touches inside of the curve, with radius matching the curvature, at time value \c t. +* Because this method internally uses unitTangentAt, t should be smaller than 1.0 (see unitTangentAt). +*/ +static Circle touching_circle( D2 const &curve, double t, double tol=0.01 ) +{ + D2 dM=derivative(curve); + if ( are_near(L2sq(dM(t)),0.) ) { + dM=derivative(dM); + } + if ( are_near(L2sq(dM(t)),0.) ) { // try second time + dM=derivative(dM); + } + Piecewise > unitv = unitVector(dM,tol); + Piecewise dMlength = dot(Piecewise >(dM),unitv); + Piecewise k = cross(derivative(unitv),unitv); + k = divide(k,dMlength,tol,3); + double curv = k(t); // note that this value is signed + + Geom::Point normal = unitTangentAt(curve, t).cw(); + double radius = 1/curv; + Geom::Point center = curve(t) + radius*normal; + return Geom::Circle(center, fabs(radius)); +} + +} + +namespace { + +typedef void join_func(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width); + +void bevel_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double /*width*/) +{ + res.appendNew(outgoing.initialPoint()); +} + +void round_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double width) +{ + res.appendNew(width, width, 0, false, width > 0, outgoing.initialPoint()); +} + +void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) +{ + Geom::Curve const& incoming = res.back(); + Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); + Geom::Point tang2 = outgoing.unitTangentAt(0); + Geom::Point p = Geom::intersection_point(incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2); + if (p.isFinite()) { + // check size of miter + Geom::Point point_on_path = incoming.finalPoint() - Geom::rot90(tang1)*width; + double len = Geom::distance(p, point_on_path); + if (len <= miter) { + // miter OK, check to see if we can do a relocation + // TODO FIXME + /*if (auto line = cast(const(LineSegment))res.back_open) { + Curve copy = line.duplicate; + copy.setFinal(p); + res.erase_last(); + res.append(copy); + } else {*/ + res.appendNew(p); + //} + } + } + res.appendNew(outgoing.initialPoint()); +} + +// might need a little reworking +void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width) +{ + using namespace Geom; + Geom::Curve const& incoming = path_builder.back(); + Geom::Point endPt = outgoing.initialPoint(); + + // The method used when extrapolating curves fails to work when either side of the join to be extrapolated + // is a line segment. When this situation is encountered, fall back to a regular miter join. + bool lineProblem = (dynamic_cast(&incoming)) || (dynamic_cast(&outgoing)); + if (lineProblem == false) { + // Geom::Point tang1 = Geom::unitTangentAt(Geom::reverse(incoming.toSBasis()), 0.); + Geom::Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0); + + Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.); + Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0); + + Geom::Point points[2]; + int solutions = Geom::circle_circle_intersection(circle1.center(), circle1.ray(), + circle2.center(), circle2.ray(), + points[0], points[1]); + if (solutions == 2) { + Geom::Point sol(0,0); + if ( dot(tang2,points[0]-endPt) > 0 ) { + // points[0] is bad, choose points[1] + sol = points[1]; + } else if ( dot(tang2,points[1]-endPt) > 0 ) { // points[0] could be good, now check points[1] + // points[1] is bad, choose points[0] + sol = points[0]; + } else { + // both points are good, choose nearest + sol = ( distanceSq(endPt, points[0]) < distanceSq(endPt, points[1]) ) ? points[0] : points[1]; + } + + Geom::EllipticalArc *arc0 = circle1.arc(incoming.finalPoint(), 0.5*(incoming.finalPoint()+sol), sol, true); + Geom::EllipticalArc *arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); + try { + if (arc0) { + path_builder.append(*arc0); + delete arc0; + arc0 = NULL; + } else { + throw std::exception(); + } + + if (arc1) { + path_builder.append(*arc1); + delete arc1; + arc1 = NULL; + } else { + throw std::exception(); + } + + } catch (std::exception const & ex) { + printf("WARNING: Error extrapolating line join: %s\n", ex.what()); + path_builder.appendNew(endPt); + } + } else { + // 1 or no solutions found, default to miter + miter_join(path_builder, outgoing, miter_limit, line_width); + } + } else { + // Line segments exist + miter_join(path_builder, outgoing, miter_limit, line_width); + } +} + +void join_inside(Geom::Path& res, Geom::Curve const& outgoing) +{ + res.appendNew(outgoing.initialPoint()); +} + +void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, double miter, Inkscape::LineJoinType join) +{ + Geom::Point tang1 = -Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); + //Geom::Point tang2 = to_add[0].unitTangentAt(0); + Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); + bool on_outside = (Geom::dot(tang1, discontinuity_vec) >= 0); + + if (on_outside) { + join_func *jf; + switch (join) { + case Inkscape::JOIN_BEVEL: + jf = &bevel_join; + break; + case Inkscape::JOIN_ROUND: + jf = &round_join; + break; + case Inkscape::JOIN_EXTRAPOLATE: + jf = &extrapolate_join; + break; + default: + jf = &miter_join; + } + jf(res, to_add[0], miter, width); + } else { + join_inside(res, to_add[0]); + } + + res.append(to_add); +} + +// Offsetting a line segment is mathematically stable and quick to do +Geom::LineSegment offset_line(Geom::LineSegment const& l, double width) +{ + Geom::Point tang1 = Geom::rot90(l.unitTangentAt(0)); + Geom::Point tang2 = Geom::rot90(unitTangentAt(reverse(l.toSBasis()), 0.)); + + Geom::Point start = l.initialPoint() + tang1 * width; + Geom::Point end = l.finalPoint() - tang2 * width; + + return Geom::LineSegment(start, end); +} + +void get_cubic_data(Geom::CubicBezier const& bez, double time, double& len, double& rad) +{ + // get derivatives + std::vector derivs = bez.pointAndDerivatives(time, 3); + + Geom::Point der1 = derivs[1]; // first deriv (tangent vector) + Geom::Point der2 = derivs[2]; // second deriv (tangent's tangent) + double l = Geom::L2(der1); // length + + len = rad = 0; + + // TODO: we might want to consider using Geom::touching_circle to determine the + // curvature radius here. Less code duplication, but slower + + if (Geom::are_near(l, 0, 1e-4)) { + l = Geom::L2(der2); + Geom::Point der3 = derivs.at(3); // try second time + if (Geom::are_near(l, 0, 1e-4)) { + l = Geom::L2(der3); + if (Geom::are_near(l, 0)) { + return; // this isn't a segment... + } + rad = 1e8; + } else { + rad = -l * (Geom::dot(der2, der2) / Geom::cross(der3, der2)); + } + } else { + rad = -l * (Geom::dot(der1, der1) / Geom::cross(der2, der1)); + } + len = l; +} + +void offset_cubic(Geom::Path& p, Geom::CubicBezier const& bez, double width, double tol, size_t levels) +{ + using Geom::X; + using Geom::Y; + + Geom::Point start_pos = bez.initialPoint(); + Geom::Point end_pos = bez.finalPoint(); + + Geom::Point start_normal = Geom::rot90(bez.unitTangentAt(0)); + Geom::Point end_normal = -Geom::rot90(Geom::unitTangentAt(Geom::reverse(bez.toSBasis()), 0.)); + + // offset the start and end control points out by the width + Geom::Point start_new = start_pos + start_normal*width; + Geom::Point end_new = end_pos + end_normal*width; + + // -------- + double start_rad, end_rad; + double start_len, end_len; // tangent lengths + get_cubic_data(bez, 0, start_len, start_rad); + get_cubic_data(bez, 1, end_len, end_rad); + + double start_off = 1, end_off = 1; + // correction of the lengths of the tangent to the offset + if (!Geom::are_near(start_rad, 0)) + start_off += width / start_rad; + if (!Geom::are_near(end_rad, 0)) + end_off += width / end_rad; + start_off *= start_len; + end_off *= end_len; + // -------- + + Geom::Point mid1_new = start_normal.ccw()*start_off; + mid1_new = Geom::Point(start_new[X] + mid1_new[X]/3., start_new[Y] + mid1_new[Y]/3.); + Geom::Point mid2_new = end_normal.ccw()*end_off; + mid2_new = Geom::Point(end_new[X] - mid2_new[X]/3., end_new[Y] - mid2_new[Y]/3.); + + // create the estimate curve + Geom::CubicBezier c = Geom::CubicBezier(start_new, mid1_new, mid2_new, end_new); + + // reached maximum recursive depth + // don't bother with any more correction + if (levels == 0) { + p.append(c, Geom::Path::STITCH_DISCONTINUOUS); + return; + } + + // check the tolerance for our estimate to be a parallel curve + Geom::Point chk = c.pointAt(.5); + Geom::Point req = bez.pointAt(.5) + Geom::rot90(bez.unitTangentAt(.5))*width; // required accuracy + + Geom::Point const diff = req - chk; + double const err = Geom::dot(diff, diff); + + if (err < tol) { + if (Geom::are_near(start_new, p.finalPoint())) { + p.setFinal(start_new); // if it isn't near, we throw + } + + // we're good, curve is accurate enough + p.append(c); + return; + } else { + // split the curve in two + std::pair s = bez.subdivide(.5); + offset_cubic(p, s.first, width, tol, levels - 1); + offset_cubic(p, s.second, width, tol, levels - 1); + } +} + +void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double width, double tol, size_t levels) +{ + // cheat + // it's faster + // seriously + std::vector points = bez.points(); + Geom::Point b1 = points[0] + (2./3) * (points[1] - points[0]); + Geom::Point b2 = b1 + (1./3) * (points[2] - points[0]); + Geom::CubicBezier cub = Geom::CubicBezier(points[0], b1, b2, points[3]); + offset_cubic(p, cub, width, tol, levels); +} + +void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) +{ + double const tolerance = 0.0025; + size_t levels = 8; + + // TODO: we can handle SVGEllipticalArc here as well, do that! + + if (Geom::BezierCurve const *b = dynamic_cast(current)) { + size_t order = b->order(); + switch (order) { + case 1: + res.append(offset_line(static_cast(*current), width)); + break; + case 2: { + Geom::QuadraticBezier const& q = static_cast(*current); + offset_quadratic(res, q, width, tolerance, levels); + break; + } + case 3: { + Geom::CubicBezier const& cb = static_cast(*current); + offset_cubic(res, cb, width, tolerance, levels); + break; + } + default: { + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), 0.1); + for (size_t i = 0; i < sbasis_path.size(); ++i) + offset_curve(res, &sbasis_path[i], width); + break; + } + } + } else { + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), 0.1); + for (size_t i = 0; i < sbasis_path.size(); ++i) + offset_curve(res, &sbasis_path[i], width); + } +} + +} + +namespace Inkscape { + +Geom::PathVector outline(Geom::Path const& input, double width, double miter, LineJoinType join, LineCapType butt) +{ + if (input.size() == 0) return Geom::PathVector(); // nope, don't even try + + Geom::PathBuilder res; + Geom::Path with_dir = half_outline(input, width/2., miter, join); + Geom::Path against_dir = half_outline(input.reverse(), width/2., miter, join); + + res.moveTo(with_dir[0].initialPoint()); + res.append(with_dir); + + // glue caps + if (!input.closed()) { + switch (butt) { + case BUTT_ROUND: + res.arcTo((-width) / 2., (-width) / 2., 0., true, true, against_dir.initialPoint()); + break; + case BUTT_SQUARE: { + Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(input[input.size()-1].toSBasis()), 0.); + double radius = 0.5 * Geom::distance(with_dir.finalPoint(), against_dir.initialPoint()); + res.lineTo(with_dir.finalPoint() + end_deriv*radius); + res.lineTo(against_dir.initialPoint() + end_deriv*radius); + res.lineTo(against_dir.initialPoint()); + break; + } + case BUTT_PEAK: { + Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(input[input.size()-1].toSBasis()), 0.); + double radius = 0.5 * Geom::distance(with_dir.finalPoint(), against_dir.initialPoint()); + Geom::Point midpoint = ((with_dir.finalPoint() + against_dir.initialPoint()) * 0.5) + end_deriv*radius; + res.lineTo(midpoint); + res.lineTo(against_dir.initialPoint()); + break; + } + case BUTT_FLAT: + default: + res.lineTo(against_dir.initialPoint()); + break; + } + } else { + res.moveTo(against_dir.initialPoint()); + } + + res.append(against_dir); + + if (!input.closed()) { + switch(butt) { + case BUTT_ROUND: + res.arcTo((-width) / 2., (-width) / 2., 0., true, true, with_dir.initialPoint()); + break; + case BUTT_SQUARE: { + Geom::Point end_deriv = -input[0].unitTangentAt(0.); + double radius = 0.5 * Geom::distance(against_dir.finalPoint(), with_dir.initialPoint()); + res.lineTo(against_dir.finalPoint() + end_deriv*radius); + res.lineTo(with_dir.initialPoint() + end_deriv*radius); + res.lineTo(with_dir.initialPoint()); + break; + } + case BUTT_PEAK: { + Geom::Point end_deriv = -input[0].unitTangentAt(0.); + double radius = 0.5 * Geom::distance(against_dir.finalPoint(), with_dir.initialPoint()); + Geom::Point midpoint = ((against_dir.finalPoint() + with_dir.initialPoint()) * 0.5) + end_deriv*radius; + res.lineTo(midpoint); + res.lineTo(with_dir.initialPoint()); + break; + } + case BUTT_FLAT: + default: + res.lineTo(with_dir.initialPoint()); + } + res.closePath(); + } + + res.flush(); + return res.peek(); +} + +Geom::Path half_outline(Geom::Path const& input, double width, double miter, LineJoinType join) +{ + Geom::Path res; + if (input.size() == 0) return res; + + Geom::Point tang1 = input[0].unitTangentAt(0); + Geom::Point start = input.initialPoint() + tang1 * width; + Geom::Path temp; + + res.start(start); + + // Do two curves at a time for efficiency, since the join function needs to know the outgoing curve as well + const size_t k = input.size(); + for (size_t u = 0; u < k; u += 2) { + temp = Geom::Path(); + + offset_curve(temp, &input[u], width); + + // on the first run through, there isn't a join + if (u == 0) { + res.append(temp); + } else { + outline_helper(res, temp, width, miter, join); + } + + // odd number of paths + if (u < k - 1) { + temp = Geom::Path(); + offset_curve(temp, &input[u+1], width); + outline_helper(res, temp, width, miter, join); + } + } + + if (input.closed()) { + Geom::Curve const &c1 = res[res.size()-1]; + Geom::Curve const &c2 = res[0]; + temp = Geom::Path(); + temp.append(c1); + Geom::Path temp2; + temp2.append(c2); + outline_helper(temp, temp2, width, miter, join); + temp.erase_last(); // we already outlined c2 + temp.erase(temp.begin()); // we already outlined c1 + + // + res.append(temp); + } + + res.close(); + return res; +} + +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8 : -- cgit v1.2.3 From 2c6f909f381a31d7de1245debcdde92f36e94d30 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Thu, 19 Mar 2015 20:58:14 -0400 Subject: Fix remaining bugs in path outliner (bzr r14017) --- src/helper/geom-pathstroke.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index f41732a51..1b8f90104 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -66,7 +66,7 @@ void bevel_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, void round_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double width) { - res.appendNew(width, width, 0, false, width > 0, outgoing.initialPoint()); + res.appendNew(width, width, 0, false, width <= 0, outgoing.initialPoint()); } void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) @@ -318,7 +318,7 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi std::vector points = bez.points(); Geom::Point b1 = points[0] + (2./3) * (points[1] - points[0]); Geom::Point b2 = b1 + (1./3) * (points[2] - points[0]); - Geom::CubicBezier cub = Geom::CubicBezier(points[0], b1, b2, points[3]); + Geom::CubicBezier cub = Geom::CubicBezier(points[0], b1, b2, points[2]); offset_cubic(p, cub, width, tol, levels); } @@ -378,7 +378,7 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li if (!input.closed()) { switch (butt) { case BUTT_ROUND: - res.arcTo((-width) / 2., (-width) / 2., 0., true, true, against_dir.initialPoint()); + res.arcTo(width / 2., width / 2., 0., true, false, against_dir.initialPoint()); break; case BUTT_SQUARE: { Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(input[input.size()-1].toSBasis()), 0.); @@ -410,7 +410,7 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li if (!input.closed()) { switch(butt) { case BUTT_ROUND: - res.arcTo((-width) / 2., (-width) / 2., 0., true, true, with_dir.initialPoint()); + res.arcTo(width / 2., width / 2., 0., true, false, with_dir.initialPoint()); break; case BUTT_SQUARE: { Geom::Point end_deriv = -input[0].unitTangentAt(0.); @@ -451,7 +451,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin res.start(start); // Do two curves at a time for efficiency, since the join function needs to know the outgoing curve as well - const size_t k = input.size(); + const size_t k = input.size_default(); for (size_t u = 0; u < k; u += 2) { temp = Geom::Path(); @@ -473,8 +473,13 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin } if (input.closed()) { - Geom::Curve const &c1 = res[res.size()-1]; - Geom::Curve const &c2 = res[0]; + if (input.back_closed().isDegenerate()) { + res.erase_last(); + res.erase_last(); // ? + } + + Geom::Curve const &c1 = res.back(); + Geom::Curve const &c2 = res.front(); temp = Geom::Path(); temp.append(c1); Geom::Path temp2; @@ -485,9 +490,9 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin // res.append(temp); + res.close(); } - res.close(); return res; } -- cgit v1.2.3 From f2f410ca16f49a676413deac914c4a2bed14d041 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sun, 22 Mar 2015 01:01:50 -0400 Subject: improve, optimize, fix path outliner (bzr r14027) --- src/helper/geom-pathstroke.cpp | 183 +++++++++++++++++++++++++---------------- 1 file changed, 112 insertions(+), 71 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 1b8f90104..6fcfb79d5 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -11,6 +11,7 @@ #include <2geom/bezier-curve.h> #include <2geom/svg-elliptical-arc.h> #include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis +#include <2geom/path-intersection.h> #include "helper/geom-pathstroke.h" @@ -57,16 +58,28 @@ static Circle touching_circle( D2 const &curve, double t, double tol=0.0 namespace { +// Join functions may: +// - inspect any curve of the current path +// - append any type of curve to the current path +// - inspect the outgoing path +// +// Join functions must: +// - append the outgoing curve +// OR +// - end at outgoing.finalPoint + typedef void join_func(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width); void bevel_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double /*width*/) { res.appendNew(outgoing.initialPoint()); + res.append(outgoing); } void round_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, double width) { res.appendNew(width, width, 0, false, width <= 0, outgoing.initialPoint()); + res.append(outgoing); } void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) @@ -81,18 +94,25 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub double len = Geom::distance(p, point_on_path); if (len <= miter) { // miter OK, check to see if we can do a relocation - // TODO FIXME - /*if (auto line = cast(const(LineSegment))res.back_open) { - Curve copy = line.duplicate; - copy.setFinal(p); - res.erase_last(); - res.append(copy); - } else {*/ + bool ls = dynamic_cast(&res.back_open()); + if (ls) { + res.setFinal(p); + } else { res.appendNew(p); - //} + } } } + res.appendNew(outgoing.initialPoint()); + + // check if we can do another relocation + + bool ls = dynamic_cast(&outgoing); + if (ls) { + res.setFinal(outgoing.finalPoint()); + } else { + res.append(outgoing); + } } // might need a little reworking @@ -152,6 +172,7 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou printf("WARNING: Error extrapolating line join: %s\n", ex.what()); path_builder.appendNew(endPt); } + path_builder.append(outgoing); } else { // 1 or no solutions found, default to miter miter_join(path_builder, outgoing, miter_limit, line_width); @@ -164,11 +185,36 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou void join_inside(Geom::Path& res, Geom::Curve const& outgoing) { - res.appendNew(outgoing.initialPoint()); + Geom::Curve const& incoming = res.back_open(); + Geom::Crossings cross = Geom::crossings(incoming, outgoing); + + if (!cross.empty()) { + // yeah if we could avoid allocing that'd be great + Geom::Curve *d1 = incoming.portion(0., cross[0].ta); + res.erase_last(); + res.append(*d1); + delete d1; + + Geom::Curve *d2 = outgoing.portion(cross[0].tb, 1.); + res.setFinal(d2->initialPoint()); + res.append(*d2); + delete d2; + } else { + res.appendNew(outgoing.initialPoint()); + res.append(outgoing); + } } void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, double miter, Inkscape::LineJoinType join) { + Geom::Curve const& outgoing = to_add[0]; + if (Geom::are_near(res.finalPoint(), outgoing.initialPoint())) { + // if the points are /that/ close, just ignore this one + res.setFinal(outgoing.initialPoint()); + res.append(outgoing); + return; + } + Geom::Point tang1 = -Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); //Geom::Point tang2 = to_add[0].unitTangentAt(0); Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); @@ -189,12 +235,10 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou default: jf = &miter_join; } - jf(res, to_add[0], miter, width); + jf(res, outgoing, miter, width); } else { - join_inside(res, to_add[0]); + join_inside(res, outgoing); } - - res.append(to_add); } // Offsetting a line segment is mathematically stable and quick to do @@ -359,8 +403,40 @@ void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) } } +typedef void cap_func(Geom::PathBuilder& res, Geom::Path const& with_dir, Geom::Path const& against_dir, double width); + +void flat_cap(Geom::PathBuilder& res, Geom::Path const&, Geom::Path const& against_dir, double) +{ + res.lineTo(against_dir.initialPoint()); +} + +void round_cap(Geom::PathBuilder& res, Geom::Path const&, Geom::Path const& against_dir, double width) +{ + res.arcTo(width / 2., width / 2., 0., true, false, against_dir.initialPoint()); +} + +void square_cap(Geom::PathBuilder& res, Geom::Path const& with_dir, Geom::Path const& against_dir, double width) +{ + width /= 2.; + Geom::Point normal_1 = -Geom::unitTangentAt(Geom::reverse(with_dir.back().toSBasis()), 0.); + Geom::Point normal_2 = -against_dir[0].unitTangentAt(0.); + res.lineTo(with_dir.finalPoint() + normal_1*width); + res.lineTo(against_dir.initialPoint() + normal_2*width); + res.lineTo(against_dir.initialPoint()); +} + +void peak_cap(Geom::PathBuilder& res, Geom::Path const& with_dir, Geom::Path const& against_dir, double width) +{ + width /= 2.; + Geom::Point normal_1 = -Geom::unitTangentAt(Geom::reverse(with_dir.back().toSBasis()), 0.); + Geom::Point normal_2 = -against_dir[0].unitTangentAt(0.); + Geom::Point midpoint = ((with_dir.finalPoint() + normal_1*width) + (against_dir.initialPoint() + normal_2*width)) * 0.5; + res.lineTo(midpoint); + res.lineTo(against_dir.initialPoint()); } +} // namespace + namespace Inkscape { Geom::PathVector outline(Geom::Path const& input, double width, double miter, LineJoinType join, LineCapType butt) @@ -374,33 +450,24 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li res.moveTo(with_dir[0].initialPoint()); res.append(with_dir); + cap_func *cf; + switch (butt) { + case BUTT_ROUND: + cf = &round_cap; + break; + case BUTT_SQUARE: + cf = &square_cap; + break; + case BUTT_PEAK: + cf = &peak_cap; + break; + default: + cf = &flat_cap; + } + // glue caps if (!input.closed()) { - switch (butt) { - case BUTT_ROUND: - res.arcTo(width / 2., width / 2., 0., true, false, against_dir.initialPoint()); - break; - case BUTT_SQUARE: { - Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(input[input.size()-1].toSBasis()), 0.); - double radius = 0.5 * Geom::distance(with_dir.finalPoint(), against_dir.initialPoint()); - res.lineTo(with_dir.finalPoint() + end_deriv*radius); - res.lineTo(against_dir.initialPoint() + end_deriv*radius); - res.lineTo(against_dir.initialPoint()); - break; - } - case BUTT_PEAK: { - Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(input[input.size()-1].toSBasis()), 0.); - double radius = 0.5 * Geom::distance(with_dir.finalPoint(), against_dir.initialPoint()); - Geom::Point midpoint = ((with_dir.finalPoint() + against_dir.initialPoint()) * 0.5) + end_deriv*radius; - res.lineTo(midpoint); - res.lineTo(against_dir.initialPoint()); - break; - } - case BUTT_FLAT: - default: - res.lineTo(against_dir.initialPoint()); - break; - } + cf(res, with_dir, against_dir, width); } else { res.moveTo(against_dir.initialPoint()); } @@ -408,30 +475,7 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li res.append(against_dir); if (!input.closed()) { - switch(butt) { - case BUTT_ROUND: - res.arcTo(width / 2., width / 2., 0., true, false, with_dir.initialPoint()); - break; - case BUTT_SQUARE: { - Geom::Point end_deriv = -input[0].unitTangentAt(0.); - double radius = 0.5 * Geom::distance(against_dir.finalPoint(), with_dir.initialPoint()); - res.lineTo(against_dir.finalPoint() + end_deriv*radius); - res.lineTo(with_dir.initialPoint() + end_deriv*radius); - res.lineTo(with_dir.initialPoint()); - break; - } - case BUTT_PEAK: { - Geom::Point end_deriv = -input[0].unitTangentAt(0.); - double radius = 0.5 * Geom::distance(against_dir.finalPoint(), with_dir.initialPoint()); - Geom::Point midpoint = ((against_dir.finalPoint() + with_dir.initialPoint()) * 0.5) + end_deriv*radius; - res.lineTo(midpoint); - res.lineTo(with_dir.initialPoint()); - break; - } - case BUTT_FLAT: - default: - res.lineTo(with_dir.initialPoint()); - } + cf(res, against_dir, with_dir, width); res.closePath(); } @@ -451,7 +495,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin res.start(start); // Do two curves at a time for efficiency, since the join function needs to know the outgoing curve as well - const size_t k = input.size_default(); + const size_t k = (input.back_closed().isDegenerate() && input.closed()) + ?input.size_default()-1:input.size_default(); for (size_t u = 0; u < k; u += 2) { temp = Geom::Path(); @@ -462,6 +507,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin res.append(temp); } else { outline_helper(res, temp, width, miter, join); + res.insert(res.end(), ++temp.begin(), temp.end()); } // odd number of paths @@ -469,15 +515,11 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin temp = Geom::Path(); offset_curve(temp, &input[u+1], width); outline_helper(res, temp, width, miter, join); + res.insert(res.end(), ++temp.begin(), temp.end()); } } if (input.closed()) { - if (input.back_closed().isDegenerate()) { - res.erase_last(); - res.erase_last(); // ? - } - Geom::Curve const &c1 = res.back(); Geom::Curve const &c2 = res.front(); temp = Geom::Path(); @@ -485,9 +527,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin Geom::Path temp2; temp2.append(c2); outline_helper(temp, temp2, width, miter, join); - temp.erase_last(); // we already outlined c2 - temp.erase(temp.begin()); // we already outlined c1 - + res.erase(res.begin()); + res.erase_last(); // res.append(temp); res.close(); -- cgit v1.2.3 From 8114c1ddc31f502875e2100adcf454e2cedb2b50 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Mon, 23 Mar 2015 20:43:28 -0400 Subject: Path outliner: refactor extrapolated joiner, allow joining line segments; some more optimizations all around (bzr r14031) --- src/helper/geom-pathstroke.cpp | 220 +++++++++++++++++++++++++++++------------ 1 file changed, 155 insertions(+), 65 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 6fcfb79d5..d3147f233 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -19,6 +19,74 @@ namespace Geom { // 2geom/circle-circle.cpp, no header int circle_circle_intersection(Point X0, double r0, Point X1, double r1, Point &p0, Point &p1); +/** + * Determine the intersection points between a circle C0 and a line defined + * by two points, X0 and X1. + * + * Which intersection point is assigned to p0 or p1 is unspecified, and callers + * should not depend on any particular intersection always being assigned to p0. + * + * Returns: + * If the line and circle do not cross, 0 is returned. + * If solution(s) exist, 2 is returned, and the results are written to p0 and p1. + */ +static int circle_line_intersection(Circle C0, Point X0, Point X1, Point &p0, Point &p1) +{ + /* equation of a circle: (x - h)^2 + (y - k)^2 = r^2 */ + Coord r = C0.ray(); + Coord h = C0.center()[X]; + Coord k = C0.center()[Y]; + + Coord x0, y0; + Coord x1, y1; + + if (are_near(X1[X], X0[X])) { + /* slope is undefined (vertical line) */ + Coord c = X0[X]; + Coord det = r*r - (c-h)*(c-h); + + /* no intersection */ + if (det < 0) + return 0; + + /* solve for y */ + y0 = k + std::sqrt(det); + y1 = k - std::sqrt(det); + + // x == c (always) + x0 = c; + x1 = c; + } else { + /* equation of a line: y = mx + b */ + Coord m = (X1[Y] - X0[Y]) / (X1[X] - X0[X]); + Coord b = X0[Y] - m*X0[X]; + + /* obtain quadratic for x: */ + Coord A = m*m + 1; + Coord B = 2*h - 2*b*m + 2*k*m; + Coord C = b*b + h*h + k*k - r*r - 2*b*k; + + Coord det = B*B - 4*A*C; + + /* no intersection, circle and line do not cross */ + if (det < 0) + return 0; + + /* solve quadratic */ + x0 = (B + std::sqrt(det)) / (2*A); + x1 = (B - std::sqrt(det)) / (2*A); + + /* substitute the calculated x times to determine the y values */ + y0 = m*x0 + b; + y1 = m*x1 + b; + } + + p0 = Point(x0, y0); + p1 = Point(x1, y1); + + return 2; +} + static Point intersection_point(Point origin_a, Point vector_a, Point origin_b, Point vector_b) { Coord denom = cross(vector_b, vector_a); @@ -88,13 +156,16 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); Geom::Point tang2 = outgoing.unitTangentAt(0); Geom::Point p = Geom::intersection_point(incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2); + + bool satisfied = false; + if (p.isFinite()) { // check size of miter Geom::Point point_on_path = incoming.finalPoint() - Geom::rot90(tang1)*width; - double len = Geom::distance(p, point_on_path); - if (len <= miter) { + satisfied = Geom::distance(p, point_on_path) <= miter; + if (satisfied) { // miter OK, check to see if we can do a relocation - bool ls = dynamic_cast(&res.back_open()); + bool ls = res.back_open().degreesOfFreedom() <= 4; if (ls) { res.setFinal(p); } else { @@ -106,81 +177,93 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub res.appendNew(outgoing.initialPoint()); // check if we can do another relocation + bool ls = outgoing.degreesOfFreedom() <= 4; - bool ls = dynamic_cast(&outgoing); - if (ls) { + if (satisfied && ls) { res.setFinal(outgoing.finalPoint()); } else { res.append(outgoing); } } -// might need a little reworking +Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point endPt) +{ + Geom::Point sol; + if ( dot(tang2,points[0]-endPt) > 0 ) { + // points[0] is bad, choose points[1] + sol = points[1]; + } else if ( dot(tang2,points[1]-endPt) > 0 ) { // points[0] could be good, now check points[1] + // points[1] is bad, choose points[0] + sol = points[0]; + } else { + // both points are good, choose nearest + sol = ( distanceSq(endPt, points[0]) < distanceSq(endPt, points[1]) ) ? points[0] : points[1]; + } + return sol; +} + void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width) { using namespace Geom; Geom::Curve const& incoming = path_builder.back(); Geom::Point endPt = outgoing.initialPoint(); + Geom::Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0); + + Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.); + Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0); + + bool inc_ls = !circle1.center().isFinite(); + bool out_ls = !circle2.center().isFinite(); - // The method used when extrapolating curves fails to work when either side of the join to be extrapolated - // is a line segment. When this situation is encountered, fall back to a regular miter join. - bool lineProblem = (dynamic_cast(&incoming)) || (dynamic_cast(&outgoing)); - if (lineProblem == false) { - // Geom::Point tang1 = Geom::unitTangentAt(Geom::reverse(incoming.toSBasis()), 0.); - Geom::Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0); + Geom::Point points[2]; - Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.); - Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0); + int solutions = 0; + Geom::EllipticalArc *arc0 = NULL; + Geom::EllipticalArc *arc1 = NULL; - Geom::Point points[2]; - int solutions = Geom::circle_circle_intersection(circle1.center(), circle1.ray(), - circle2.center(), circle2.ray(), - points[0], points[1]); + if (!inc_ls && !out_ls) { + solutions = Geom::circle_circle_intersection(circle1.center(), circle1.ray(), + circle2.center(), circle2.ray(), + points[0], points[1]); if (solutions == 2) { - Geom::Point sol(0,0); - if ( dot(tang2,points[0]-endPt) > 0 ) { - // points[0] is bad, choose points[1] - sol = points[1]; - } else if ( dot(tang2,points[1]-endPt) > 0 ) { // points[0] could be good, now check points[1] - // points[1] is bad, choose points[0] - sol = points[0]; - } else { - // both points are good, choose nearest - sol = ( distanceSq(endPt, points[0]) < distanceSq(endPt, points[1]) ) ? points[0] : points[1]; - } + Geom::Point sol = pick_solution(points, tang2, endPt); - Geom::EllipticalArc *arc0 = circle1.arc(incoming.finalPoint(), 0.5*(incoming.finalPoint()+sol), sol, true); - Geom::EllipticalArc *arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); - try { - if (arc0) { - path_builder.append(*arc0); - delete arc0; - arc0 = NULL; - } else { - throw std::exception(); - } - - if (arc1) { - path_builder.append(*arc1); - delete arc1; - arc1 = NULL; - } else { - throw std::exception(); - } - - } catch (std::exception const & ex) { - printf("WARNING: Error extrapolating line join: %s\n", ex.what()); - path_builder.appendNew(endPt); - } - path_builder.append(outgoing); - } else { - // 1 or no solutions found, default to miter - miter_join(path_builder, outgoing, miter_limit, line_width); + arc0 = circle1.arc(incoming.finalPoint(), 0.5*(incoming.finalPoint()+sol), sol, true); + arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); + } + } else if (inc_ls && !out_ls) { + solutions = Geom::circle_line_intersection(circle2, incoming.initialPoint(), incoming.finalPoint(), points[0], points[1]); + + if (solutions == 2) { + Geom::Point sol = pick_solution(points, tang2, endPt); + path_builder.setFinal(sol); + arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); + } + } else if (!inc_ls && out_ls) { + solutions = Geom::circle_line_intersection(circle1, outgoing.initialPoint(), outgoing.finalPoint(), points[0], points[1]); + + if (solutions == 2) { + Geom::Point sol = pick_solution(points, tang2, endPt); + arc0 = circle1.arc(incoming.finalPoint(), 0.5*(sol+incoming.finalPoint()), sol, true); } - } else { - // Line segments exist - miter_join(path_builder, outgoing, miter_limit, line_width); } + + if (solutions != 2) + // no solutions available, fall back to miter + return miter_join(path_builder, outgoing, miter_limit, line_width); + + if (arc0) + path_builder.append(*arc0); + if (arc1) + path_builder.append(*arc1); + + delete arc0; + delete arc1; + + if (!inc_ls && out_ls) + path_builder.appendNew(outgoing.finalPoint()); + else + path_builder.append(outgoing); } void join_inside(Geom::Path& res, Geom::Curve const& outgoing) @@ -207,6 +290,9 @@ void join_inside(Geom::Path& res, Geom::Curve const& outgoing) void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, double miter, Inkscape::LineJoinType join) { + if (res.size() == 0 || to_add.size() == 0) + return; + Geom::Curve const& outgoing = to_add[0]; if (Geom::are_near(res.finalPoint(), outgoing.initialPoint())) { // if the points are /that/ close, just ignore this one @@ -216,7 +302,6 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou } Geom::Point tang1 = -Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); - //Geom::Point tang2 = to_add[0].unitTangentAt(0); Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); bool on_outside = (Geom::dot(tang1, discontinuity_vec) >= 0); @@ -368,9 +453,11 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) { - double const tolerance = 0.0025; + double const tolerance = 0.005; size_t levels = 8; + if (current->isDegenerate()) return; // don't do anything + // TODO: we can handle SVGEllipticalArc here as well, do that! if (Geom::BezierCurve const *b = dynamic_cast(current)) { @@ -390,7 +477,7 @@ void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) break; } default: { - Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), 0.1); + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), tolerance); for (size_t i = 0; i < sbasis_path.size(); ++i) offset_curve(res, &sbasis_path[i], width); break; @@ -469,6 +556,7 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li if (!input.closed()) { cf(res, with_dir, against_dir, width); } else { + res.closePath(); res.moveTo(against_dir.initialPoint()); } @@ -476,9 +564,9 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li if (!input.closed()) { cf(res, against_dir, with_dir, width); - res.closePath(); } + res.closePath(); res.flush(); return res.peek(); } @@ -507,7 +595,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin res.append(temp); } else { outline_helper(res, temp, width, miter, join); - res.insert(res.end(), ++temp.begin(), temp.end()); + if (temp.size() > 0) + res.insert(res.end(), ++temp.begin(), temp.end()); } // odd number of paths @@ -515,7 +604,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin temp = Geom::Path(); offset_curve(temp, &input[u+1], width); outline_helper(res, temp, width, miter, join); - res.insert(res.end(), ++temp.begin(), temp.end()); + if (temp.size() > 0) + res.insert(res.end(), ++temp.begin(), temp.end()); } } -- cgit v1.2.3 From 8c5e33effcd16fac6ff807fa4b1700291892cbf7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 27 Mar 2015 17:37:16 +0100 Subject: Fix calculation of miter limit. Implement 'miter-clip' line join. (bzr r14033) --- src/helper/geom-pathstroke.cpp | 55 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index d3147f233..1908f2db7 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -6,6 +6,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include <2geom/path-sink.h> #include <2geom/point.h> #include <2geom/bezier-curve.h> @@ -150,7 +151,7 @@ void round_join(Geom::Path& res, Geom::Curve const& outgoing, double /*miter*/, res.append(outgoing); } -void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) +void miter_join_internal(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width, bool clip) { Geom::Curve const& incoming = res.back(); Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); @@ -161,8 +162,8 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub if (p.isFinite()) { // check size of miter - Geom::Point point_on_path = incoming.finalPoint() - Geom::rot90(tang1)*width; - satisfied = Geom::distance(p, point_on_path) <= miter; + Geom::Point point_on_path = incoming.finalPoint() + Geom::rot90(tang1)*width; + satisfied = Geom::distance(p, point_on_path) <= miter * 2.0 * width; if (satisfied) { // miter OK, check to see if we can do a relocation bool ls = res.back_open().degreesOfFreedom() <= 4; @@ -171,6 +172,31 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub } else { res.appendNew(p); } + } else if (clip) { + // miter needs clipping, find two points + Geom::Line bisector(point_on_path, p); + Geom::Point point_limit = point_on_path + miter * 2.0 * width * bisector.versor(); + + Geom::Line line_limit = + Geom::Line::from_origin_and_versor( point_limit, bisector.versor().cw() ); + + Geom::Line incoming_line( incoming.finalPoint(), p ); + Geom::Line outgoing_line( p, outgoing.initialPoint() ); + + Geom::OptCrossing i1 = intersection( line_limit, incoming_line ); + Geom::OptCrossing i2 = intersection( line_limit, outgoing_line ); + + // It would be nice to have a simple point returned by intersection! + Geom::Point p1 = line_limit.pointAt( (*i1).ta ); + Geom::Point p2 = line_limit.pointAt( (*i2).ta ); + + bool ls = res.back_open().degreesOfFreedom() <= 4; + if (ls) { + res.setFinal(p1); + } else { + res.appendNew(p1); + } + res.appendNew(p2); } } @@ -179,13 +205,21 @@ void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, doub // check if we can do another relocation bool ls = outgoing.degreesOfFreedom() <= 4; - if (satisfied && ls) { + if ( (satisfied || clip) && ls) { res.setFinal(outgoing.finalPoint()); } else { res.append(outgoing); } } +void miter_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) { + miter_join_internal( res, outgoing, miter, width, false ); +} + +void miter_clip_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) { + miter_join_internal( res, outgoing, miter, width, true ); +} + Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point endPt) { Geom::Point sol; @@ -301,9 +335,13 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou return; } - Geom::Point tang1 = -Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); - Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); - bool on_outside = (Geom::dot(tang1, discontinuity_vec) >= 0); + Geom::Point tang1 = Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); + Geom::Point tang2 = Geom::unitTangentAt(to_add.front().toSBasis(), 0.); + // Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); + bool on_outside = (Geom::cross(tang1, tang2) < 0); + // std::cout << std::fixed << std::setprecision(3) + // << " in: " << tang1 << " out: " << tang2 + // << " side: " << (on_outside?"inside":"outside") << std::endl; if (on_outside) { join_func *jf; @@ -317,6 +355,9 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou case Inkscape::JOIN_EXTRAPOLATE: jf = &extrapolate_join; break; + case Inkscape::JOIN_MITER_CLIP: + jf = &miter_clip_join; + break; default: jf = &miter_join; } -- cgit v1.2.3 From ee2b444706c7fd17c381d4c330185e02fc6d3ec9 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 28 Mar 2015 22:20:44 -0400 Subject: clean up previous commit (bzr r14034) --- src/helper/geom-pathstroke.cpp | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 1908f2db7..e34546d0e 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -159,6 +159,7 @@ void miter_join_internal(Geom::Path& res, Geom::Curve const& outgoing, double mi Geom::Point p = Geom::intersection_point(incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2); bool satisfied = false; + bool inc_ls = res.back_open().degreesOfFreedom() <= 4; if (p.isFinite()) { // check size of miter @@ -166,32 +167,20 @@ void miter_join_internal(Geom::Path& res, Geom::Curve const& outgoing, double mi satisfied = Geom::distance(p, point_on_path) <= miter * 2.0 * width; if (satisfied) { // miter OK, check to see if we can do a relocation - bool ls = res.back_open().degreesOfFreedom() <= 4; - if (ls) { + if (inc_ls) { res.setFinal(p); } else { res.appendNew(p); } } else if (clip) { // miter needs clipping, find two points - Geom::Line bisector(point_on_path, p); - Geom::Point point_limit = point_on_path + miter * 2.0 * width * bisector.versor(); + Geom::Point bisector_versor = Geom::Line(point_on_path, p).versor(); + Geom::Point point_limit = point_on_path + miter * 2.0 * width * bisector_versor; - Geom::Line line_limit = - Geom::Line::from_origin_and_versor( point_limit, bisector.versor().cw() ); + Geom::Point p1 = Geom::intersection_point(incoming.finalPoint(), tang1, point_limit, bisector_versor.cw()); + Geom::Point p2 = Geom::intersection_point(outgoing.initialPoint(), tang2, point_limit, bisector_versor.cw()); - Geom::Line incoming_line( incoming.finalPoint(), p ); - Geom::Line outgoing_line( p, outgoing.initialPoint() ); - - Geom::OptCrossing i1 = intersection( line_limit, incoming_line ); - Geom::OptCrossing i2 = intersection( line_limit, outgoing_line ); - - // It would be nice to have a simple point returned by intersection! - Geom::Point p1 = line_limit.pointAt( (*i1).ta ); - Geom::Point p2 = line_limit.pointAt( (*i2).ta ); - - bool ls = res.back_open().degreesOfFreedom() <= 4; - if (ls) { + if (inc_ls) { res.setFinal(p1); } else { res.appendNew(p1); @@ -203,9 +192,9 @@ void miter_join_internal(Geom::Path& res, Geom::Curve const& outgoing, double mi res.appendNew(outgoing.initialPoint()); // check if we can do another relocation - bool ls = outgoing.degreesOfFreedom() <= 4; + bool out_ls = outgoing.degreesOfFreedom() <= 4; - if ( (satisfied || clip) && ls) { + if ( (satisfied || clip) && out_ls) { res.setFinal(outgoing.finalPoint()); } else { res.append(outgoing); @@ -337,11 +326,7 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou Geom::Point tang1 = Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); Geom::Point tang2 = Geom::unitTangentAt(to_add.front().toSBasis(), 0.); - // Geom::Point discontinuity_vec = to_add.initialPoint() - res.finalPoint(); bool on_outside = (Geom::cross(tang1, tang2) < 0); - // std::cout << std::fixed << std::setprecision(3) - // << " in: " << tang1 << " out: " << tang2 - // << " side: " << (on_outside?"inside":"outside") << std::endl; if (on_outside) { join_func *jf; -- cgit v1.2.3 From ef9edf66715ddbc498b31e921e2506c6e87116fc Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 29 Mar 2015 22:33:48 +0200 Subject: Add clipping at miter-length to 'arcs' line join. (bzr r14036) --- src/helper/geom-pathstroke.cpp | 152 +++++++++++++++++++++++++++++++++++------ 1 file changed, 131 insertions(+), 21 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index e34546d0e..aaafea98f 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -225,12 +225,14 @@ Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point return sol; } -void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width) +void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter, double width) { using namespace Geom; Geom::Curve const& incoming = path_builder.back(); + Geom::Point startPt = incoming.finalPoint(); Geom::Point endPt = outgoing.initialPoint(); - Geom::Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0); + Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); + Geom::Point tang2 = outgoing.unitTangentAt(0); Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.); Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0); @@ -241,52 +243,160 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou Geom::Point points[2]; int solutions = 0; - Geom::EllipticalArc *arc0 = NULL; Geom::EllipticalArc *arc1 = NULL; + Geom::EllipticalArc *arc2 = NULL; + Geom::Point sol; + Geom::Point p1; + Geom::Point p2; if (!inc_ls && !out_ls) { + // Two circles solutions = Geom::circle_circle_intersection(circle1.center(), circle1.ray(), circle2.center(), circle2.ray(), points[0], points[1]); if (solutions == 2) { - Geom::Point sol = pick_solution(points, tang2, endPt); - - arc0 = circle1.arc(incoming.finalPoint(), 0.5*(incoming.finalPoint()+sol), sol, true); - arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); + sol = pick_solution(points, tang2, endPt); + arc1 = circle1.arc(startPt, 0.5*(startPt+sol), sol, true); + arc2 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); } } else if (inc_ls && !out_ls) { + // Line and circle solutions = Geom::circle_line_intersection(circle2, incoming.initialPoint(), incoming.finalPoint(), points[0], points[1]); if (solutions == 2) { - Geom::Point sol = pick_solution(points, tang2, endPt); - path_builder.setFinal(sol); - arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); + sol = pick_solution(points, tang2, endPt); + arc2 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true); } } else if (!inc_ls && out_ls) { + // Circle and line solutions = Geom::circle_line_intersection(circle1, outgoing.initialPoint(), outgoing.finalPoint(), points[0], points[1]); if (solutions == 2) { - Geom::Point sol = pick_solution(points, tang2, endPt); - arc0 = circle1.arc(incoming.finalPoint(), 0.5*(sol+incoming.finalPoint()), sol, true); + sol = pick_solution(points, tang2, endPt); + arc1 = circle1.arc(startPt, 0.5*(sol+startPt), sol, true); } } if (solutions != 2) // no solutions available, fall back to miter - return miter_join(path_builder, outgoing, miter_limit, line_width); + return miter_clip_join(path_builder, outgoing, miter, width); + + // We have a solution, thus sol is defined. + p1 = sol; + + // See if we need to clip. Miter length is measured along a circular arc that is tangent to the + // bisector of the incoming and out going angles and passes through the end point (sol) of the + // line join. + + // Center of circle is intersection of a line orthogonal to bisector and a line bisecting + // a chord connecting the path end point (point_on_path) and the join end point (sol). + Geom::Point point_on_path = startPt + Geom::rot90(tang1)*width; + Geom::Line bisector = make_angle_bisector_line( startPt, point_on_path, endPt ); + Geom::Line ortho = make_orthogonal_line(point_on_path, bisector); + + Geom::LineSegment chord( point_on_path, sol ); + Geom::Line bisector_chord = make_bisector_line( chord ); + + Geom::Line limit_line; + double miter_limit = 2.0 * width * miter; + bool clipped = false; + + if( are_parallel( bisector_chord, ortho ) ) { + + // No intersection (can happen if curvatures are equal but opposite) + if( Geom::distance( point_on_path, sol ) > miter_limit ) { + clipped = true; + Geom::Point limit_point = point_on_path + miter_limit * bisector.versor(); + limit_line = make_parallel_line( limit_point, ortho ); + } + + } else { + + Geom::Point center = + Geom::intersection_point( bisector_chord.pointAt(0), bisector_chord.versor(), + ortho.pointAt(0), ortho.versor() ); + Geom::Coord radius = distance( center, point_on_path ); + Geom::Circle circle_center( center, radius ); + + double limit_angle = miter_limit / radius; + Geom::Ray start_ray( center, point_on_path ); + Geom::Ray end_ray( center, sol ); + Geom::Line limit_line( center, 0 ); // Angle set below + + if( Geom::cross( start_ray.versor(), end_ray.versor() ) > 0 ) { + limit_line.setAngle( start_ray.angle() - limit_angle ); + } else { + limit_line.setAngle( start_ray.angle() + limit_angle ); + } + + Geom::EllipticalArc* arc_center = circle_center.arc(point_on_path, 0.5*(point_on_path + sol), sol, true); + if( arc_center && arc_center->sweepAngle() > limit_angle ) { + // We need to clip + clipped = true; + + if (!inc_ls ) { + // Incoming circular + solutions = Geom::circle_line_intersection(circle1, limit_line.pointAt(0), limit_line.pointAt(1), points[0], points[1]); + + if (solutions == 2) { + p1 = pick_solution(points, tang2, endPt); + delete arc1; + arc1 = circle1.arc(startPt, 0.5*(p1+startPt), p1, true); + } + } else { + p1 = Geom::intersection_point( startPt, tang1, limit_line.pointAt(0), limit_line.versor() ); + } - if (arc0) - path_builder.append(*arc0); - if (arc1) + if (!out_ls ) { + // Outgoing circular + solutions = Geom::circle_line_intersection(circle2, limit_line.pointAt(0), limit_line.pointAt(1), points[0], points[1]); + + if (solutions == 2) { + p2 = pick_solution(points, tang1, endPt); + delete arc2; + arc2 = circle2.arc(p2, 0.5*(p2+endPt), endPt, true); + } + } else { + p2 = Geom::intersection_point( endPt, tang2, limit_line.pointAt(0), limit_line.versor() ); + } + } + // std::cout << " IFP: " << startPt + // << " POP: " << point_on_path + // << " OIP: " << endPt << std::endl; + // std::cout << " center: " << center << std::endl; + // std::cout << " radius: " << radius << std::endl; + // std::cout << " miter_limit: " << miter_limit << std::endl; + // std::cout << " limit_angle: " << limit_angle << std::endl; + // std::cout << " start_ray: " << Geom::Line( start_ray ) << std::endl; + // std::cout << " limit_line: " << limit_line << std::endl; + // std::cout << " P1 out: " << p1 << std::endl; + // std::cout << " P2 out: " << p2 << std::endl; + } + + // Add initial + if (arc1) { path_builder.append(*arc1); + } else { + // Straight line segment: move last point + path_builder.setFinal(p1); + } - delete arc0; - delete arc1; + if( clipped ) { + path_builder.appendNew(p2); + } - if (!inc_ls && out_ls) - path_builder.appendNew(outgoing.finalPoint()); - else + // Add outgoing + if (arc2) { + path_builder.append(*arc2); path_builder.append(outgoing); + } else { + // Straight line segment: + path_builder.appendNew(outgoing.finalPoint()); + } + + delete arc1; + delete arc2; + } void join_inside(Geom::Path& res, Geom::Curve const& outgoing) -- cgit v1.2.3 From c129639bcc5baa175bbdfacd3c7fed22b0b51b60 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 31 Mar 2015 16:51:58 -0400 Subject: Update turn angle predicate for outliner (bzr r14038) --- src/helper/geom-pathstroke.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index aaafea98f..e7ee3b5f8 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -421,7 +421,14 @@ void join_inside(Geom::Path& res, Geom::Curve const& outgoing) } } -void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, double miter, Inkscape::LineJoinType join) +bool decide(Geom::Curve const& incoming, Geom::Curve const& outgoing) +{ + Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); + Geom::Point tang2 = outgoing.unitTangentAt(0.); + return (Geom::cross(tang1, tang2) < 0); +} + +void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, bool on_outside, double miter, Inkscape::LineJoinType join) { if (res.size() == 0 || to_add.size() == 0) return; @@ -434,10 +441,6 @@ void outline_helper(Geom::Path& res, Geom::Path const& to_add, double width, dou return; } - Geom::Point tang1 = Geom::unitTangentAt(reverse(res.back().toSBasis()), 0.); - Geom::Point tang2 = Geom::unitTangentAt(to_add.front().toSBasis(), 0.); - bool on_outside = (Geom::cross(tang1, tang2) < 0); - if (on_outside) { join_func *jf; switch (join) { @@ -730,7 +733,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin if (u == 0) { res.append(temp); } else { - outline_helper(res, temp, width, miter, join); + bool on_outside = decide(input[u], input[u-1]); + outline_helper(res, temp, width, on_outside, miter, join); if (temp.size() > 0) res.insert(res.end(), ++temp.begin(), temp.end()); } @@ -739,7 +743,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin if (u < k - 1) { temp = Geom::Path(); offset_curve(temp, &input[u+1], width); - outline_helper(res, temp, width, miter, join); + bool on_outside = decide(input[u], input[u+1]); + outline_helper(res, temp, width, on_outside, miter, join); if (temp.size() > 0) res.insert(res.end(), ++temp.begin(), temp.end()); } @@ -752,7 +757,8 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin temp.append(c1); Geom::Path temp2; temp2.append(c2); - outline_helper(temp, temp2, width, miter, join); + bool on_outside = decide(input.back(), input.front()); + outline_helper(temp, temp2, width, on_outside, miter, join); res.erase(res.begin()); res.erase_last(); // -- cgit v1.2.3 From f64c0f8c7974a5ed8844aa07ff220dabf4aa54ca Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 31 Mar 2015 17:47:50 -0400 Subject: Small cleanup: consistency, style (bzr r14039) --- src/helper/geom-pathstroke.cpp | 75 +++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 44 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index e7ee3b5f8..56200402b 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -225,10 +225,11 @@ Geom::Point pick_solution(Geom::Point points[2], Geom::Point tang2, Geom::Point return sol; } -void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter, double width) +void extrapolate_join(Geom::Path& res, Geom::Curve const& outgoing, double miter, double width) { using namespace Geom; - Geom::Curve const& incoming = path_builder.back(); + + Geom::Curve const& incoming = res.back(); Geom::Point startPt = incoming.finalPoint(); Geom::Point endPt = outgoing.initialPoint(); Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); @@ -279,7 +280,7 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou if (solutions != 2) // no solutions available, fall back to miter - return miter_clip_join(path_builder, outgoing, miter, width); + return miter_clip_join(res, outgoing, miter, width); // We have a solution, thus sol is defined. p1 = sol; @@ -291,50 +292,48 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou // Center of circle is intersection of a line orthogonal to bisector and a line bisecting // a chord connecting the path end point (point_on_path) and the join end point (sol). Geom::Point point_on_path = startPt + Geom::rot90(tang1)*width; - Geom::Line bisector = make_angle_bisector_line( startPt, point_on_path, endPt ); + Geom::Line bisector = make_angle_bisector_line(startPt, point_on_path, endPt); Geom::Line ortho = make_orthogonal_line(point_on_path, bisector); - Geom::LineSegment chord( point_on_path, sol ); - Geom::Line bisector_chord = make_bisector_line( chord ); + Geom::LineSegment chord(point_on_path, sol); + Geom::Line bisector_chord = make_bisector_line(chord); Geom::Line limit_line; double miter_limit = 2.0 * width * miter; bool clipped = false; - if( are_parallel( bisector_chord, ortho ) ) { - + if (are_parallel(bisector_chord, ortho)) { // No intersection (can happen if curvatures are equal but opposite) - if( Geom::distance( point_on_path, sol ) > miter_limit ) { + if (Geom::distance(point_on_path, sol) > miter_limit) { clipped = true; Geom::Point limit_point = point_on_path + miter_limit * bisector.versor(); limit_line = make_parallel_line( limit_point, ortho ); } - } else { - Geom::Point center = Geom::intersection_point( bisector_chord.pointAt(0), bisector_chord.versor(), ortho.pointAt(0), ortho.versor() ); - Geom::Coord radius = distance( center, point_on_path ); - Geom::Circle circle_center( center, radius ); + Geom::Coord radius = distance(center, point_on_path); + Geom::Circle circle_center(center, radius); double limit_angle = miter_limit / radius; - Geom::Ray start_ray( center, point_on_path ); - Geom::Ray end_ray( center, sol ); - Geom::Line limit_line( center, 0 ); // Angle set below - if( Geom::cross( start_ray.versor(), end_ray.versor() ) > 0 ) { - limit_line.setAngle( start_ray.angle() - limit_angle ); + Geom::Ray start_ray(center, point_on_path); + Geom::Ray end_ray(center, sol); + Geom::Line limit_line(center, 0); // Angle set below + + if (Geom::cross(start_ray.versor(), end_ray.versor()) > 0) { + limit_line.setAngle(start_ray.angle() - limit_angle); } else { - limit_line.setAngle( start_ray.angle() + limit_angle ); + limit_line.setAngle(start_ray.angle() + limit_angle); } - Geom::EllipticalArc* arc_center = circle_center.arc(point_on_path, 0.5*(point_on_path + sol), sol, true); - if( arc_center && arc_center->sweepAngle() > limit_angle ) { + Geom::EllipticalArc *arc_center = circle_center.arc(point_on_path, 0.5*(point_on_path + sol), sol, true); + if (arc_center && arc_center->sweepAngle() > limit_angle) { // We need to clip clipped = true; - if (!inc_ls ) { + if (!inc_ls) { // Incoming circular solutions = Geom::circle_line_intersection(circle1, limit_line.pointAt(0), limit_line.pointAt(1), points[0], points[1]); @@ -344,10 +343,10 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou arc1 = circle1.arc(startPt, 0.5*(p1+startPt), p1, true); } } else { - p1 = Geom::intersection_point( startPt, tang1, limit_line.pointAt(0), limit_line.versor() ); + p1 = Geom::intersection_point(startPt, tang1, limit_line.pointAt(0), limit_line.versor()); } - if (!out_ls ) { + if (!out_ls) { // Outgoing circular solutions = Geom::circle_line_intersection(circle2, limit_line.pointAt(0), limit_line.pointAt(1), points[0], points[1]); @@ -357,46 +356,34 @@ void extrapolate_join(Geom::Path& path_builder, Geom::Curve const& outgoing, dou arc2 = circle2.arc(p2, 0.5*(p2+endPt), endPt, true); } } else { - p2 = Geom::intersection_point( endPt, tang2, limit_line.pointAt(0), limit_line.versor() ); + p2 = Geom::intersection_point(endPt, tang2, limit_line.pointAt(0), limit_line.versor()); } } - // std::cout << " IFP: " << startPt - // << " POP: " << point_on_path - // << " OIP: " << endPt << std::endl; - // std::cout << " center: " << center << std::endl; - // std::cout << " radius: " << radius << std::endl; - // std::cout << " miter_limit: " << miter_limit << std::endl; - // std::cout << " limit_angle: " << limit_angle << std::endl; - // std::cout << " start_ray: " << Geom::Line( start_ray ) << std::endl; - // std::cout << " limit_line: " << limit_line << std::endl; - // std::cout << " P1 out: " << p1 << std::endl; - // std::cout << " P2 out: " << p2 << std::endl; } // Add initial if (arc1) { - path_builder.append(*arc1); + res.append(*arc1); } else { // Straight line segment: move last point - path_builder.setFinal(p1); + res.setFinal(p1); } - if( clipped ) { - path_builder.appendNew(p2); + if (clipped) { + res.appendNew(p2); } // Add outgoing if (arc2) { - path_builder.append(*arc2); - path_builder.append(outgoing); + res.append(*arc2); + res.append(outgoing); } else { // Straight line segment: - path_builder.appendNew(outgoing.finalPoint()); + res.appendNew(outgoing.finalPoint()); } delete arc1; delete arc2; - } void join_inside(Geom::Path& res, Geom::Curve const& outgoing) -- cgit v1.2.3 From ffdf1e9b2ecc1be4469678d0fbe7120bb709e3cc Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 4 Apr 2015 08:51:44 +0200 Subject: Call decide() with subpaths in proper order. (bzr r14043) --- src/helper/geom-pathstroke.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 56200402b..4b5a437b2 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -720,7 +720,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin if (u == 0) { res.append(temp); } else { - bool on_outside = decide(input[u], input[u-1]); + bool on_outside = decide(input[u-1], input[u]); outline_helper(res, temp, width, on_outside, miter, join); if (temp.size() > 0) res.insert(res.end(), ++temp.begin(), temp.end()); -- cgit v1.2.3 From 6c059f826b8e43e0bfb0516e4c9a2ecab77bdacf Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 4 Apr 2015 09:32:14 -0400 Subject: herpderp (bzr r14044) --- src/helper/geom-pathstroke.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 4b5a437b2..eb0c432c6 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -411,7 +411,7 @@ void join_inside(Geom::Path& res, Geom::Curve const& outgoing) bool decide(Geom::Curve const& incoming, Geom::Curve const& outgoing) { Geom::Point tang1 = Geom::unitTangentAt(reverse(incoming.toSBasis()), 0.); - Geom::Point tang2 = outgoing.unitTangentAt(0.); + Geom::Point tang2 = outgoing.unitTangentAt(0.); return (Geom::cross(tang1, tang2) < 0); } -- cgit v1.2.3