Skip to content

Commit 9c1cd93

Browse files
committed
Refactor to reduce closures.
1 parent 855061d commit 9c1cd93

3 files changed

Lines changed: 73 additions & 55 deletions

File tree

d3.js

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,49 +3508,32 @@ d3 = function() {
35083508
}
35093509
return stream;
35103510
}
3511-
d3.geo.transform = function(methods) {
3512-
return {
3513-
stream: function(stream) {
3514-
var transform = new d3_geo_transform(stream);
3515-
for (var k in methods) transform[k] = methods[k];
3516-
return transform;
3517-
}
3518-
};
3519-
};
3520-
function d3_geo_transform(stream) {
3521-
this.stream = stream;
3522-
}
3523-
d3_geo_transform.prototype = {
3524-
point: function(x, y) {
3525-
this.stream.point(x, y);
3526-
},
3527-
sphere: function() {
3528-
this.stream.sphere();
3529-
},
3530-
lineStart: function() {
3531-
this.stream.lineStart();
3532-
},
3533-
lineEnd: function() {
3534-
this.stream.lineEnd();
3535-
},
3536-
polygonStart: function() {
3537-
this.stream.polygonStart();
3538-
},
3539-
polygonEnd: function() {
3540-
this.stream.polygonEnd();
3541-
}
3542-
};
35433511
function d3_geo_resample(project) {
35443512
var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
35453513
function resample(stream) {
3546-
if (!maxDepth) {
3547-
var transform = new d3_geo_transform(stream);
3548-
transform.point = function(λ, φ) {
3549-
var p = project(λ, φ);
3550-
stream.point(p[0], p[1]);
3551-
};
3552-
return transform;
3553-
}
3514+
return (maxDepth ? resampleRecursive : resampleNone)(stream);
3515+
}
3516+
function resampleNone(stream) {
3517+
return {
3518+
point: function(x, y) {
3519+
x = project(x, y);
3520+
stream.point(x[0], x[1]);
3521+
},
3522+
lineStart: function() {
3523+
stream.lineStart();
3524+
},
3525+
lineEnd: function() {
3526+
stream.lineEnd();
3527+
},
3528+
polygonStart: function() {
3529+
stream.polygonStart();
3530+
},
3531+
polygonEnd: function() {
3532+
stream.polygonEnd();
3533+
}
3534+
};
3535+
}
3536+
function resampleRecursive(stream) {
35543537
var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
35553538
var resample = {
35563539
point: point,
@@ -3617,6 +3600,38 @@ d3 = function() {
36173600
};
36183601
return resample;
36193602
}
3603+
d3.geo.transform = function(methods) {
3604+
return {
3605+
stream: function(stream) {
3606+
var transform = new d3_geo_transform(stream);
3607+
for (var k in methods) transform[k] = methods[k];
3608+
return transform;
3609+
}
3610+
};
3611+
};
3612+
function d3_geo_transform(stream) {
3613+
this.stream = stream;
3614+
}
3615+
d3_geo_transform.prototype = {
3616+
point: function(x, y) {
3617+
this.stream.point(x, y);
3618+
},
3619+
sphere: function() {
3620+
this.stream.sphere();
3621+
},
3622+
lineStart: function() {
3623+
this.stream.lineStart();
3624+
},
3625+
lineEnd: function() {
3626+
this.stream.lineEnd();
3627+
},
3628+
polygonStart: function() {
3629+
this.stream.polygonStart();
3630+
},
3631+
polygonEnd: function() {
3632+
this.stream.polygonEnd();
3633+
}
3634+
};
36203635
d3.geo.path = function() {
36213636
var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
36223637
function path(object) {

0 commit comments

Comments
 (0)