Skip to content

First color's height drifts by a layer when swatches are recomputed #164

Closed

Description

@vycdev

Summary

When the first-layer height isn't a multiple of the layer height, the first color's height can jump up or down by one layer whenever the swatch list is recomputed, even though the user didn't change it.

The first color's valid heights are max(layerHeight, firstLayer) + n × layerHeight. In src/hooks/useColorSlicing.ts, two effects disagree about that:

  1. The reconcile effect that runs when filtered changes snaps every height, including the first, to a plain multiple of layerHeight.
  2. The alignment effect then snaps the first color back onto the first-layer lattice, rounding from the already-moved value.

Running the two snaps in sequence on valid starting heights (same arithmetic as the hooks):

Layer / first layer Start After 1st recompute After 2nd After 3rd
0.08 / 0.20 0.28 0.36 0.44 0.44
0.08 / 0.20 0.52 0.60 0.68 0.76
0.20 / 0.30 0.70 0.50 0.50 0.50
0.10 / 0.25 0.35 0.25 0.25 0.25

Combinations where the first layer is a multiple of the layer height (for example 0.08 / 0.24 or 0.2 / 0.2) are not affected.

How to trigger it: set a 0.2 mm first layer and 0.08 mm layers, set the first color to 0.28 mm, then make any image change that recomputes the swatches but keeps the same colors (such as a crop, or undo and redo in 2D). The first color should come back as 0.36 mm. This was found from the code and a small simulation, and still needs confirming in the app.

Fix

In the reconcile effect, snap the first color in display order to minimum + round((h − minimum) / layerHeight) × layerHeight, where minimum = max(layerHeight, firstLayerHeight), the same rule the alignment effect uses. Leave the other colors unchanged. #156 contains this change.

Acceptance

  • A node:test regression: repeated reconciliation leaves a valid first-layer height unchanged for first-layer heights that are not a multiple of the layer height.
  • The swap plan (useSwapPlan) still lines up with the snapped heights.

Split from #156.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. vycdev commented on Nov 19, 2026

    @vycdev
    OwnerAuthor

    Fixed by #178, merged into develop.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions