diff --git a/src/modules/graphics/Polyline.cpp b/src/modules/graphics/Polyline.cpp index 6861e759f..5ce7e2a2f 100644 --- a/src/modules/graphics/Polyline.cpp +++ b/src/modules/graphics/Polyline.cpp @@ -188,11 +188,26 @@ void MiterJoinPolyline::renderEdge(std::vector &anchors, std::vector 0) + if (fabs(det) / (segmentLength * newSegmentLength) < LINES_PARALLEL_EPS) { // lines parallel, compute as u1 = q + ns * w/2, u2 = q - ns * w/2 normals.push_back(segmentNormal); normals.push_back(-segmentNormal); + + if (Vector2::dot(segment, newSegment) < 0) + { + // line reverses direction; because the normal flips, the + // triangle strip would twist here, so insert a zero-size + // quad to contain the twist + // ____.___.____ + // | |\ /| | + // p q X q r + // |____|/ \|____| + anchors.push_back(pointA); + anchors.push_back(pointA); + normals.push_back(-segmentNormal); + normals.push_back(segmentNormal); + } } else { @@ -233,14 +248,24 @@ void BevelJoinPolyline::renderEdge(std::vector &anchors, std::vector 0) + if (fabs(det) / (segmentLength * newSegmentLength) < LINES_PARALLEL_EPS) { // lines parallel, compute as u1 = q + ns * w/2, u2 = q - ns * w/2 Vector2 newSegmentNormal = newSegment.getNormal(halfWidth / newSegmentLength); anchors.push_back(pointA); anchors.push_back(pointA); - normals.push_back(newSegmentNormal); - normals.push_back(-newSegmentNormal); + normals.push_back(segmentNormal); + normals.push_back(-segmentNormal); + + if (Vector2::dot(segment, newSegment) < 0) + { + // line reverses direction; same as for miter + anchors.push_back(pointA); + anchors.push_back(pointA); + normals.push_back(-segmentNormal); + normals.push_back(segmentNormal); + } + segment = newSegment; segmentLength = newSegmentLength; segmentNormal = newSegmentNormal;