Skip to content

Commit

Permalink
Add a sanity check for a2c arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Apr 15, 2015
1 parent 6747e2d commit a7de94a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/a2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ module.exports = function a2c(x1, y1, x2, y2, fa, fs, rx, ry, φ) {
var x1p = cos_φ*(x1-x2)/2 + sin_φ*(y1-y2)/2;
var y1p = -sin_φ*(x1-x2)/2 + cos_φ*(y1-y2)/2;

if (x1p === 0 && y1p === 0) {
// we're asked to draw line to itself
return [];
}

if (rx === 0 || ry === 0) {
// one of the radii is zero
return [];
}

var radii = correct_radii(x1p, y1p, rx, ry);
rx = radii[0];
ry = radii[1];
Expand All @@ -152,7 +162,7 @@ module.exports = function a2c(x1, y1, x2, y2, fa, fs, rx, ry, φ) {
// Split an arc to multiple segments, so each segment
// will be less than τ/4 (= 90°)
//
var segments = Math.ceil(Math.abs(Δθ) / (TAU / 4));
var segments = Math.max(Math.ceil(Math.abs(Δθ) / (TAU / 4)), 1);
Δθ /= segments;

for (var i = 0; i < segments; i++) {
Expand Down
14 changes: 14 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,19 @@ describe('API', function () {
'M100 100'
);
});

it('radii are zero', function () {
// both rx and ry are zero
assert.equal(
svgpath('M100 100A0 0 0 0 1 110 110').unarc().round().toString(),
'M100 100'
);

// rx is zero
assert.equal(
svgpath('M100 100A0 100 0 0 1 110 110').unarc().round().toString(),
'M100 100'
);
});
});
});

0 comments on commit a7de94a

Please sign in to comment.