-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathcollignon.js
43 lines (35 loc) · 1.26 KB
/
collignon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {geoCentroid as centroid, geoProjection as projection} from "d3-geo";
import {collignonRaw} from "../collignon.js";
import {pi, sqrt} from "../math.js";
import polyhedral from "./index.js";
import octahedron from "./octahedron.js";
var kx = 2 / sqrt(3);
function collignonK(a, b) {
var p = collignonRaw(a, b);
return [p[0] * kx, p[1]];
}
collignonK.invert = function(x,y) {
return collignonRaw.invert(x / kx, y);
};
export default function(faceProjection) {
faceProjection = faceProjection || function(face) {
var c = centroid({type: "MultiPoint", coordinates: face});
return projection(collignonK).translate([0, 0]).scale(1).rotate(c[1] > 0 ? [-c[0], 0] : [180 - c[0], 180]);
};
var faces = octahedron.map(function(face) {
return {face: face, project: faceProjection(face)};
});
[-1, 0, 0, 1, 0, 1, 4, 5].forEach(function(d, i) {
var node = faces[d];
node && (node.children || (node.children = [])).push(faces[i]);
});
return polyhedral(faces[0], function(lambda, phi) {
return faces[lambda < -pi / 2 ? phi < 0 ? 6 : 4
: lambda < 0 ? phi < 0 ? 2 : 0
: lambda < pi / 2 ? phi < 0 ? 3 : 1
: phi < 0 ? 7 : 5];
})
.angle(-30)
.scale(121.906)
.center([0, 48.5904]);
}