Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Extract math and hyperbolic functions.
Browse files Browse the repository at this point in the history
Also, add missing geo/projection/index.js file.
  • Loading branch information
jasondavies committed Mar 13, 2013
1 parent c6fef9f commit c88daab
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 48 deletions.
1 change: 1 addition & 0 deletions geo/projection/august.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "projection";
import "hyperbolic";

function august(λ, φ) {
var tanφ = Math.tan(φ / 2),
Expand Down
3 changes: 2 additions & 1 deletion geo/projection/elliptic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "projection";
import "math";
import "hyperbolic";

// Returns [sn, cn, dn](u + iv|m).
function ellipticJi(u, v, m) {
Expand Down
22 changes: 22 additions & 0 deletions geo/projection/hyperbolic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import "math";

function tanh(x) {
x = Math.exp(2 * x);
return (x - 1) / (x + 1);
}

function sinh(x) {
return .5 * (Math.exp(x) - Math.exp(-x));
}

function cosh(x) {
return .5 * (Math.exp(x) + Math.exp(-x));
}

function arsinh(x) {
return Math.log(x + asqrt(x * x + 1));
}

function arcosh(x) {
return Math.log(x + asqrt(x * x - 1));
}
69 changes: 69 additions & 0 deletions geo/projection/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import "start";
import "quincuncial";
import "interrupt";
import "aitoff";
import "guyou";
import "mollweide";
import "sinusoidal";
import "sinu-mollweide";
import "armadillo";
import "august";
import "baker";
import "berghaus";
import "boggs";
import "bonne";
import "bromley";
import "collignon";
import "conic-conformal";
import "conic-equal-area";
import "conic-equidistant";
import "craig";
import "craster";
import "cylindrical-equal-area";
import "eckert1";
import "eckert2";
import "eckert3";
import "eckert4";
import "eckert5";
import "eckert6";
import "eisenlohr";
import "fahey";
import "gringorten";
import "hammer-retroazimuthal";
import "hammer";
import "hatano";
import "healpix";
import "hill";
import "homolosine";
import "kavrayskiy7";
import "lagrange";
import "larrivee";
import "laskowski";
import "littrow";
import "loximuthal";
import "miller";
import "modified-stereographic";
import "mt-flat-polar-parabolic";
import "mt-flat-polar-quartic";
import "mt-flat-polar-sinusoidal";
import "natural-earth";
import "nell-hammer";
import "peirce-quincuncial";
import "polyconic";
import "rectangular-polyconic";
import "robinson";
import "satellite";
import "times";
import "transverse-mercator";
import "two-point-azimuthal";
import "two-point-equidistant";
import "van-der-grinten";
import "van-der-grinten2";
import "van-der-grinten3";
import "van-der-grinten4";
import "wagner4";
import "wagner6";
import "wagner7";
import "wiechel";
import "winkel3";
import "end";
26 changes: 26 additions & 0 deletions geo/projection/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var ε = 1e-6,
ε2 = ε * ε,
π = Math.PI,
sqrtπ = Math.sqrt(π),
radians = π / 180,
degrees = 180 / π;

function sinci(x) {
return x ? x / Math.sin(x) : 1;
}

function sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0;
}

function asin(x) {
return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
}

function acos(x) {
return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
}

function asqrt(x) {
return x > 0 ? Math.sqrt(x) : 0;
}
48 changes: 1 addition & 47 deletions geo/projection/projection.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
var ε = 1e-6,
ε2 = ε * ε,
π = Math.PI,
sqrtπ = Math.sqrt(π),
radians = π / 180,
degrees = 180 / π;
import "math";

var projection = d3.geo.projection,
projectionMutator = d3.geo.projectionMutator;

function sinci(x) {
return x ? x / Math.sin(x) : 1;
}

function sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0;
}

function asqrt(x) {
return x > 0 ? Math.sqrt(x) : 0;
}

function asin(x) {
return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
}

function acos(x) {
return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
}

function tanh(x) {
x = Math.exp(2 * x);
return (x - 1) / (x + 1);
}

function sinh(x) {
return .5 * (Math.exp(x) - Math.exp(-x));
}

function cosh(x) {
return .5 * (Math.exp(x) + Math.exp(-x));
}

function arsinh(x) {
return Math.log(x + asqrt(x * x + 1));
}

function arcosh(x) {
return Math.log(x + asqrt(x * x - 1));
}
1 change: 1 addition & 0 deletions geo/projection/transverse-mercator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "projection";
import "hyperbolic";

function transverseMercator(λ, φ) {
var B = Math.cos(φ) * Math.sin(λ);
Expand Down

0 comments on commit c88daab

Please sign in to comment.