Repository navigation
feat(core): unit registry for world_units; per-dimension display units; SI <-> nav's normalized frame - #632
Merged
Merged
Conversation
…s; SI <-> nav's normalized frame
world_units converted through a fixed table of eight dimensions. The physics
tier needs power, pressure, temperature, curvature, charge and energy per
distance, applications need units the table does not have, and nav's plant
adapter needs to move SI quantities into the normalized frame its kernels
and weights live in.
- cvc::unit_registry (core/unit_registry.h): dimensions with an SI unit and a
length exponent; units that are linear, affine (degC, degF) or a pair of
functions (dBm). The built-in table covers SI and imperial for every
world_units dimension plus nmi, kn, kWh, Wh/km, psi, rpm, mAh and others,
with every factor from cvc::units. add_dimension / add_linear /
add_affine / add_function drop in custom units at run time. Duplicates,
bad factors, unknown units and conversions across dimensions throw the new
cvc::unit_error. The registry is copyable and thread-safe. A function
unit's callable runs outside the lock.
- world_units: 14 dimensions are appended to the enum, so the existing values
are unchanged. Each instance owns its registry. New calls:
- to_si / from_si / convert;
- set_display_unit / clear_display_unit / display_unit per dimension (a
length override turns off km/mile promotion);
- every display call by dimension name, so custom dimensions work.
- SI <-> normalized: to_normalized / from_normalized scale by the
dimension's length exponent, so velocity is multiplied by S / mpwu,
curvature by mpwu / S, and time, angle and mass pass through.
si_point_to_normalized / normalized_point_to_si apply the centre in the
order nav's snapshot uses. cvc::nav::frame_of(sim_world::config) names the
frame. No kernel calls any of it.
- pycvc wraps unit_registry (add_function takes Python callables and
re-acquires the GIL per call), the new world_units calls with the _d
convention, and normalized_frame / xyz.
- Existing conversions are unchanged: all 25 earlier world_units tests pass
untouched. 15 new C++ tests and 7 new Python tests cover the registry,
overrides, custom dimensions, the frame and concurrent registration. The
header-hygiene test now includes both new headers.
- Docs: WORLD_UNITS_API.md (dimension table, registry, frame, Python) and a
NAV_UNITS_ROADMAP.md update noting which primitives have landed.
transfix
added a commit
that referenced
this pull request
Oct 17, 2026
Minor release. It carries: - the world clock: lockstep and batch, followers, the sim.* binding, and nav on the clock (#629, #630, #631, #640); - the units registry with SI <-> normalized-frame conversions (#632); - cvc::physics with the Jolt backend (#641); - the material trainer on the kinematic bicycle and its pycvc bindings (#642). Bumps project(VERSION) 3.5.1 -> 3.6.0 and every cvcpkg recipe's upstream_version to match. cvc_revision stays 1, per the recipe-version gate.
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.
Why
Doc 31's physics tier needs the following before the Jolt work starts:
What
cvc::unit_registry(inc/cvc/core/unit_registry.h):degC,degF) and function (dBm, or any invertible pair).nmi kn kWh Wh/km kWh/100km psi bar rpm mAh acre galand others. Every factor comes fromcvc::units.add_dimension,add_linear,add_affineandadd_functionadd units at run time.cvc::unit_error.world_units:registry()).to_si,from_siandconvert.set_display_unit,clear_display_unitanddisplay_unit. A length override turns off km/mile promotion.to_normalizedandfrom_normalizedscale by the dimension's length exponent: velocity by S / mpwu, curvature by mpwu / S; time, angle and mass pass through.si_point_to_normalizedandnormalized_point_to_siapply the centre in the same order as nav's snapshot (o/S + c).cvc::nav::frame_of(sim_world::config)(inc/cvc/nav/nav_units.h) builds the frame for a config.unit_registryis wrapped.add_functiontakes Python callables and re-acquires the GIL for each call; an exception raised in the callable comes back as aRuntimeErrorthat names it._dconvention.world_units_normalized_frameandworld_units_xyzare exposed.docs/WORLD_UNITS_API.md: the dimension table with exponents, the registry, display overrides, the frame, and Python.docs/roadmap/NAV_UNITS_ROADMAP.md: a note on which primitives have landed.Verification (Windows, MSVC 2022, local cvcpkg prefix)
world_units_test: 40/40 pass. The 25 existing tests pass unmodified, so existing conversions are unchanged. 15 tests are new:system_macro_headers_test: passes with both new headers included after<windows.h>.test_pycvc_world_units.py: all pass, including 7 new cases. The world_clock, app, state, nav_train, threading and memory suites also pass.