Skip to content

fix: set omit_zeros unconditionally when LZ/TZ is declared in Excellon header#275

Merged
spe-ciellt merged 2 commits intogerbv:developfrom
SourceParts:fix/excellon-file-format-lz-regression
Feb 22, 2026
Merged

fix: set omit_zeros unconditionally when LZ/TZ is declared in Excellon header#275
spe-ciellt merged 2 commits intogerbv:developfrom
SourceParts:fix/excellon-file-format-lz-regression

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

Summary

Fixes #174. When an Excellon drill file contains both FILE_FORMAT and INCH,LZ (or METRIC,LZ, INCH,TZ, etc.), the FILE_FORMAT handler sets autod = 0, which causes the subsequent LZ/TZ parsing to skip setting omit_zeros. This results in incorrect coordinate interpretation — trailing zeros are not suppressed when they should be.

The fix moves the omit_zeros assignment outside the if (state->autod) gate in both drill_parse_header_is_metric() and drill_parse_header_is_inch(). The autod gate is preserved for decimals and number_format — only omit_zeros is decoupled.

This regression was introduced in 944a4b3 (PR #156).

What changed

  • src/drill.c: 4 lines moved — omit_zeros assignment for cases 'L' and 'T' in both drill_parse_header_is_metric() and drill_parse_header_is_inch() now executes unconditionally
  • test/golden/LimeSDR-QPCIe_1v2-RoundHoles.png: Regenerated — previous golden was produced with the buggy autod=0 path
  • test/inputs/Altium_file_format_inch_lz.drl: New test input — FILE_FORMAT=2:5 before INCH,LZ with trailing-zero-suppressed coordinates
  • test/tests.list: Added Altium_file_format_inch_lz test entry

Regression analysis

Scenario autod Before fix After fix
INCH,TZ alone (no FILE_FORMAT) 1 omit_zeros set omit_zeros set — same
FILE_FORMAT then INCH,TZ 0 omit_zeros skipped (bug) omit_zeros set — fixed
FILE_FORMAT then METRIC,LZ 0 omit_zeros skipped (bug) omit_zeros set — fixed
INCH,TZ then FILE_FORMAT 1→0 omit_zeros set (autod still 1 during TZ parse) omit_zeros set — same
No LZ/TZ at all any fallback at header-end unchanged

The new test Altium_file_format_inch_lz fails on develop with MAE=13726 and passes with this fix.

Test plan

  • All existing drill tests pass (except pre-existing test-drill-trailing-zero-suppression failure unrelated to this change)
  • New Altium_file_format_inch_lz test passes
  • Verified new test fails on develop without the fix
  • Altium_file_format_inch and Altium_inch_file_format unchanged (still pass)

When FILE_FORMAT=N:M sets autod=0 (commit 944a4b3, PR gerbv#156), the
subsequent INCH,LZ or METRIC,LZ line is completely ignored — not just
the decimals/number_format override (intended), but also the omit_zeros
setting (regression).

This causes coordinates with suppressed trailing zeros to be
misinterpreted, rendering drill holes at wildly incorrect positions.
Affects all Altium-exported drill files using FILE_FORMAT + INCH,LZ.

Fix: move omit_zeros assignment outside the if(state->autod) gate in
both drill_parse_header_is_inch() and drill_parse_header_is_metric().
The autod guard still correctly prevents decimals/number_format from
being overridden when FILE_FORMAT has already set them.

Fixes gerbv#174. Fixes gerbv#195.
Add new test case Altium_file_format_inch_lz that covers the exact
scenario from issue gerbv#174: FILE_FORMAT declared before INCH,LZ. This
test fails on develop (MAE=13726) and passes with the omit_zeros fix.

Regenerate golden PNG for LimeSDR-QPCIe_1v2-RoundHoles since the
previous golden was generated with the buggy autod gate that skipped
omit_zeros when FILE_FORMAT was present.
@spe-ciellt
Copy link
Copy Markdown
Contributor

Hello and thank you for the patch. I will merge this patch since it seems to solve a real world problem and does not affect the current ones.

@spe-ciellt spe-ciellt merged commit fb04afa into gerbv:develop Feb 22, 2026
1 check passed
@rampageservices rampageservices deleted the fix/excellon-file-format-lz-regression branch February 27, 2026 17:20
@spe-ciellt spe-ciellt added the bug Something isn't working label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.9.6 Trailing zero imports wrong

2 participants