Skip to content

Commit

Permalink
Alias Math.abs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 5, 2013
1 parent 28d2d39 commit 7ba007f
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 95 deletions.
85 changes: 43 additions & 42 deletions d3.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/arrays/range.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "../math/abs";

d3.range = function(start, stop, step) {
if (arguments.length < 3) {
step = 1;
Expand All @@ -8,7 +10,7 @@ d3.range = function(start, stop, step) {
}
if ((stop - start) / step === Infinity) throw new Error("infinite range");
var range = [],
k = d3_range_integerScale(Math.abs(step)),
k = d3_range_integerScale(abs(step)),
i = -1,
j;
start *= k, stop *= k, step *= k;
Expand Down
3 changes: 2 additions & 1 deletion src/format/formatPrefix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "format";
import "../math/abs";

var d3_formatPrefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"].map(d3_formatPrefix);

Expand All @@ -14,7 +15,7 @@ d3.formatPrefix = function(value, precision) {
};

function d3_formatPrefix(d, i) {
var k = Math.pow(10, Math.abs(8 - i) * 3);
var k = Math.pow(10, abs(8 - i) * 3);
return {
scale: i > 8 ? function(d) { return d / k; } : function(d) { return d * k; },
symbol: d
Expand Down
6 changes: 3 additions & 3 deletions src/geo/bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ d3.geo.bounds = (function() {
var = λ - λ_,
s = > 0 ? 1 : -1,
λi = inflection[0] * d3_degrees * s,
antimeridian = Math.abs() > 180;
antimeridian = abs() > 180;
if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
var φi = inflection[1] * d3_degrees;
if (φi > φ1) φ1 = φi;
Expand Down Expand Up @@ -101,7 +101,7 @@ d3.geo.bounds = (function() {
function ringPoint(λ, φ) {
if (p0) {
var = λ - λ_;
dλSum += Math.abs() > 180 ? + ( > 0 ? 360 : -360) : ;
dλSum += abs() > 180 ? + ( > 0 ? 360 : -360) : ;
} else λ__ = λ, φ__ = φ;
d3_geo_area.point(λ, φ);
linePoint(λ, φ);
Expand All @@ -114,7 +114,7 @@ d3.geo.bounds = (function() {
function ringEnd() {
ringPoint(λ__, φ__);
d3_geo_area.lineEnd();
if (Math.abs(dλSum) > ε) λ0 = -(λ1 = 180);
if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
range[0] = λ0, range[1] = λ1;
p0 = null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/geo/clip-antimeridian.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function d3_geo_clipAntimeridianLine(listener) {
},
point: function(λ1, φ1) {
var sλ1 = λ1 > 0 ? π : -π,
= Math.abs(λ1 - λ0);
if (Math.abs( - π) < ε) { // line crosses a pole
= abs(λ1 - λ0);
if (abs( - π) < ε) { // line crosses a pole
listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
listener.point(sλ0, φ0);
listener.lineEnd();
Expand All @@ -38,8 +38,8 @@ function d3_geo_clipAntimeridianLine(listener) {
clean = 0;
} else if (sλ0 !== sλ1 && >= π) { // line crosses antimeridian
// handle degeneracies
if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
listener.point(sλ0, φ0);
listener.lineEnd();
Expand All @@ -63,7 +63,7 @@ function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
var cosφ0,
cosφ1,
sinλ0_λ1 = Math.sin(λ0 - λ1);
return Math.abs(sinλ0_λ1) > ε
return abs(sinλ0_λ1) > ε
? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1)
- Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0))
/ (cosφ0 * cosφ1 * sinλ0_λ1))
Expand All @@ -83,7 +83,7 @@ function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
listener.point(-π, -φ);
listener.point(-π, 0);
listener.point(-π, φ);
} else if (Math.abs(from[0] - to[0]) > ε) {
} else if (abs(from[0] - to[0]) > ε) {
var s = (from[0] < to[0] ? 1 : -1) * π;
φ = direction * s / 2;
listener.point(-s, φ);
Expand Down
6 changes: 3 additions & 3 deletions src/geo/clip-circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "point-in-polygon";
function d3_geo_clipCircle(radius) {
var cr = Math.cos(radius),
smallRadius = cr > 0,
notHemisphere = Math.abs(cr) > ε, // TODO optimise for this common case
notHemisphere = abs(cr) > ε, // TODO optimise for this common case
interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);

return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-π, radius - π]);
Expand Down Expand Up @@ -146,15 +146,15 @@ function d3_geo_clipCircle(radius) {
z;
if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
var δλ = λ1 - λ0,
polar = Math.abs(δλ - π) < ε,
polar = abs(δλ - π) < ε,
meridian = polar || δλ < ε;

if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;

// Check that the first point is between a and b.
if (meridian
? polar
? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1)
? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1)
: φ0 <= q[1] && q[1] <= φ1
: δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
Expand Down
12 changes: 6 additions & 6 deletions src/geo/clip-extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ function d3_geo_clipExtent(x0, y0, x1, y1) {
};

function corner(p, direction) {
return Math.abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3
: Math.abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1
: Math.abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0
: direction > 0 ? 3 : 2; // Math.abs(p[1] - y1) < ε
return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3
: abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1
: abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0
: direction > 0 ? 3 : 2; // abs(p[1] - y1) < ε
}

function compare(a, b) {
Expand All @@ -202,7 +202,7 @@ function d3_geo_clipExtent(x0, y0, x1, y1) {
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 (abs(dx) < ε && abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;

if (d3_geo_clipExtentT(x0 - a[0], dx, t) &&
d3_geo_clipExtentT(a[0] - x1, -dx, t) &&
Expand All @@ -224,7 +224,7 @@ function d3_geo_clipExtent(x0, y0, x1, y1) {
}

function d3_geo_clipExtentT(num, denominator, t) {
if (Math.abs(denominator) < ε) return num <= 0;
if (abs(denominator) < ε) return num <= 0;

var u = num / denominator;

Expand Down
2 changes: 1 addition & 1 deletion src/geo/conic-conformal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function d3_geo_conicConformal(φ0, φ1) {
if (!n) return d3_geo_mercator;

function forward(λ, φ) {
var ρ = Math.abs(Math.abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
var ρ = abs(abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
return [
ρ * Math.sin(n * λ),
F - ρ * Math.cos(n * λ)
Expand Down
2 changes: 1 addition & 1 deletion src/geo/conic-equidistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function d3_geo_conicEquidistant(φ0, φ1) {
n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0),
G = cosφ0 / n + φ0;

if (Math.abs(n) < ε) return d3_geo_equirectangular;
if (abs(n) < ε) return d3_geo_equirectangular;

function forward(λ, φ) {
var ρ = G - φ;
Expand Down
4 changes: 2 additions & 2 deletions src/geo/graticule.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ d3.geo.graticule = function() {
function lines() {
return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X)
.concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y))
.concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return Math.abs(x % DX) > ε; }).map(x))
.concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return Math.abs(y % DY) > ε; }).map(y));
.concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > ε; }).map(x))
.concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > ε; }).map(y));
}

graticule.lines = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/geo/length.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function d3_geo_lengthLineStart() {
function nextPoint(λ, φ) {
var sinφ = Math.sin(φ *= d3_radians),
cosφ = Math.cos(φ),
t = Math.abs((λ *= d3_radians) - λ0),
t = abs((λ *= d3_radians) - λ0),
cosΔλ = Math.cos(t);
d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
Expand Down
2 changes: 1 addition & 1 deletion src/geo/path-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
},
polygonEnd: function() {
d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/geo/point-in-polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function d3_geo_pointInPolygon(point, polygon) {
sinφ = Math.sin(φ),
cosφ = Math.cos(φ),
= λ - λ0,
antimeridian = Math.abs() > π,
antimeridian = abs() > π,
k = sinφ0 * sinφ;
d3_geo_areaRingSum.add(Math.atan2(k * Math.sin(), cosφ0 * cosφ + k * Math.cos()));

Expand Down
4 changes: 2 additions & 2 deletions src/geo/resample.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ function d3_geo_resample(project) {
c = c0 + c1,
m = Math.sqrt(a * a + b * b + c * c),
φ2 = Math.asin(c /= m),
λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a),
λ2 = abs(abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a),
p = project(λ2, φ2),
x2 = p[0],
y2 = p[1],
dx2 = x2 - x0,
dy2 = y2 - y0,
dz = dy * dx2 - dx * dy2;
if (dz * dz / d2 > δ2 // perpendicular projected distance
|| Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 // midpoint close to an end
|| abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 // midpoint close to an end
|| a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
stream.point(x2, y2);
Expand Down
2 changes: 1 addition & 1 deletion src/geo/spherical.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ function d3_geo_spherical(cartesian) {
}

function d3_geo_sphericalEqual(a, b) {
return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
}
2 changes: 1 addition & 1 deletion src/geom/quadtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ d3.geom.quadtree = function(points, x1, y1, x2, y2) {
// point we are adding, we leave the point associated with the
// internal node while adding the new point to a child node. This
// avoids infinite recursion.
if ((Math.abs(nx - x) + Math.abs(ny - y)) < .01) {
if ((abs(nx - x) + abs(ny - y)) < .01) {
insertChild(n, d, x, y, x1, y1, x2, y2);
} else {
var nPoint = n.point;
Expand Down
8 changes: 4 additions & 4 deletions src/geom/voronoi/beach.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function d3_geom_voronoiRemoveBeach(beach) {

var lArc = previous;
while (lArc.circle
&& Math.abs(x - lArc.circle[0]) < ε
&& Math.abs(y - lArc.circle.cy) < ε) {
&& abs(x - lArc.circle[0]) < ε
&& abs(y - lArc.circle.cy) < ε) {
previous = lArc.P;
disappearing.unshift(lArc);
d3_geom_voronoiDetachBeach(lArc);
Expand All @@ -44,8 +44,8 @@ function d3_geom_voronoiRemoveBeach(beach) {

var rArc = next;
while (rArc.circle
&& Math.abs(x - rArc.circle[0]) < ε
&& Math.abs(y - rArc.circle.cy) < ε) {
&& abs(x - rArc.circle[0]) < ε
&& abs(y - rArc.circle.cy) < ε) {
next = rArc.N;
disappearing.push(rArc);
d3_geom_voronoiDetachBeach(rArc);
Expand Down
18 changes: 9 additions & 9 deletions src/geom/voronoi/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ function d3_geom_voronoiCloseCells(extent) {
iRight = (iLeft + 1) % nHalfEdges;
end = halfEdges[iLeft].end();
start = halfEdges[iRight].start();
if (Math.abs(end[0] - start[0]) > ε || Math.abs(end[1] - start[1]) > ε) {
if (abs(end[0] - start[0]) > ε || abs(end[1] - start[1]) > ε) {
va = end;
if (Math.abs(end[0] - x0) < ε && y1 - end[1] > ε) {
vb = [x0, Math.abs(start[0] - x0) < ε ? start[1] : y1];
} else if (Math.abs(end[1] - y1) < ε && x1 - end[0] > ε) {
vb = [Math.abs(start[1] - y1) < ε ? start[0] : x1, y1];
} else if (Math.abs(end[0] - x1) < ε && end[1] - y0 > ε) {
vb = [x1, Math.abs(start[0] - x1) < ε ? start[1] : y0];
} else if (Math.abs(end[1] - y0) < ε && end[0] - x0 > ε) {
vb = [Math.abs(start[1] - y0) < ε ? start[0] : x0, y0];
if (abs(end[0] - x0) < ε && y1 - end[1] > ε) {
vb = [x0, abs(start[0] - x0) < ε ? start[1] : y1];
} else if (abs(end[1] - y1) < ε && x1 - end[0] > ε) {
vb = [abs(start[1] - y1) < ε ? start[0] : x1, y1];
} else if (abs(end[0] - x1) < ε && end[1] - y0 > ε) {
vb = [x1, abs(start[0] - x1) < ε ? start[1] : y0];
} else if (abs(end[1] - y0) < ε && end[0] - x0 > ε) {
vb = [abs(start[1] - y0) < ε ? start[0] : x0, y0];
}
edge = d3_geom_voronoiCreateBorderEdge(cell.site, va, vb);
halfEdges.splice(iLeft + 1, 0, new d3_geom_voronoiHalfEdge(edge, cell.site, null));
Expand Down
2 changes: 1 addition & 1 deletion src/geom/voronoi/clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function d3_geom_voronoiClipEdges(extent) {
e = edges[i];
if (!d3_geom_voronoiConnectEdge(e, extent)
|| !d3_geom_voronoiClipEdge(e, extent)
|| (Math.abs(e.a[0] - e.b[0]) < ε && Math.abs(e.a[1] - e.b[1]) < ε)) {
|| (abs(e.a[0] - e.b[0]) < ε && abs(e.a[1] - e.b[1]) < ε)) {
e.a = e.b = null;
edges.splice(i, 1);
}
Expand Down
1 change: 1 addition & 0 deletions src/math/abs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var abs = Math.abs;
2 changes: 2 additions & 0 deletions src/math/trigonometry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "abs";

var π = Math.PI,
τ = 2 * π,
halfπ = π / 2,
Expand Down
2 changes: 1 addition & 1 deletion src/svg/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,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) < ε) {
if (abs(d) < ε) {
m[i] = m[i + 1] = 0;
} else {
// 4. Let ak = mk / dk and bk = m{k + 1} / dk.
Expand Down
5 changes: 3 additions & 2 deletions src/time/format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "../arrays/map";
import "../format/requote";
import "../math/abs";
import "day";
import "format-localized";
import "time";
Expand Down Expand Up @@ -309,8 +310,8 @@ var d3_time_amPmLookup = d3.map({
function d3_time_zone(d) {
var z = d.getTimezoneOffset(),
zs = z > 0 ? "-" : "+",
zh = ~~(Math.abs(z) / 60),
zm = Math.abs(z) % 60;
zh = ~~(abs(z) / 60),
zm = abs(z) % 60;
return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
}

Expand Down

0 comments on commit 7ba007f

Please sign in to comment.