Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/store/gcodePreview/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ export const getters = {
z: NaN
}

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--) {
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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--
) {

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

const move = moves[i]

Object.assign(output, move)
if (Number.isNaN(output.x) && move.x != null) {
output.x = move.x
count++
}

if (Number.isNaN(output.y) && move.y != null) {
output.y = move.y
count++
}

if (Number.isNaN(output.z) && move.z != null) {
output.z = move.z
count++
}
}

return {
Expand Down