Skip to content

Commit

Permalink
Fix more bugs in circle clipping.
Browse files Browse the repository at this point in the history
It was returning 0 rather than null when a feature was completely clipped, and
it was crashing when a closed polygon was completely clipped.
  • Loading branch information
mbostock committed Jul 3, 2012
1 parent 54b0dcb commit d0b0af5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions d3.v2.js
Expand Up @@ -7637,7 +7637,7 @@ d3.geo.circle = function() {

circle.clip = function(d) {
if (typeof origin === "function") arc.source(origin.apply(this, arguments));
return clipType(d);
return clipType(d) || null;
};

var clipType = d3_geo_type({
Expand Down Expand Up @@ -7720,7 +7720,7 @@ d3.geo.circle = function() {
// Close the clipped polygon if necessary.
p0 = coordinates[0];
p1 = clipped[0];
if (p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
if (p1 && p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
clipped.push(p1);
}

Expand Down
4 changes: 2 additions & 2 deletions d3.v2.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/geo/circle.js
Expand Up @@ -16,7 +16,7 @@ d3.geo.circle = function() {

circle.clip = function(d) {
if (typeof origin === "function") arc.source(origin.apply(this, arguments));
return clipType(d);
return clipType(d) || null;
};

var clipType = d3_geo_type({
Expand Down Expand Up @@ -99,7 +99,7 @@ d3.geo.circle = function() {
// Close the clipped polygon if necessary.
p0 = coordinates[0];
p1 = clipped[0];
if (p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
if (p1 && p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
clipped.push(p1);
}

Expand Down
5 changes: 5 additions & 0 deletions test/geo/circle-test.js
@@ -1,3 +1,5 @@
require("../env");

var vows = require("vows"),
assert = require("assert");

Expand All @@ -24,6 +26,9 @@ suite.addBatch({
[110, -47.63539018933809]
], 1e-6);
},
"can completely clip a LineString": function(clip) {
assert.isNull(clip({type: "LineString", coordinates: [[90.0, -42.37], [95.0, -42.37], [90.0, -42.37]]}));
},
"doesn't insert a duplicate point": function(clip) {
assert.inDelta(clip({type: "LineString", coordinates: [[0, 0]]}).coordinates, [[0, 0]], 1e-6);
}
Expand Down

0 comments on commit d0b0af5

Please sign in to comment.