Skip to content

Commit 58fb99d

Browse files
committedJan 13, 2013
Fix big with constant greatArc target.
The local variable `t` was masking the private field of the same name. The use of single-letter variables is preferred for smaller scopes.
1 parent baf7855 commit 58fb99d

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed
 

‎d3.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -6159,9 +6159,9 @@
61596159
return interpolate;
61606160
}
61616161
d3.geo.greatArc = function() {
6162-
var source = d3_source, s, target = d3_target, t, precision = 6 * d3_radians, interpolate;
6162+
var source = d3_source, source_, target = d3_target, target_, precision = 6 * d3_radians, interpolate;
61636163
function greatArc() {
6164-
var p0 = s || source.apply(this, arguments), p1 = t || target.apply(this, arguments), i = interpolate || d3.geo.interpolate(p0, p1), t = 0, dt = precision / i.distance, coordinates = [ p0 ];
6164+
var p0 = source_ || source.apply(this, arguments), p1 = target_ || target.apply(this, arguments), i = interpolate || d3.geo.interpolate(p0, p1), t = 0, dt = precision / i.distance, coordinates = [ p0 ];
61656165
while ((t += dt) < 1) coordinates.push(i(t));
61666166
coordinates.push(p1);
61676167
return {
@@ -6170,18 +6170,18 @@
61706170
};
61716171
}
61726172
greatArc.distance = function() {
6173-
return (interpolate || d3.geo.interpolate(s || source.apply(this, arguments), t || target.apply(this, arguments))).distance;
6173+
return (interpolate || d3.geo.interpolate(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments))).distance;
61746174
};
61756175
greatArc.source = function(_) {
61766176
if (!arguments.length) return source;
6177-
source = _, s = typeof _ === "function" ? null : _;
6178-
interpolate = s && t ? d3.geo.interpolate(s, t) : null;
6177+
source = _, source_ = typeof _ === "function" ? null : _;
6178+
interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
61796179
return greatArc;
61806180
};
61816181
greatArc.target = function(_) {
61826182
if (!arguments.length) return target;
6183-
target = _, t = typeof _ === "function" ? null : _;
6184-
interpolate = s && t ? d3.geo.interpolate(s, t) : null;
6183+
target = _, target_ = typeof _ === "function" ? null : _;
6184+
interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
61856185
return greatArc;
61866186
};
61876187
greatArc.precision = function(_) {

‎d3.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/geo/greatArc.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
d3.geo.greatArc = function() {
2-
var source = d3_source, s,
3-
target = d3_target, t,
2+
var source = d3_source, source_,
3+
target = d3_target, target_,
44
precision = 6 * d3_radians,
55
interpolate;
66

77
function greatArc() {
8-
var p0 = s || source.apply(this, arguments),
9-
p1 = t || target.apply(this, arguments),
8+
var p0 = source_ || source.apply(this, arguments),
9+
p1 = target_ || target.apply(this, arguments),
1010
i = interpolate || d3.geo.interpolate(p0, p1),
1111
t = 0,
1212
dt = precision / i.distance,
@@ -18,20 +18,20 @@ d3.geo.greatArc = function() {
1818

1919
// Length returned in radians; multiply by radius for distance.
2020
greatArc.distance = function() {
21-
return (interpolate || d3.geo.interpolate(s || source.apply(this, arguments), t || target.apply(this, arguments))).distance;
21+
return (interpolate || d3.geo.interpolate(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments))).distance;
2222
};
2323

2424
greatArc.source = function(_) {
2525
if (!arguments.length) return source;
26-
source = _, s = typeof _ === "function" ? null : _;
27-
interpolate = s && t ? d3.geo.interpolate(s, t) : null;
26+
source = _, source_ = typeof _ === "function" ? null : _;
27+
interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
2828
return greatArc;
2929
};
3030

3131
greatArc.target = function(_) {
3232
if (!arguments.length) return target;
33-
target = _, t = typeof _ === "function" ? null : _;
34-
interpolate = s && t ? d3.geo.interpolate(s, t) : null;
33+
target = _, target_ = typeof _ === "function" ? null : _;
34+
interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null;
3535
return greatArc;
3636
};
3737

‎test/geo/greatArc-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ suite.addBatch({
1717
target: [ 73 + 47 / 60, 40 + 38 / 60]
1818
}), 3973 / 6371, .5);
1919
},
20+
"source and target can be set as constants": function() {
21+
var arc = d3.geo.greatArc()
22+
.source([5, 52])
23+
.target([-120, 37])
24+
.precision(7.2);
25+
assert.inDelta(arc().coordinates, [
26+
[ 5, 52 ],
27+
[ -3.805036, 57.05083],
28+
[ -15.122869, 61.30118],
29+
[ -29.396213, 64.34584],
30+
[ -46.132729, 65.72409],
31+
[ -63.394401, 65.15597],
32+
[ -78.854311, 62.76337],
33+
[ -91.401599, 58.96701],
34+
[-101.190927, 54.21333],
35+
[-108.843633, 48.83586],
36+
[-114.961152, 43.05231],
37+
[-120, 37 ]
38+
], .5);
39+
},
2040
"geodesic": function(arc) {
2141
assert.inDelta(arc.precision(7.2)({source: [5, 52], target: [-120, 37]}).coordinates, [
2242
[ 5, 52 ],

0 commit comments

Comments
 (0)
Please sign in to comment.