Skip to content

Commit

Permalink
Don’t render empty arcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 20, 2015
1 parent 135b98f commit 6b77db4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-path",
"version": "0.1.1",
"version": "0.1.2",
"description": "Serialize Canvas path commands to SVG.",
"keywords": [
"d3",
Expand Down
3 changes: 3 additions & 0 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Path.prototype = path.prototype = {
);
}

// Is this arc empty? We’re done.
if (!r) return;

// Is this a complete circle? Draw two arcs to complete the circle.
if (da > tauEpsilon) {
this._.push(
Expand Down
12 changes: 12 additions & 0 deletions test/path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ tape("path.arc(x, y, radius, startAngle, endAngle) throws an error if the radius
test.end();
});

tape("path.arc(x, y, radius, startAngle, endAngle) may append only an M command if the radius is zero", function(test) {
var p = path.path(); p.arc(100, 100, 0, 0, Math.PI / 2);
test.pathEqual(p, "M100,100");
test.end();
});

tape("path.arc(x, y, radius, startAngle, endAngle) may append only an L command if the radius is zero", function(test) {
var p = path.path(); p.moveTo(0, 0); p.arc(100, 100, 0, 0, Math.PI / 2);
test.pathEqual(p, "M0,0L100,100");
test.end();
});

tape("path.arc(x, y, radius, startAngle, endAngle) may append an M command if the path was empty", function(test) {
var p = path.path(); p.arc(100, 100, 50, 0, Math.PI * 2);
test.pathEqual(p, "M150,100A50,50,0,1,1,50,100A50,50,0,1,1,150,100");
Expand Down

0 comments on commit 6b77db4

Please sign in to comment.