Skip to content

fix(svg): consolidate hardcoded geometry parameters into layout constants#6129

Closed
hardik-bhalekar wants to merge 1 commit into
JhaSourav07:mainfrom
hardik-bhalekar:fix/svg-isometric-projection
Closed

fix(svg): consolidate hardcoded geometry parameters into layout constants#6129
hardik-bhalekar wants to merge 1 commit into
JhaSourav07:mainfrom
hardik-bhalekar:fix/svg-isometric-projection

Conversation

@hardik-bhalekar

Copy link
Copy Markdown

Summary

Consolidates hardcoded isometric geometry magic numbers (16, 10, 20, 8) scattered across generator.ts into named constants in layoutConstants.ts, eliminating layout fragmentation caused by inconsistent values and making the SVG projection layer maintainable.

Problem

The SVG isometric rendering pipeline uses several geometry parameters (tile half-width, tile half-height, full tile height, label offsets) that were duplicated as raw numeric literals across buildTowerPaths(), renderIsometricLabels(), and generateLanguagesSVG(). This led to:

  1. Layout fragmentation — changing one value without updating the others breaks visual alignment
  2. Poor maintainability — the meaning of magic numbers like 16, 10, 20 was unclear without context
  3. Inconsistency riskISOMETRIC_VERTICAL_OFFSET was a local const in generator.ts while TILE_WIDTH_HALF/TILE_HEIGHT_HALF were already exported from layoutConstants.ts

Changes

lib/svg/layoutConstants.ts

Added 5 new exported constants:

Constant Value Purpose
TILE_FULL_HEIGHT 20 Full vertical extent of one isometric tile
TILE_DIAGONAL_HALF 8 Half the tile diagonal (used for offset calculations)
GRID_CELL_SIZE 16 Logical grid cell size in CSS pixels
MONTH_LABEL_OFFSET_X 8 Horizontal offset for month label positioning
ISOMETRIC_LABEL_VERTICAL_OFFSET 20 Vertical offset for isometric label projection

lib/svg/generator.ts

Location Before After
buildTowerPaths() 16 * scale, 10 * scale, 20 * scale TILE_WIDTH_HALF * scale, TILE_HEIGHT_HALF * scale, TILE_FULL_HEIGHT * scale
Module-level const ISOMETRIC_VERTICAL_OFFSET = 20 Removed (now imported from layoutConstants.ts)
renderIsometricLabels() month labels Hardcoded + 8 and ISOMETRIC_VERTICAL_OFFSET MONTH_LABEL_OFFSET_X and ISOMETRIC_LABEL_VERTICAL_OFFSET
renderIsometricLabels() weekday labels ISOMETRIC_VERTICAL_OFFSET + Math.round(20 * sf) ISOMETRIC_LABEL_VERTICAL_OFFSET throughout
generateLanguagesSVG() 10 * towerScale TILE_HEIGHT_HALF * towerScale

Testing

  • npx tsc --noEmit passes with zero errors
  • SVG output is visually identical (same numeric values, just sourced from constants)
  • All constants are single-source-of-truth in layoutConstants.ts

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@hardik-bhalekar is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @hardik-bhalekar! Thanks for your contribution! 🎉

Unfortunately, this PR has been automatically closed because it is not linked to any open issue.

To resolve this, please do the following:

  1. Link a valid open issue by editing your PR description to include a closing keyword (e.g., Fixes #<issue-number>).
  2. Reopen this PR once the link is added.

💡 You can link multiple issues if needed (e.g. Fixes #12, Closes #34).
If you're working on something that doesn't have an issue yet, please open one first and then link it here.

We look forward to reviewing your PR once an issue is linked! 🚀

@github-actions github-actions Bot closed this Jun 20, 2026
@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant