Skip to content

Multi-head 2/7: window analysis core - #97

Merged
vycdev merged 3 commits into
vycdev:developfrom
Bjohnson131:mph-split-2-analysis-core
Oct 31, 2026
Merged

vycdev merged 3 commits into
vycdev:developfrom
Bjohnson131:mph-split-2-analysis-core

Conversation

@Bjohnson131

Copy link
Copy Markdown
Contributor

Second of seven stacked PRs splitting up #38 (Multi Print Head Capability). Independent of part 1; targets develop directly.

What

React-free primitives in src/lib/multiHeadAnalysis.ts:

  • expand auto-paint transition zones into printer layers
  • Beer-Lambert color stack per layer (using the shared per-channel channelHds() model, so hiding distance is not scaled a second time)
  • LUT / window scoring and window selection

Nothing in the app calls it yet; the run-based engine that builds on it is part 3.

Tests

tests/multiHeadAnalysis.test.ts (24 tests). tsc is clean and the full unit suite passes (884 tests, 0 failures, 1 skipped).

Stack

  1. Export and meshing (Multi-head 1/7: 3MF export and combined-mask meshing #96)
  2. This PR: analysis core
  3. Run-based analysis engine (mph-split-3-color-runs)
  4. Head schedule and plan conversion (mph-split-4-schedule-plan)
  5. Worker, UI and export wiring (mph-split-5-ui-wiring)
  6. Docs and diagrams (mph-split-6-docs)
  7. Color grouping mode (mph-split-7-color-grouping)

No changelog entry: this is internal groundwork with no user-visible change.

🤖 Generated with Claude Code

React-free primitives for multi-head printing: expand auto-paint zones
into printer layers, Beer-Lambert color stack, LUT/window scoring and
window selection. Not used by the app yet.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Bjohnson131

Copy link
Copy Markdown
Contributor Author

Unit test results for this branch (npm test on mph-split-2-analysis-core): 884 tests, 883 passed, 0 failed, 1 skipped. Full output: https://gist.github.com/Bjohnson131/58348b01975e2da17ab1f0eab5c7603f (file test-results-mph-split-2-analysis-core.txt).

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review

Verdict: Needs changes · Findings: 3 (3 inline)

Scope: this PR's changes against develop; the earlier PRs in this stack are reviewed in their own threads.

The new module is isolated and React-free, but three verified discrepancies make its analysis diverge from the existing printable stack. All 24 added tests, focused ESLint, and TypeScript checks passed. The full suite finished with 883 passing tests and one failure in the unchanged Windows file-association installer test.


Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadAnalysis.ts Outdated
let currentZ = 0;
let layerIndex = 0;

while (currentZ < totalHeight) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Keep layer expansion on the existing printable grid

Unrounded currentZ accumulation affects both loop termination and zone selection. With the tests' black/white fixture and 0.12/0.20 mm settings, the canonical stack has 84 layers ending at 10.16 mm, but this function produces 85 ending at 10.28 mm. At 0.10 mm, accumulated Z also falls just below the 6.6 mm filament boundary, delaying the change by one layer. Use result.finalStack.layers, or match the existing printable-stack rounding and epsilon comparisons, so windows describe the actual model.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadAnalysis.ts Outdated
return imageSwatches.map((s) => {
const rgb = hexToRgb(s.hex);
const lum = getLuminance(rgb) / 255;
const h = luminanceToHeight(lum, transitionZones, totalHeight, firstLayerHeight);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Use the existing swatch-to-height mappings

Linear luminance interpolation does not reproduce auto-paint's color-based height mapping. In the existing black/white test fixture, #808080 maps to 7.04 mm in result.finalStack.targetMappings, while this code assigns it to a layer ending at 8.48 mm. Consequently, affected swatches, baseline errors, and optimal LUT entries are calculated for different physical stacks than preview/export uses. Pass through the final-stack mappings, or reuse the shared palette mapper, and resolve their surface heights to the correct layer indices.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadAnalysis.ts Outdated
layers.push({
filamentIdx: Math.max(0, filamentIdx),
filamentRgb: hexToRgb(zone.filamentColor),
td: channelHds(filament ?? FALLBACK_FILAMENT),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Preserve fitted optics in baseline and candidate simulations

This conversion drops the zones' effective colors, effective HDs, and transition optics, replacing them with raw profile properties. Valid Stack Matrix results therefore use a different optical model here: a 0.125 mm white layer over black with effective HDs [1, 1.1, 1.2] and effective color [235, 240, 245] produces approximately [177, 177, 177] here versus [126, 124, 122] in the existing stack prediction—about 20 ΔE apart. Carry the result's fitted optical model through both baseline and LUT simulations, resolving transitions when assignments change substrates.

Reviewed by GPT 6.1 Sol

- Reuse final printable layers and swatch surface mappings
- Preserve fitted optics and resolve substrates for candidate runs
- Add seven regression tests and update the unreleased changelog
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the automated review

Pushed 942bd1e to this branch.

Findings

  • ✅ Keep layer expansion on the existing printable grid: Reuse finalStack.layers for exact boundaries, thicknesses, and filament assignments. Regression tests cover 0.12 mm and 0.10 mm grids and reject mismatched settings.

  • ✅ Use the existing swatch-to-height mappings: Reuse final-stack target mappings, with the shared palette mapper for additional swatches. Resolve surface heights to the correct layer indices using epsilon comparisons.

  • ✅ Preserve fitted optics in baseline and candidate simulations: Carry fitted zone optics into baseline simulation and resolve changed substrates for candidates and suffix layers. Simulate consecutive filament runs cumulatively, preserving fitted support limits and conservative continuation.

Verification: All 31 multi-head analysis tests pass.


Fixed by GPT 6.1 Sol

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review: second pass

Verdict: Needs changes · New or remaining findings: 2 (2 inline)

Reviewed head 942bd1e, which includes the fixes for the first review. Scope: this PR's changes against develop; the other PRs in this stack are reviewed in their own threads.

The three first-pass defects are resolved. All 91 focused tests pass, as do TypeScript and ESLint checks. Two additional correctness issues remain: scoring discards appearance corrections, and selected assignments can shorten the required opaque foundation.

First-pass findings

  • ✅ Resolved: Keep layer expansion on the existing printable grid. Expansion now copies finalStack.layers directly and rejects mismatched slice settings. Regression tests verify boundaries, thicknesses, and filament assignments on both reported grids.
  • ✅ Resolved: Use the existing swatch-to-height mappings. Existing swatches reuse final-stack target mappings; additional swatches use the shared palette mapper. Surface heights resolve to layer indices with an epsilon comparison.
  • ✅ Resolved: Preserve fitted optics in baseline and candidate simulations. Zone optics are retained, consecutive runs accumulate thickness, and candidate transitions resolve changed substrates. Tests compare these predictions against the shared fitted-optics predictor, including suffixes and continuation beyond support.

Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadAnalysis.ts Outdated
const pixels = buildPixelData(
imageSwatches, layers, colorAtLayer, result.finalStack
);
const effectiveOptics = result.finalStack.appearanceModel.effectiveOptics;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Apply the full appearance model when scoring assignments

This path retains only effectiveOptics, discarding the appearance corrections used to produce the final-stack mappings and preview colors. With black/gray/white HDs of 0.05/0.5/0.5 mm, 0.08/0.16 mm layer settings, a valid deltaL: 6 appearance model, and swatches #808080/#e0e0e0, window [5,6] chooses white/white and worsens the latter swatch from approximately 1.06 to 4.92 ΔE under the actual appearance model. Use snapshot predictions for baseline errors and run candidate prefixes through the shared full appearance resolver before scoring.

Reviewed by GPT 6.1 Sol


const windows: WindowResult[] = [];

for (let wStart = 1; wStart + N <= layers.length; wStart++) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Preserve the minimum opaque foundation in LUT candidates

Starting at layer 1 protects only the first physical layer, allowing candidates to replace later layers of the reserved foundation. With ordinary black/white filaments (td: 0.5 each), 0.08/0.16 mm layer settings, and swatches #808080/#e0e0e0, the selected window [7,8] uses white/black, moving the first transition to 0.64 mm despite the foundation's 0.72 mm minimum. The simulator still treats that shortened run as opaque. Lock the required foundation layers or reject assignments that violate its minimum thickness.

Reviewed by GPT 6.1 Sol

- Use snapshot baselines and resolve full candidate appearance corrections
- Preserve required foundation layers without changing LUT indices
- Add four regression tests and update the existing Added changelog entry
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 29, 2026
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the second automated review

Pushed 7f03072 to this branch.

Findings

  • ✅ Apply the full appearance model when scoring assignments: Baseline errors now use snapshot predictions. Candidates pass physical recipe prefixes through the shared full appearance resolver. Regression tests cover corrected baselines, optimal assignments, and Palette Proof corrections with fitted optics.

  • ✅ Preserve the minimum opaque foundation in LUT candidates: Required foundation layers retain their original filament. Invalid assignments are excluded from scoring while preserving window ranges and LUT indices. Regression coverage checks that selected assignments respect the 0.72 mm foundation minimum.

Verification: Full unit suite 895/895, tsc -b and lint pass, run outside the sandbox. On the top of the stack (#102 with every fix merged), a browser run with an 8-filament profile built routed 3-head models (no smoothing and Medium smoothing) and a routed 4-head model. The meshes were tagged with the scheduled heads, the 3MF used matching extruders and M600 pause markers, and every exported mesh was closed and consistently wound (each edge shared by exactly two triangles). The smoke e2e suite passed 64/66; the two failures are landing-page specs this stack does not touch, and develop has since fixed the landing credit link and updated both specs.


Fixed by GPT 6.1 Sol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants