Skip to content

Commit

Permalink
unarc: don't drop degenerated arcs, #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Jan 3, 2016
1 parent ac56660 commit 9f5b841
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/svgpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,14 @@ SvgPath.prototype.unarc = function () {
nextY = s[7];
}

// one of the radii is zero, treating it as a line segment instead
if (s[1] === 0 || s[2] === 0) {
new_segments = a2c(x, y, nextX, nextY, s[4], s[5], s[1], s[2], s[3]);

// Degenerated arcs can be ignored by renderer, but should not be dropped
// to avoid collisions wish `S A S` and so on. Replace with empty line.
if (new_segments.length === 0) {
return [ [ 'L', nextX, nextY ] ];
}

new_segments = a2c(x, y, nextX, nextY, s[4], s[5], s[1], s[2], s[3]);

new_segments.forEach(function (s) {
result.push([ 'C', s[2], s[3], s[4], s[5], s[6], s[7] ]);
});
Expand Down
2 changes: 1 addition & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ describe('API', function () {
//
assert.equal(
svgpath('M100 100A123 456 90 0 1 100 100').unarc().round(0).toString(),
'M100 100'
'M100 100L100 100'
);
});

Expand Down

0 comments on commit 9f5b841

Please sign in to comment.