-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from d3/master
feat: New updated code
- Loading branch information
Showing
22 changed files
with
438 additions
and
240 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,16 @@ | ||
import {hammerRaw} from "../hammer"; | ||
import interrupt from "./index"; | ||
|
||
var lobes = [[ // northern hemisphere | ||
[[-180, 0], [-90, 90], [ 0, 0]], | ||
[[ 0, 0], [ 90, 90], [ 180, 0]] | ||
], [ // southern hemisphere | ||
[[-180, 0], [-90, -90], [ 0, 0]], | ||
[[ 0, 0], [ 90, -90], [180, 0]] | ||
]]; | ||
|
||
export default function() { | ||
return interrupt(hammerRaw(Infinity), lobes) | ||
.rotate([20, 0]) | ||
.scale(152.63); | ||
} |
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 {geoProjection as projection} from "d3-geo"; | ||
import {abs, cos, halfPi, pi, sign, sin, sqrt} from "./math"; | ||
import {solve} from "./newton.js"; | ||
|
||
// Based on Torben Jansen's implementation | ||
// https://beta.observablehq.com/@toja/nicolosi-globular-projection | ||
// https://beta.observablehq.com/@toja/nicolosi-globular-inverse | ||
|
||
export function nicolosiRaw(lambda, phi) { | ||
var sinPhi = sin(phi), | ||
q = cos(phi), | ||
s = sign(lambda); | ||
|
||
if (lambda === 0 || abs(phi) === halfPi) return [0, phi]; | ||
else if (phi === 0) return [lambda, 0]; | ||
else if (abs(lambda) === halfPi) return [lambda * q, halfPi * sinPhi]; | ||
|
||
var b = pi / (2 * lambda) - (2 * lambda) / pi, | ||
c = (2 * phi) / pi, | ||
d = (1 - c * c) / (sinPhi - c); | ||
|
||
var b2 = b * b, | ||
d2 = d * d, | ||
b2d2 = 1 + b2 / d2, | ||
d2b2 = 1 + d2 / b2; | ||
|
||
var M = ((b * sinPhi) / d - b / 2) / b2d2, | ||
N = ((d2 * sinPhi) / b2 + d / 2) / d2b2, | ||
m = M * M + (q * q) / b2d2, | ||
n = N * N - ((d2 * sinPhi * sinPhi) / b2 + d * sinPhi - 1) / d2b2; | ||
|
||
return [ | ||
halfPi * (M + sqrt(m) * s), | ||
halfPi * (N + sqrt(n < 0 ? 0 : n) * sign(-phi * b) * s) | ||
]; | ||
} | ||
|
||
nicolosiRaw.invert = function(x, y) { | ||
|
||
x /= halfPi; | ||
y /= halfPi; | ||
|
||
var x2 = x * x, | ||
y2 = y * y, | ||
x2y2 = x2 + y2, | ||
pi2 = pi * pi; | ||
|
||
return [ | ||
x ? (x2y2 -1 + sqrt((1 - x2y2) * (1 - x2y2) + 4 * x2)) / (2 * x) * halfPi : 0, | ||
solve(function(phi) { | ||
return ( | ||
x2y2 * (pi * sin(phi) - 2 * phi) * pi + | ||
4 * phi * phi * (y - sin(phi)) + | ||
2 * pi * phi - | ||
pi2 * y | ||
); | ||
}, 0) | ||
]; | ||
}; | ||
|
||
export default function() { | ||
return projection(nicolosiRaw) | ||
.scale(127.267); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var tape = require("tape"), | ||
d3 = require("../"); | ||
|
||
require("./inDelta"); | ||
|
||
tape("geoGilbert(point) returns the expected values", function(test) { | ||
var gilbert = d3.geoGilbert().scale(150); | ||
test.projectionEqual(gilbert, [ 0, 0], [480.0000000, 250.000000]); | ||
test.assert("fitExtent" in gilbert); | ||
test.inDelta(gilbert.fitExtent([[0,0],[10,10]], {type:"Sphere"}).scale(), 5, 1e-12); | ||
test.inDelta(gilbert.fitSize([10,10], {type:"Sphere"}).scale(), 5, 1e-12); | ||
test.inDelta(gilbert.fitWidth(10, {type:"Sphere"}).scale(), 5, 1e-12); | ||
test.inDelta(gilbert.fitHeight(10, {type:"Sphere"}).scale(), 5, 1e-12); | ||
test.end(); | ||
}); |
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,26 @@ | ||
var tape = require("tape"); | ||
|
||
tape.Test.prototype.inDelta = function(actual, expected, delta) { | ||
delta = delta || 1e-6; | ||
this._assert(inDelta(actual, expected, delta), { | ||
message: "should be in delta " + delta, | ||
operator: "inDelta", | ||
actual: actual, | ||
expected: expected | ||
}); | ||
}; | ||
|
||
function inDelta(actual, expected, delta) { | ||
return (Array.isArray(expected) ? inDeltaArray : inDeltaNumber)(actual, expected, delta); | ||
} | ||
|
||
function inDeltaArray(actual, expected, delta) { | ||
var n = expected.length, i = -1; | ||
if (actual.length !== n) return false; | ||
while (++i < n) if (!inDelta(actual[i], expected[i], delta)) return false; | ||
return true; | ||
} | ||
|
||
function inDeltaNumber(actual, expected, delta) { | ||
return actual >= expected - delta && actual <= expected + delta; | ||
} |
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