Skip to content

Commit 1dd2f40

Browse files
committed
Shared point-based stream transform.
Rather than use d3_geo_transform, parts of d3.geo that need a point-based geometry stream transform now use d3_geo_transformPoint, which is slightly more efficient. (This is the same as the d3_geo_streamTransform that was removed in ac9f51f.)
1 parent 9c1cd93 commit 1dd2f40

6 files changed

Lines changed: 84 additions & 84 deletions

File tree

d3.js

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,24 +3514,10 @@ d3 = function() {
35143514
return (maxDepth ? resampleRecursive : resampleNone)(stream);
35153515
}
35163516
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-
};
3517+
return d3_geo_transformPoint(stream, function(x, y) {
3518+
x = project(x, y);
3519+
stream.point(x[0], x[1]);
3520+
});
35353521
}
35363522
function resampleRecursive(stream) {
35373523
var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
@@ -3600,38 +3586,6 @@ d3 = function() {
36003586
};
36013587
return resample;
36023588
}
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-
};
36353589
d3.geo.path = function() {
36363590
var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
36373591
function path(object) {
@@ -3684,11 +3638,59 @@ d3 = function() {
36843638
return project([ x * d3_degrees, y * d3_degrees ]);
36853639
});
36863640
return function(stream) {
3687-
var transform = new d3_geo_transform(stream = resample(stream));
3688-
transform.point = function(x, y) {
3689-
stream.point(x * d3_radians, y * d3_radians);
3690-
};
3691-
return transform;
3641+
return d3_geo_projectionRadians(resample(stream));
3642+
};
3643+
}
3644+
d3.geo.transform = function(methods) {
3645+
return {
3646+
stream: function(stream) {
3647+
var transform = new d3_geo_transform(stream);
3648+
for (var k in methods) transform[k] = methods[k];
3649+
return transform;
3650+
}
3651+
};
3652+
};
3653+
function d3_geo_transform(stream) {
3654+
this.stream = stream;
3655+
}
3656+
d3_geo_transform.prototype = {
3657+
point: function(x, y) {
3658+
this.stream.point(x, y);
3659+
},
3660+
sphere: function() {
3661+
this.stream.sphere();
3662+
},
3663+
lineStart: function() {
3664+
this.stream.lineStart();
3665+
},
3666+
lineEnd: function() {
3667+
this.stream.lineEnd();
3668+
},
3669+
polygonStart: function() {
3670+
this.stream.polygonStart();
3671+
},
3672+
polygonEnd: function() {
3673+
this.stream.polygonEnd();
3674+
}
3675+
};
3676+
function d3_geo_transformPoint(stream, point) {
3677+
return {
3678+
point: point,
3679+
sphere: function() {
3680+
stream.sphere();
3681+
},
3682+
lineStart: function() {
3683+
stream.lineStart();
3684+
},
3685+
lineEnd: function() {
3686+
stream.lineEnd();
3687+
},
3688+
polygonStart: function() {
3689+
stream.polygonStart();
3690+
},
3691+
polygonEnd: function() {
3692+
stream.polygonEnd();
3693+
}
36923694
};
36933695
}
36943696
d3.geo.projection = d3_geo_projection;
@@ -3771,11 +3773,9 @@ d3 = function() {
37713773
};
37723774
}
37733775
function d3_geo_projectionRadians(stream) {
3774-
var transform = new d3_geo_transform(stream);
3775-
transform.point = function(λ, φ) {
3776-
stream.point(λ * d3_radians, φ * d3_radians);
3777-
};
3778-
return transform;
3776+
return d3_geo_transformPoint(stream, function(x, y) {
3777+
stream.point(x * d3_radians, y * d3_radians);
3778+
});
37793779
}
37803780
function d3_geo_equirectangular(λ, φ) {
37813781
return [ λ, φ ];

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/path.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import "path-context";
1313
import "projection";
1414
import "resample";
1515
import "stream";
16-
import "transform";
1716

1817
d3.geo.path = function() {
1918
var pointRadius = 4.5,
@@ -84,9 +83,5 @@ d3.geo.path = function() {
8483

8584
function d3_geo_pathProjectStream(project) {
8685
var resample = d3_geo_resample(function(x, y) { return project([x * d3_degrees, y * d3_degrees]); });
87-
return function(stream) {
88-
var transform = new d3_geo_transform(stream = resample(stream));
89-
transform.point = function(x, y) { stream.point(x * d3_radians, y * d3_radians); };
90-
return transform;
91-
};
86+
return function(stream) { return d3_geo_projectionRadians(resample(stream)); };
9287
}

src/geo/projection.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import "geo";
99
import "path";
1010
import "resample";
1111
import "rotation";
12-
import "stream";
1312
import "transform";
1413

1514
d3.geo.projection = d3_geo_projection;
@@ -116,9 +115,7 @@ function d3_geo_projectionMutator(projectAt) {
116115
}
117116

118117
function d3_geo_projectionRadians(stream) {
119-
var transform = new d3_geo_transform(stream);
120-
transform.point = function(λ, φ) {
121-
stream.point(λ * d3_radians, φ * d3_radians);
122-
};
123-
return transform;
118+
return d3_geo_transformPoint(stream, function(x, y) {
119+
stream.point(x * d3_radians, y * d3_radians);
120+
});
124121
}

src/geo/resample.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ function d3_geo_resample(project) {
1212
}
1313

1414
function resampleNone(stream) {
15-
return {
16-
point: function(x, y) { x = project(x, y); stream.point(x[0], x[1]); },
17-
lineStart: function() { stream.lineStart(); },
18-
lineEnd: function() { stream.lineEnd(); },
19-
polygonStart: function() { stream.polygonStart(); },
20-
polygonEnd: function() { stream.polygonEnd(); }
21-
};
15+
return d3_geo_transformPoint(stream, function(x, y) {
16+
x = project(x, y);
17+
stream.point(x[0], x[1]);
18+
});
2219
}
2320

2421
function resampleRecursive(stream) {

src/geo/transform.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ d3_geo_transform.prototype = {
2323
polygonStart: function() { this.stream.polygonStart(); },
2424
polygonEnd: function() { this.stream.polygonEnd(); }
2525
};
26+
27+
function d3_geo_transformPoint(stream, point) {
28+
return {
29+
point: point,
30+
sphere: function() { stream.sphere(); },
31+
lineStart: function() { stream.lineStart(); },
32+
lineEnd: function() { stream.lineEnd(); },
33+
polygonStart: function() { stream.polygonStart(); },
34+
polygonEnd: function() { stream.polygonEnd(); },
35+
};
36+
}

0 commit comments

Comments
 (0)