Skip to content

Commit 0fc0e95

Browse files
committed
Various improvements
1 parent a58c9e6 commit 0fc0e95

6 files changed

Lines changed: 332 additions & 240 deletions

File tree

experiments/Pentagon_Lattice_Geometry/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,4 @@ <h1>Multi-Sheeted Pentagon Lattice Lab</h1>
466466
</div>
467467
</div>
468468
</body>
469-
</html>
469+
</html>

experiments/Pentagon_Lattice_Geometry/main.js

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ const els = {
124124
caGen: $('caGen'),
125125
caPop: $('caPop'),
126126
caBySheet: $('caBySheet'),
127-
// Path tool
128-
pathMode: $('pathMode'),
129-
pathSetStart: $('pathSetStart'),
130-
pathSetEnd: $('pathSetEnd'),
131-
pathClear: $('pathClear'),
132-
pathShowAll: $('pathShowAll'),
133-
pathStart: $('pathStart'),
134-
pathEnd: $('pathEnd'),
135-
pathHops: $('pathHops'),
136-
pathCount: $('pathCount'),
137-
pathSheet: $('pathSheet'),
138-
pathEuclid: $('pathEuclid'),
127+
// Path tool
128+
pathMode: $('pathMode'),
129+
pathSetStart: $('pathSetStart'),
130+
pathSetEnd: $('pathSetEnd'),
131+
pathClear: $('pathClear'),
132+
pathShowAll: $('pathShowAll'),
133+
pathStart: $('pathStart'),
134+
pathEnd: $('pathEnd'),
135+
pathHops: $('pathHops'),
136+
pathCount: $('pathCount'),
137+
pathSheet: $('pathSheet'),
138+
pathEuclid: $('pathEuclid'),
139139
// value displays
140140
alphaSelVal: $('alphaSelVal'),
141141
alphaOtherVal: $('alphaOtherVal'),
@@ -191,8 +191,7 @@ function getPolyConfig() {
191191
function updatePolyTypeUI() {
192192
const type = els.polyType.value;
193193
els.customNLabel.style.display = type === 'custom' ? '' : 'none';
194-
els.sierpinskiDepthLabel.style.display =
195-
type === 'sierpinski' || type === 'vicsek' ? '' : 'none';
194+
els.sierpinskiDepthLabel.style.display = type === 'sierpinski' || type === 'vicsek' ? '' : 'none';
196195
if (els.pinwheelOptionsLabel) {
197196
els.pinwheelOptionsLabel.style.display = type === 'pinwheel' ? '' : 'none';
198197
}
@@ -297,7 +296,7 @@ function rebuild() {
297296
appendWalkStep(els.walk, lattice.tiles[currentTileIdx], null, 'origin');
298297
initCA();
299298
updatePolyTypeUI();
300-
clearPath();
299+
clearPath();
301300
}
302301

303302
function initCA() {
@@ -326,44 +325,44 @@ function updateCAStats() {
326325
}
327326
}
328327
function recomputePath() {
329-
if (pathStartIdx === null || pathEndIdx === null) {
330-
view.setPath(null);
331-
updatePathStats(null);
332-
return;
333-
}
334-
const result = computePath(lattice, pathStartIdx, pathEndIdx);
335-
view.setPath(result);
336-
updatePathStats(result);
328+
if (pathStartIdx === null || pathEndIdx === null) {
329+
view.setPath(null);
330+
updatePathStats(null);
331+
return;
332+
}
333+
const result = computePath(lattice, pathStartIdx, pathEndIdx);
334+
view.setPath(result);
335+
updatePathStats(result);
337336
}
338337
function updatePathStats(result) {
339-
els.pathStart.textContent = pathStartIdx === null ? '—' : `#${pathStartIdx}`;
340-
els.pathEnd.textContent = pathEndIdx === null ? '—' : `#${pathEndIdx}`;
341-
if (!result) {
342-
els.pathHops.textContent = '—';
343-
els.pathCount.textContent = '—';
344-
els.pathSheet.textContent = '—';
345-
els.pathEuclid.textContent = '—';
346-
return;
347-
}
348-
if (!result.reachable) {
349-
els.pathHops.textContent = '∞ (unreachable)';
350-
els.pathCount.textContent = '0';
351-
els.pathSheet.textContent = '—';
352-
els.pathEuclid.textContent = result.euclid != null ? result.euclid.toFixed(4) : '—';
353-
return;
354-
}
355-
els.pathHops.textContent = String(result.hops);
356-
els.pathCount.textContent =
357-
result.numPaths > 64 ? `${result.numPaths} (showing 64)` : String(result.numPaths);
358-
els.pathSheet.textContent = `+${result.sheetShift} (mod ${lattice.groupOrder})`;
359-
els.pathEuclid.textContent = result.euclid.toFixed(4);
338+
els.pathStart.textContent = pathStartIdx === null ? '—' : `#${pathStartIdx}`;
339+
els.pathEnd.textContent = pathEndIdx === null ? '—' : `#${pathEndIdx}`;
340+
if (!result) {
341+
els.pathHops.textContent = '—';
342+
els.pathCount.textContent = '—';
343+
els.pathSheet.textContent = '—';
344+
els.pathEuclid.textContent = '—';
345+
return;
346+
}
347+
if (!result.reachable) {
348+
els.pathHops.textContent = '∞ (unreachable)';
349+
els.pathCount.textContent = '0';
350+
els.pathSheet.textContent = '—';
351+
els.pathEuclid.textContent = result.euclid != null ? result.euclid.toFixed(4) : '—';
352+
return;
353+
}
354+
els.pathHops.textContent = String(result.hops);
355+
els.pathCount.textContent =
356+
result.numPaths > 64 ? `${result.numPaths} (showing 64)` : String(result.numPaths);
357+
els.pathSheet.textContent = `+${result.sheetShift} (mod ${lattice.groupOrder})`;
358+
els.pathEuclid.textContent = result.euclid.toFixed(4);
360359
}
361360
function clearPath() {
362-
pathStartIdx = null;
363-
pathEndIdx = null;
364-
pathPickNext = 'start';
365-
view.setPath(null);
366-
updatePathStats(null);
361+
pathStartIdx = null;
362+
pathEndIdx = null;
363+
pathPickNext = 'start';
364+
view.setPath(null);
365+
updatePathStats(null);
367366
}
368367

369368
function caTick(now) {
@@ -616,21 +615,20 @@ els.caClear.addEventListener('click', () => {
616615
});
617616
// ---- Path tool wiring ----
618617
els.pathSetStart.addEventListener('click', () => {
619-
pathStartIdx = currentTileIdx;
620-
recomputePath();
618+
pathStartIdx = currentTileIdx;
619+
recomputePath();
621620
});
622621
els.pathSetEnd.addEventListener('click', () => {
623-
pathEndIdx = currentTileIdx;
624-
recomputePath();
622+
pathEndIdx = currentTileIdx;
623+
recomputePath();
625624
});
626625
els.pathClear.addEventListener('click', clearPath);
627626
els.pathShowAll.addEventListener('change', (e) => {
628-
view.setOption('pathShowAll', e.target.checked);
627+
view.setOption('pathShowAll', e.target.checked);
629628
});
630629
// Initialize the render option to match the checkbox.
631630
view.setOption('pathShowAll', els.pathShowAll.checked);
632631

633-
634632
function ensureCAOverlayOn() {
635633
if (!els.caOverlay.checked) {
636634
els.caOverlay.checked = true;
@@ -675,21 +673,21 @@ window.addEventListener('mouseup', (e) => {
675673
const [sx, sy] = view.eventToCanvas(e);
676674
const idx = view.pickTile(sx, sy);
677675
if (idx !== null) {
678-
if (els.pathMode.checked) {
679-
// Path-pick mode: alternate start / end.
680-
if (pathPickNext === 'start') {
681-
pathStartIdx = idx;
682-
pathEndIdx = null;
683-
pathPickNext = 'end';
684-
} else {
685-
pathEndIdx = idx;
686-
pathPickNext = 'start';
687-
}
688-
currentTileIdx = idx;
689-
view.select(idx);
690-
renderTileInfo(els.tileInfo, lattice.tiles[idx], lattice);
691-
recomputePath();
692-
} else if (els.caPaintMode.checked && ca) {
676+
if (els.pathMode.checked) {
677+
// Path-pick mode: alternate start / end.
678+
if (pathPickNext === 'start') {
679+
pathStartIdx = idx;
680+
pathEndIdx = null;
681+
pathPickNext = 'end';
682+
} else {
683+
pathEndIdx = idx;
684+
pathPickNext = 'start';
685+
}
686+
currentTileIdx = idx;
687+
view.select(idx);
688+
renderTileInfo(els.tileInfo, lattice.tiles[idx], lattice);
689+
recomputePath();
690+
} else if (els.caPaintMode.checked && ca) {
693691
ca.toggleCell(idx);
694692
ensureCAOverlayOn();
695693
view.draw();
@@ -761,4 +759,4 @@ window.addEventListener('keydown', (e) => {
761759

762760
// initial build
763761
rebuild();
764-
initDocs();
762+
initDocs();

experiments/Pentagon_Lattice_Geometry/ngon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,4 @@ export function buildPinwheel({ radius = 0, a = 2, b = 1, c = 1, hypotenuseSheet
738738
isSierpinski: false,
739739
isPinwheel: true,
740740
};
741-
}
741+
}

0 commit comments

Comments
 (0)