Skip to content

[measure-tools] Adopt generated Units.* identifiers and phenomenon-aware bearing fallback#1701

Draft
hl662 wants to merge 4 commits into
masterfrom
nam/measure-tools-canonical-units
Draft

[measure-tools] Adopt generated Units.* identifiers and phenomenon-aware bearing fallback#1701
hl662 wants to merge 4 commits into
masterfrom
nam/measure-tools-canonical-units

Conversation

@hl662

@hl662 hl662 commented May 28, 2026

Copy link
Copy Markdown
Contributor

Draft until iTwin.js 5.10.0 stable releases. Peers are pinned to 5.10.0-dev.22; before marking ready I'll relax them to ^5.10.0.

TL;DR

measure-tools passed unit names as bare strings ("Units.M", "Units.RAD") — untyped and typo-prone — and the bearing fallback only built an ANGLE composite. iTwin.js 5.10 ships generated Units.* identifiers and a new HORIZONTAL_DIRECTION phenomenon. This PR adopts those identifiers, swaps every magic string for its typed constant, and extends the bearing fallback to pick its composite by the persistence unit's phenomenon (ANGLE or HORIZONTAL_DIRECTION), defaulting to ANGLE for unknown units.

Bearing stays opt-in. Units.HORIZONTAL_DIRECTION.HORIZONTAL_DIR_RAD is canonical for bearing persistence. Closes #1343.

What

Asset Why it exists
package.json (measure-tools, test-viewer) ^5.9.2 core predates the generated Units namespace — bumps @itwin/core-* peers + dev pins to 5.10.0-dev.22.
FormatterUtils.ts Bearing fallback was ANGLE-only; 5.10 adds the HORIZONTAL_DIRECTION phenomenon. Now phenomenon-keyed (ANGLE default). Kept rather than dropped — hosts (OpenSitePlus) pass a non-resolving KoQ to trigger it.
Polygon.ts, *Measurement.ts (Angle/Area/Distance/Location/Radius) Magic unit strings → Units.* constants; stale "Defaults to…" JSDoc fixed (bearing now documented as opt-in).

Change file: minor.

Tests

New and updated test coverage
Test What it covers
FormatterUtils.test.ts — ANGLE / HORIZONTAL_DIRECTION composites Fallback picks the persistence unit's phenomenon.
FormatterUtils.test.ts — unknown unit → ANGLE Bogus unit makes isCompatible throw → defaults to ANGLE.
FormatterUtils.test.ts — round-trip through getBearingFormatterSpec End-to-end per phenomenon.
*Measurement.test.ts Assertions reference typed Units.* constants.

Nambot 🤖 (powered by claude-opus-4-8)

hl662 and others added 4 commits May 28, 2026 12:17
Prereq for adopting canonical Units identifiers shipped via iTwin.js 5.10 (itwinjs-core#9275). Pin will be relaxed to ^5.10.0 once 5.10.0 stable is published. apps/test-viewer bumped in lockstep since it consumes measure-tools.
…ntifiers

Adopt typed unit constants (Units.LENGTH.M, Units.AREA.SQ_M, Units.ANGLE.RAD/REVOLUTION/ARC_DEG/ARC_MINUTE/ARC_SECOND) from @itwin/core-quantity in src and tests. No behavior change. Serialized JSON wire-format strings are intentionally left untouched.
getDefaultBearingFormatProps now accepts the persistence unit name and returns a composite + revolutionUnit in the matching phenomenon. Detects HORIZONTAL_DIRECTION via UnitConversions.isCompatible (sync, package-owned) and falls back to ANGLE-phenomenon composite for ANGLE.RAD or unknown units. Unblocks consumers passing Units.HORIZONTAL_DIR_RAD as the bearing persistence unit.
- Refactor pickBearingUnits to a table-driven phenomenon lookup
- Document the intentional UnitName cast and isCompatible throw-on-unknown contract
- Share DMS composite labels across phenomena
- Document getDefaultBearingFormatProps public fallback helper
- Update stale "Units.*" JSDoc to canonical Units.* identifiers
- Add ANGLE edge-case, label, and per-phenomenon round-trip tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

[measure-tools] Remove usage of a default bearing formatProps in DistanceMeasurement

1 participant