[measure-tools] Adopt generated Units.* identifiers and phenomenon-aware bearing fallback#1701
Draft
hl662 wants to merge 4 commits into
Draft
[measure-tools] Adopt generated Units.* identifiers and phenomenon-aware bearing fallback#1701hl662 wants to merge 4 commits into
hl662 wants to merge 4 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
measure-toolspassed 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 generatedUnits.*identifiers and a newHORIZONTAL_DIRECTIONphenomenon. 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_RADis canonical for bearing persistence. Closes #1343.What
package.json(measure-tools, test-viewer)^5.9.2core predates the generatedUnitsnamespace — bumps@itwin/core-*peers + dev pins to5.10.0-dev.22.FormatterUtils.tsHORIZONTAL_DIRECTIONphenomenon. 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)Units.*constants; stale "Defaults to…" JSDoc fixed (bearing now documented as opt-in).Change file:
minor.Tests
New and updated test coverage
FormatterUtils.test.ts— ANGLE / HORIZONTAL_DIRECTION compositesFormatterUtils.test.ts— unknown unit → ANGLEisCompatiblethrow → defaults to ANGLE.FormatterUtils.test.ts— round-trip throughgetBearingFormatterSpec*Measurement.test.tsUnits.*constants.Nambot 🤖 (powered by claude-opus-4-8)