From f4c56b0f307b4f0f2ab499e7f10cf2a9644688c4 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 29 Apr 2015 16:23:05 -0400 Subject: Better solution picking (bzr r14073) --- src/helper/geom-pathstroke.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/helper/geom-pathstroke.cpp') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 292ba3044..1df17acf5 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -415,9 +415,28 @@ void join_inside(join_data jd) Geom::Path const& temp = jd.outgoing; Geom::Crossings cross = Geom::crossings(res, temp); - if (cross.size() == 1) { - Geom::Path d1 = res.portion(0., cross[0].ta); - Geom::Path d2 = temp.portion(cross[0].tb, temp.size()); + int solution = -1; // lol, really hope there aren't more than INT_MAX crossings + if (cross.size() == 1) solution = 0; + else if (cross.size() > 1) { + // I am not sure how well this will work -- we pick the join node closest + // to the cross point of the paths + Geom::Point original = res.finalPoint()+Geom::rot90(jd.in_tang)*jd.width; + Geom::Coord trial = Geom::L2(res.pointAt(cross[0].ta)-original); + solution = 0; + for (size_t i = 1; i < cross.size(); ++i) { + //printf("Trying %d\n", i); + Geom::Coord test = Geom::L2(res.pointAt(cross[i].ta)-original); + if (test < trial) { + trial = test; + solution = i; + //printf("Found improved solution: %f\n", trial); + } + } + } + + if (solution != -1) { + Geom::Path d1 = res.portion(0., cross[solution].ta); + Geom::Path d2 = temp.portion(cross[solution].tb, temp.size()); // Watch for bugs in 2geom crossing regarding severe inflection points res.clear(); -- cgit v1.2.3