Refactored label120cell.js so that it works a bit better on the repl

feature-120-cell-layers
Mike Lynch 2023-10-18 11:22:13 +11:00
parent 88049ca891
commit 1f6c35c7b8
1 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,6 @@
//testbed for playing with stuff in node repl // code for generating the 120-cell labels
// has some overlap with permute - FIXME
const THREE =require('three'); const THREE =require('three');
@ -133,7 +134,7 @@ function dist2(n1, n2) {
return (n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2 + (n1.z - n2.z) ** 2 + (n1.w - n2.w) ** 2; return (n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2 + (n1.z - n2.z) ** 2 + (n1.w - n2.w) ** 2;
} }
function auto_detect_edges(nodes, neighbours, debug=false) { export function auto_detect_edges(nodes, neighbours, debug=false) {
const seen = {}; const seen = {};
const nnodes = nodes.length; const nnodes = nodes.length;
const links = []; const links = [];
@ -168,7 +169,7 @@ function auto_detect_edges(nodes, neighbours, debug=false) {
function make_120cell_vertices() { export function make_120cell_vertices() {
const phi = 0.5 * (1 + Math.sqrt(5)); const phi = 0.5 * (1 + Math.sqrt(5));
const r5 = Math.sqrt(5); const r5 = Math.sqrt(5);
const phi2 = phi * phi; const phi2 = phi * phi;
@ -230,7 +231,7 @@ function fingerprint(ids) {
function auto_120cell_faces(links) { export function auto_120cell_faces(links) {
const faces = []; const faces = [];
const seen = {}; const seen = {};
let id = 1; let id = 1;
@ -486,7 +487,7 @@ function colour_next_dodeca_maybe(nodes, links, faces, colours, dd, nextf, nextd
const nextvs = dodecahedron_vertices(nextdd); const nextvs = dodecahedron_vertices(nextdd);
// get the initial colour permutations from the existing labels; // get the initial colour permutations from the existing labels;
const p = []; const p = [];
for( i = 0; i < 5; i ++ ) { for( let i = 0; i < 5; i ++ ) {
p[i] = colours[nextvs[i]]; p[i] = colours[nextvs[i]];
} }
const nlabels = colour_dodecahedron_from_face(nextdd, p); const nlabels = colour_dodecahedron_from_face(nextdd, p);
@ -668,8 +669,9 @@ function arctic(nodes, links, faces, startf, startn, max) {
// this is the one that works
function arctic_two(nodes, links, faces, startf, startn) { export function label_120cell(nodes, links, faces, startf, startn) {
const pole = face_plus_to_dodecahedron(faces, startf, startn); const pole = face_plus_to_dodecahedron(faces, startf, startn);
const dds = [ pole ]; const dds = [ pole ];
@ -815,7 +817,6 @@ function make_120cell_cells(faces) {
for( const dd of dds ) { for( const dd of dds ) {
const fp = dd_fingerprint(dd); const fp = dd_fingerprint(dd);
if( ! (fp in seen) ) { if( ! (fp in seen) ) {
//console.log(`added dodeca ${fp}`);
const d = { const d = {
id: i, id: i,
faces: dd, faces: dd,
@ -927,6 +928,8 @@ function make_dodecahedron_vertices() {
} }
// const nodes = make_120cell_vertices(); // const nodes = make_120cell_vertices();
// const links = auto_detect_edges(nodes, 4); // const links = auto_detect_edges(nodes, 4);
// const faces = auto_120cell_faces(links); // const faces = auto_120cell_faces(links);