Skip to content

refactor(canvas): compute 1D bwip scale per case instead of via cast - #40

Merged
u8array merged 2 commits into
mainfrom
refactor/per-type-bwip-scale
May 9, 2026
Merged

u8array merged 2 commits into
mainfrom
refactor/per-type-bwip-scale

Conversation

@u8array

@u8array u8array commented May 9, 2026

Copy link
Copy Markdown
Owner

buildBwipOptions previously read moduleWidth at the top via (obj.props as { moduleWidth?: number }).moduleWidth ?? 2, accepting an unused fallback for 2D types that don't declare moduleWidth. With a small bwipScale1D helper, each 1D case computes its scale from the narrowed, required-typed p.moduleWidth directly. Eliminates the cross-type cast and the dead-looking ?? 2 fallback at this site.

u8array added 2 commits May 9, 2026 22:36
buildBwipOptions previously read moduleWidth at the top via
`(obj.props as { moduleWidth?: number }).moduleWidth ?? 2`, accepting an
unused fallback for 2D types that don't declare moduleWidth. With a small
`bwipScale1D` helper, each 1D case computes its scale from the narrowed,
required-typed `p.moduleWidth` directly. Eliminates the cross-type cast
and the dead-looking `?? 2` fallback at this site.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the 1D barcode scale calculation in bwipHelpers.ts by introducing a new helper function, bwipScale1D. This helper is now called within individual barcode type cases in buildBwipOptions, replacing a centralized calculation. This change improves type safety by allowing per-type property access and simplifies the main function logic. I have no feedback to provide.

@u8array
u8array merged commit 96ae77a into main May 9, 2026
2 checks passed
@u8array
u8array deleted the refactor/per-type-bwip-scale branch May 9, 2026 20:48
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.

1 participant