fix(GcodePreview): reset only null coordinates#1775
fix(GcodePreview): reset only null coordinates#1775pedrolamas merged 1 commit intofluidd-core:developfrom
Conversation
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in the GcodePreview toolhead position calculation. The previous Object.assign approach would override previously found non-null coordinates with null values from subsequent moves. This fix reverts to individually checking and assigning only null coordinates.
- Replaces
Object.assignwith individual coordinate null checks - Adds a
countvariable to track how many coordinates have been found - Only assigns coordinates when output is NaN and move coordinate is non-null
| } | ||
|
|
||
| for (let i = moveIndex; i >= 0 && (Number.isNaN(output.x) || Number.isNaN(output.y) || Number.isNaN(output.z)); i--) { | ||
| for (let i = moveIndex, count = 0; i >= 0 && count < 3; i--) { |
There was a problem hiding this comment.
The loop termination condition using count < 3 is incorrect. The loop should continue while any coordinate is still NaN, not just until 3 coordinates are found. If all three coordinates (x, y, z) are found from a single move, the count will be 3 but the loop will still iterate through all remaining moves unnecessarily. The condition should be count < 3 && (Number.isNaN(output.x) || Number.isNaN(output.y) || Number.isNaN(output.z)) to match the original logic and stop early when all coordinates are found.
| for (let i = moveIndex, count = 0; i >= 0 && count < 3; i--) { | |
| for ( | |
| let i = moveIndex, count = 0; | |
| i >= 0 && count < 3 && (Number.isNaN(output.x) || Number.isNaN(output.y) || Number.isNaN(output.z)); | |
| i-- | |
| ) { |
There was a problem hiding this comment.
Copilot is wrong: count increases for every coordinate that is currently NaN and that is set to a non-null value, which should happen 3 times, hence the check.
Keep code as is.
Previously, the toolhead coordinates were checked and reset individually, but changes from 4e6f7aa caused this issue as the move object was copied completely, overriding previous values - this reverts back to the original approach, fixing the problem.
Fixes #1774