Commit 876e7644 authored by Mike Bostock's avatar Mike Bostock
Browse files

Yay τ!

parent 88862d37
......@@ -1158,7 +1158,7 @@ d3 = function() {
};
return d3.rebind(drag, event, "on");
};
var π = Math.PI, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
function d3_sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0;
}
......@@ -1166,7 +1166,7 @@ d3 = function() {
return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
}
function d3_asin(x) {
return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
}
function d3_sinh(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
......@@ -2820,7 +2820,7 @@ d3 = function() {
};
}
function d3_geo_clipSort(a, b) {
return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1]) - ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
return ((a = a.point)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.point)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
}
function d3_geo_pointInPolygon(point, polygon) {
var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
......@@ -2862,7 +2862,7 @@ d3 = function() {
point: function(λ1, φ1) {
var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs(λ1 - λ0);
if (Math.abs(dλ - π) < ε) {
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? π / 2 : -π / 2);
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
listener.point(sλ0, φ0);
listener.lineEnd();
listener.lineStart();
......@@ -2898,7 +2898,7 @@ d3 = function() {
function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
var φ;
if (from == null) {
φ = direction * π / 2;
φ = direction * halfπ;
listener.point(-π, φ);
listener.point(0, φ);
listener.point(π, φ);
......@@ -3465,7 +3465,7 @@ d3 = function() {
};
function point(x, y) {
context.moveTo(x, y);
context.arc(x, y, pointRadius, 0, 2 * π);
context.arc(x, y, pointRadius, 0, τ);
}
function pointLineStart(x, y) {
context.moveTo(x, y);
......@@ -3747,7 +3747,7 @@ d3 = function() {
return forward;
};
function d3_geo_identityRotation(λ, φ) {
return [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
}
d3_geo_identityRotation.invert = d3_geo_equirectangular;
function d3_geo_rotation(δλ, δφ, δγ) {
......@@ -3755,7 +3755,7 @@ d3 = function() {
}
function d3_geo_forwardRotationλ(δλ) {
return function(λ, φ) {
return λ += δλ, [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
};
}
function d3_geo_rotationλ(δλ) {
......@@ -3814,9 +3814,9 @@ d3 = function() {
if (from != null) {
from = d3_geo_circleAngle(cr, from);
to = d3_geo_circleAngle(cr, to);
if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
if (direction > 0 ? from < to : from > to) from += direction * τ;
} else {
from = radius + direction * 2 * π;
from = radius + direction * τ;
to = radius - .5 * step;
}
for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
......@@ -4032,12 +4032,12 @@ d3 = function() {
}, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
if (!n) return d3_geo_mercator;
function forward(λ, φ) {
var ρ = Math.abs(Math.abs(φ) - π / 2) < ε ? 0 : F / Math.pow(t(φ), n);
var ρ = Math.abs(Math.abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
}
forward.invert = function(x, y) {
var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - π / 2 ];
return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
};
return forward;
}
......@@ -4070,7 +4070,7 @@ d3 = function() {
return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
}
d3_geo_mercator.invert = function(x, y) {
return [ x, 2 * Math.atan(Math.exp(y)) - π / 2 ];
return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
};
function d3_geo_mercatorProjection(project) {
var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
......@@ -4357,7 +4357,7 @@ d3 = function() {
var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
while (++i < j) {
d = d3_svg_lineSlope(points[i], points[i + 1]);
if (Math.abs(d) < 1e-6) {
if (Math.abs(d) < ε) {
m[i] = m[i + 1] = 0;
} else {
a = m[i] / d;
......@@ -5272,7 +5272,7 @@ d3 = function() {
};
}
function d3_ease_sin(t) {
return 1 - Math.cos(t * π / 2);
return 1 - Math.cos(t * halfπ);
}
function d3_ease_exp(t) {
return Math.pow(2, 10 * (t - 1));
......@@ -5283,9 +5283,9 @@ d3 = function() {
function d3_ease_elastic(a, p) {
var s;
if (arguments.length < 2) p = .45;
if (arguments.length) s = p / (2 * π) * Math.asin(1 / a); else a = 1, s = p / 4;
if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
return function(t) {
return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * π / p);
return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
};
}
function d3_ease_back(s) {
......@@ -5519,7 +5519,7 @@ d3 = function() {
});
});
}
k = (2 * π - padding * n) / k;
k = (τ - padding * n) / k;
x = 0, i = -1;
while (++i < n) {
x0 = x, j = -1;
......@@ -5971,7 +5971,7 @@ d3 = function() {
return d3_layout_hierarchyRebind(partition, hierarchy);
};
d3.layout.pie = function() {
var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * π;
var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
function pie(data) {
var values = data.map(function(d, i) {
return +value.call(pie, d, i);
......@@ -7325,7 +7325,7 @@ d3 = function() {
};
return arc;
};
var d3_svg_arcOffset = -π / 2, d3_svg_arcMax = 2 * π - 1e-6;
var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
function d3_svg_arcInnerRadius(d) {
return d.innerRadius;
}
......@@ -7881,7 +7881,7 @@ d3 = function() {
function axis(g) {
g.each(function() {
var g = d3.select(this);
var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
d3.transition(path));
var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -56,9 +56,9 @@ function d3_geo_circleInterpolate(radius, precision) {
if (from != null) {
from = d3_geo_circleAngle(cr, from);
to = d3_geo_circleAngle(cr, to);
if (direction > 0 ? from < to: from > to) from += direction * 2 * π;
if (direction > 0 ? from < to: from > to) from += direction * τ;
} else {
from = radius + direction * 2 * π;
from = radius + direction * τ;
to = radius - .5 * step;
}
for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
......
......@@ -29,7 +29,7 @@ function d3_geo_clipAntimeridianLine(listener) {
var sλ1 = λ1 > 0 ? π : -π,
= Math.abs(λ1 - λ0);
if (Math.abs( - π) < ε) { // line crosses a pole
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? π / 2 : -π / 2);
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
listener.point(sλ0, φ0);
listener.lineEnd();
listener.lineStart();
......@@ -73,7 +73,7 @@ function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
var φ;
if (from == null) {
φ = direction * π / 2;
φ = direction * halfπ;
listener.point(-π, φ);
listener.point( 0, φ);
listener.point( π, φ);
......
......@@ -138,6 +138,6 @@ function d3_geo_clipBufferListener() {
// Intersection points are sorted along the clip edge. For both antimeridian
// cutting and circle clipping, the same comparison is used.
function d3_geo_clipSort(a, b) {
return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1])
- ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
return ((a = a.point)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1])
- ((b = b.point)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
}
......@@ -12,7 +12,7 @@ function d3_geo_conicConformal(φ0, φ1) {
if (!n) return d3_geo_mercator;
function forward(λ, φ) {
var ρ = Math.abs(Math.abs(φ) - π / 2) < ε ? 0 : F / Math.pow(t(φ), n);
var ρ = Math.abs(Math.abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
return [
ρ * Math.sin(n * λ),
F - ρ * Math.cos(n * λ)
......@@ -24,7 +24,7 @@ function d3_geo_conicConformal(φ0, φ1) {
ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
return [
Math.atan2(x, ρ0_y) / n,
2 * Math.atan(Math.pow(F / ρ, 1 / n)) - π / 2
2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ
];
};
......
......@@ -7,7 +7,7 @@ function d3_geo_mercator(λ, φ) {
}
d3_geo_mercator.invert = function(x, y) {
return [x, 2 * Math.atan(Math.exp(y)) - π / 2];
return [x, 2 * Math.atan(Math.exp(y)) - halfπ];
};
function d3_geo_mercatorProjection(project) {
......
......@@ -25,7 +25,7 @@ function d3_geo_pathContext(context) {
function point(x, y) {
context.moveTo(x, y);
context.arc(x, y, pointRadius, 0, 2 * π);
context.arc(x, y, pointRadius, 0, τ);
}
function pointLineStart(x, y) {
......
......@@ -19,7 +19,7 @@ d3.geo.rotation = function(rotate) {
};
function d3_geo_identityRotation(λ, φ) {
return [λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ];
return [λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ];
}
d3_geo_identityRotation.invert = d3_geo_equirectangular;
......@@ -34,7 +34,7 @@ function d3_geo_rotation(δλ, δφ, δγ) {
function d3_geo_forwardRotationλ(δλ) {
return function(λ, φ) {
return λ += δλ, [λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ];
return λ += δλ, [λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ];
};
}
......
......@@ -74,7 +74,7 @@ function d3_ease_poly(e) {
}
function d3_ease_sin(t) {
return 1 - Math.cos(t * π / 2);
return 1 - Math.cos(t * halfπ);
}
function d3_ease_exp(t) {
......@@ -88,10 +88,10 @@ function d3_ease_circle(t) {
function d3_ease_elastic(a, p) {
var s;
if (arguments.length < 2) p = 0.45;
if (arguments.length) s = p / (2 * π) * Math.asin(1 / a);
if (arguments.length) s = p / τ * Math.asin(1 / a);
else a = 1, s = p / 4;
return function(t) {
return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * π / p);
return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
};
}
......
......@@ -56,7 +56,7 @@ d3.layout.chord = function() {
// Convert the sum to scaling factor for [0, 2pi].
// TODO Allow start and end angle to be specified.
// TODO Allow padding to be specified as percentage?
k = (2 * π - padding * n) / k;
k = (τ - padding * n) / k;
// Compute the start and end angle for each group and subgroup.
// Note: Opera has a bug reordering object literal properties!
......
......@@ -7,7 +7,7 @@ d3.layout.pie = function() {
var value = Number,
sort = d3_layout_pieSortByValue,
startAngle = 0,
endAngle = 2 * π;
endAngle = τ;
function pie(data) {
......
var π = Math.PI,
τ = 2 * π,
halfπ = π / 2,
ε = 1e-6,
ε2 = ε * ε,
d3_radians = π / 180,
......@@ -13,7 +15,7 @@ function d3_acos(x) {
}
function d3_asin(x) {
return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
}
function d3_sinh(x) {
......
......@@ -79,8 +79,8 @@ d3.svg.arc = function() {
return arc;
};
var d3_svg_arcOffset = -π / 2,
d3_svg_arcMax = 2 * π - 1e-6;
var d3_svg_arcOffset = -halfπ,
d3_svg_arcMax = τ - ε;
function d3_svg_arcInnerRadius(d) {
return d.innerRadius;
......
import "../math/trigonometry";
import "../scale/linear";
import "../scale/scale";
import "../selection/selection";
......@@ -22,8 +23,8 @@ d3.svg.axis = function() {
var ticks = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain()) : tickValues,
tickFormat = tickFormat_ == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : d3_identity) : tickFormat_,
tick = g.selectAll(".tick").data(ticks, scale),
tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", 1e-6),
tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(),
tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε),
tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(),
tickUpdate = d3.transition(tick).style("opacity", 1),
tickTransform;
......
......@@ -2,6 +2,7 @@ import "../arrays/map";
import "../core/functor";
import "../core/identity";
import "../core/true";
import "../math/trigonometry";
import "svg";
function d3_svg_line(projection) {
......@@ -403,7 +404,7 @@ function d3_svg_lineMonotoneTangents(points) {
// mk = m{k + 1} = 0 as the spline connecting these points must be flat to
// preserve monotonicity. Ignore step 4 and 5 for those k.
if (Math.abs(d) < 1e-6) {
if (Math.abs(d) < ε) {
m[i] = m[i + 1] = 0;
} else {
// 4. Let ak = mk / dk and bk = m{k + 1} / dk.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment