-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inline code from d3-geo-projection (closes #23)
- Loading branch information
Showing
11 changed files
with
160 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,64 @@ | ||
export var epsilon = 1e-6; | ||
export var epsilon2 = 1e-12; | ||
export var pi = Math.PI; | ||
export var halfPi = pi / 2; | ||
export var quarterPi = pi / 4; | ||
export var tau = pi * 2; | ||
|
||
export var degrees = 180 / pi; | ||
export var radians = pi / 180; | ||
|
||
export var abs = Math.abs; | ||
export var atan = Math.atan; | ||
export var atan2 = Math.atan2; | ||
export var cos = Math.cos; | ||
export var ceil = Math.ceil; | ||
export var cos = Math.cos; | ||
export var exp = Math.exp; | ||
export var floor = Math.floor; | ||
export var log = Math.log; | ||
export var max = Math.max; | ||
export var min = Math.min; | ||
export var pow = Math.pow; | ||
export var sin = Math.sin; | ||
export var round = Math.round; | ||
export var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; }; | ||
export var sqrt = Math.sqrt; | ||
export var sin = Math.sin; | ||
export var tan = Math.tan; | ||
|
||
export function acos(x) { | ||
return x > 1 ? 0 : x < -1 ? pi : Math.acos(x); | ||
export var epsilon = 1e-6; | ||
export var epsilon2 = 1e-12; | ||
export var pi = Math.PI; | ||
export var halfPi = pi / 2; | ||
export var quarterPi = pi / 4; | ||
export var sqrt1_2 = Math.SQRT1_2; | ||
export var sqrt2 = sqrt(2); | ||
export var sqrtPi = sqrt(pi); | ||
export var tau = pi * 2; | ||
export var degrees = 180 / pi; | ||
export var radians = pi / 180; | ||
|
||
export function sinci(x) { | ||
return x ? x / Math.sin(x) : 1; | ||
} | ||
|
||
export function asin(x) { | ||
return x > 1 ? halfPi : x < -1 ? -halfPi : Math.asin(x); | ||
} | ||
|
||
export function haversin(x) { | ||
return (x = sin(x / 2)) * x; | ||
export function acos(x) { | ||
return x > 1 ? 0 : x < -1 ? pi : Math.acos(x); | ||
} | ||
|
||
export function sqrt(x) { | ||
return x > 0 ? Math.sqrt(x) : 0; | ||
} | ||
|
||
export function tanh(x) { | ||
x = exp(2 * x); | ||
return (x - 1) / (x + 1); | ||
} | ||
|
||
export function sinh(x) { | ||
return (exp(x) - exp(-x)) / 2; | ||
} | ||
|
||
export function cosh(x) { | ||
return (exp(x) + exp(-x)) / 2; | ||
} | ||
|
||
export function arsinh(x) { | ||
return log(x + sqrt(x * x + 1)); | ||
} | ||
|
||
export function arcosh(x) { | ||
return log(x + sqrt(x * x - 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {atan, degrees, sqrt1_2} from "../math"; | ||
|
||
var phi1 = atan(sqrt1_2) * degrees; | ||
|
||
var cube = [ | ||
[0, phi1], [90, phi1], [180, phi1], [-90, phi1], | ||
[0, -phi1], [90, -phi1], [180, -phi1], [-90, -phi1] | ||
]; | ||
|
||
export default [ | ||
[0, 3, 2, 1], // N | ||
[0, 1, 5, 4], | ||
[1, 2, 6, 5], | ||
[2, 3, 7, 6], | ||
[3, 0, 4, 7], | ||
[4, 5, 6, 7] // S | ||
].map(function(face) { | ||
return face.map(function(i) { | ||
return cube[i]; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {atan2, cos, sin, sqrt} from "../math"; | ||
|
||
// Note: 6-element arrays are used to denote the 3x3 affine transform matrix: | ||
// [a, b, c, | ||
// d, e, f, | ||
// 0, 0, 1] - this redundant row is left out. | ||
|
||
// Transform matrix for [a0, a1] -> [b0, b1]. | ||
export default function(a, b) { | ||
var u = subtract(a[1], a[0]), | ||
v = subtract(b[1], b[0]), | ||
phi = angle(u, v), | ||
s = length(u) / length(v); | ||
|
||
return multiply([ | ||
1, 0, a[0][0], | ||
0, 1, a[0][1] | ||
], multiply([ | ||
s, 0, 0, | ||
0, s, 0 | ||
], multiply([ | ||
cos(phi), sin(phi), 0, | ||
-sin(phi), cos(phi), 0 | ||
], [ | ||
1, 0, -b[0][0], | ||
0, 1, -b[0][1] | ||
]))); | ||
} | ||
|
||
// Inverts a transform matrix. | ||
export function inverse(m) { | ||
var k = 1 / (m[0] * m[4] - m[1] * m[3]); | ||
return [ | ||
k * m[4], -k * m[1], k * (m[1] * m[5] - m[2] * m[4]), | ||
-k * m[3], k * m[0], k * (m[2] * m[3] - m[0] * m[5]) | ||
]; | ||
} | ||
|
||
// Multiplies two 3x2 matrices. | ||
export function multiply(a, b) { | ||
return [ | ||
a[0] * b[0] + a[1] * b[3], | ||
a[0] * b[1] + a[1] * b[4], | ||
a[0] * b[2] + a[1] * b[5] + a[2], | ||
a[3] * b[0] + a[4] * b[3], | ||
a[3] * b[1] + a[4] * b[4], | ||
a[3] * b[2] + a[4] * b[5] + a[5] | ||
]; | ||
} | ||
|
||
// Subtracts 2D vectors. | ||
function subtract(a, b) { | ||
return [a[0] - b[0], a[1] - b[1]]; | ||
} | ||
|
||
// Magnitude of a 2D vector. | ||
function length(v) { | ||
return sqrt(v[0] * v[0] + v[1] * v[1]); | ||
} | ||
|
||
// Angle between two 2D vectors. | ||
function angle(a, b) { | ||
return atan2(a[0] * b[1] - a[1] * b[0], a[0] * b[0] + a[1] * b[1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// TODO generate on-the-fly to avoid external modification. | ||
var octahedron = [ | ||
[0, 90], | ||
[-90, 0], [0, 0], [90, 0], [180, 0], | ||
[0, -90] | ||
]; | ||
|
||
export default [ | ||
[0, 2, 1], | ||
[0, 3, 2], | ||
[5, 1, 2], | ||
[5, 2, 3], | ||
[0, 1, 4], | ||
[0, 4, 3], | ||
[5, 4, 1], | ||
[5, 3, 4] | ||
].map(function(face) { | ||
return face.map(function(i) { | ||
return octahedron[i]; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters