Skip to content

Commit

Permalink
flatten src
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Jun 10, 2024
1 parent 998a755 commit 799c565
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 67 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
{
"name": "Philippe Rivière",
"url": "https://visionscarto.net"
},
{
"name": "Enrico Spinielli",
"url": "https://enrico.spinielli.net/"
},
{
"name": "Ronnie Bathoorn",
"url": "https://github.com/bathoorn"
}
],
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions src/polyhedral/butterfly.js → src/butterfly.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {geoCentroid as centroid, geoGnomonic as gnomonic} from "d3-geo";
import {pi} from "../math.js";
import polyhedral from "./index.js";
import octahedron from "./octahedron.js";
import {pi} from "./math.js";
import polyhedral from "./polyhedral/index.js";
import octahedron from "./polyhedral/octahedron.js";

export default function(faceProjection = ((face) => {
const c = centroid({type: "MultiPoint", coordinates: face});
Expand Down
37 changes: 36 additions & 1 deletion src/collignon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// code duplicated from d3-geo-projection
import {geoCentroid as centroid, geoProjection as projection} from "d3-geo";
import {asin, pi, sin, sqrt, sqrtPi} from "./math.js";
import polyhedral from "./polyhedral/index.js";
import octahedron from "./polyhedral/octahedron.js";

// code duplicated from d3-geo-projection
export function collignonRaw(lambda, phi) {
const alpha = sqrt(1 - sin(phi));
return [(2 / sqrtPi) * lambda * alpha, sqrtPi * (1 - alpha)];
Expand All @@ -10,3 +13,35 @@ collignonRaw.invert = function(x, y) {
const lambda = (y / sqrtPi - 1);
return [lambda ? x * sqrt(pi) / lambda / 2 : 0, asin(1 - lambda ** 2)];
};


const kx = 2 / sqrt(3);

function collignonK(a, b) {
const p = collignonRaw(a, b);
return [p[0] * kx, p[1]];
}

collignonK.invert = (x,y) => collignonRaw.invert(x / kx, y);

export default function(faceProjection = (face) => {
const 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]);
}) {
const faces = octahedron.map((face) => ({face, project: faceProjection(face)}));

[-1, 0, 0, 1, 0, 1, 4, 5].forEach((d, i) => {
const node = faces[d];
node && (node.children || (node.children = [])).push(faces[i]);
});

return polyhedral(
faces[0],
(lambda, phi) => 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]);
}
16 changes: 15 additions & 1 deletion src/cubic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@
*
*/
import voronoi from "./polyhedral/voronoi.js";
import { default as cube } from "./polyhedral/cube.js";
import {atan, degrees, sqrt1_2} from "./math.js";

const phi1 = atan(sqrt1_2) * degrees;
const cube1 = [
[0, phi1], [90, phi1], [180, phi1], [-90, phi1],
[0, -phi1], [90, -phi1], [180, -phi1], [-90, -phi1]
];
const cube = [
[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((face) => face.map((i) => cube1[i]));

export default function() {
const polygons = {
Expand Down
4 changes: 2 additions & 2 deletions src/polyhedral/dodecahedral.js → src/dodecahedral.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {acos, asin, degrees, sqrt} from "../math.js";
import voronoi from "./voronoi.js";
import {acos, asin, degrees, sqrt} from "./math.js";
import voronoi from "./polyhedral/voronoi.js";

export default function() {
const A0 = asin(1/sqrt(3)) * degrees;
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export {default as geoClipPolygon} from "./clip/polygon.js";
export {default as geoIntersectArc} from "./intersect.js";
export {default as geoPolyhedral} from "./polyhedral/index.js";
export {default as geoPolyhedralButterfly} from "./polyhedral/butterfly.js";
export {default as geoPolyhedralCollignon} from "./polyhedral/collignon.js";
export {default as geoPolyhedralWaterman} from "./polyhedral/waterman.js";
export {default as geoPolyhedralButterfly} from "./butterfly.js";
export {default as geoPolyhedralCollignon} from "./collignon.js";
export {default as geoPolyhedralWaterman} from "./waterman.js";
export {default as geoPolyhedralVoronoi} from "./polyhedral/voronoi.js";
export {default as geoDodecahedral} from "./polyhedral/dodecahedral.js";
export {default as geoDodecahedral} from "./dodecahedral.js";
export {default as geoCox, coxRaw as geoCoxRaw} from "./cox.js";
export {default as geoTetrahedralLee, leeRaw as geoLeeRaw} from "./tetrahedralLee.js";
export {default as geoGrayFullerRaw} from "./grayfuller.js";
Expand Down
36 changes: 0 additions & 36 deletions src/polyhedral/collignon.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/polyhedral/cube.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/polyhedral/waterman.js → src/waterman.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {geoCentroid as centroid, geoGnomonic as gnomonic} from "d3-geo";
import {asin, atan2, cos, degrees, max, min, pi, radians, sin} from "../math.js";
import polyhedral from "./index.js";
import octahedron from "./octahedron.js";
import {asin, atan2, cos, degrees, max, min, pi, radians, sin} from "./math.js";
import polyhedral from "./polyhedral/index.js";
import octahedron from "./polyhedral/octahedron.js";

export default function(faceProjection = ((face) => {
const c = face.length === 6 ? centroid({type: "MultiPoint", coordinates: face}) : face[0];
Expand Down

0 comments on commit 799c565

Please sign in to comment.