Skip to content

Commit

Permalink
Better point clamping in projection.clipExtent.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondavies committed Mar 21, 2013
1 parent 51228cc commit 3de9ef3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
8 changes: 3 additions & 5 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ d3 = function() {
return code;
}
}
var d3_geo_clipViewMAX = 1e15;
var d3_geo_clipViewMAX = 1e9;
function d3_geo_clipView(x0, y0, x1, y1) {
return function(listener) {
var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring;
Expand Down Expand Up @@ -2725,6 +2725,8 @@ d3 = function() {
if (v_) listener.lineEnd();
}
function linePoint(x, y) {
x = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, x));
y = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, y));
var v = visible(x, y);
if (polygon) ring.push([ x, y ]);
if (first) {
Expand Down Expand Up @@ -2765,10 +2767,6 @@ d3 = function() {
return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
}
function clipLine(a, b) {
a[0] = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, a[0]));
a[1] = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, a[1]));
b[0] = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, b[0]));
b[1] = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, b[1]));
var dx = b[0] - a[0], dy = b[1] - a[1], t = [ 0, 1 ];
if (Math.abs(dx) < ε && Math.abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;
if (d3_geo_clipViewT(x0 - a[0], dx, t) && d3_geo_clipViewT(a[0] - x1, -dx, t) && d3_geo_clipViewT(y0 - a[1], dy, t) && d3_geo_clipViewT(a[1] - y1, -dy, t)) {
Expand Down
Loading

0 comments on commit 3de9ef3

Please sign in to comment.