feat(sensors): open external distortion factory and add an ExternalDistortionParameters base - #179
Queued
janickm wants to merge 1 commit into
Queued
Conversation
janickm
force-pushed
the
dev/janickm/external-distortion-factory
branch
from
September 9, 2026 08:58
f9382f2 to
17b3d73
Compare
…tory with open registry Applies the treatment the camera model hierarchy already received to the external distortion hierarchy, which was the most asymmetric of the three: it had an abstract *model* base but no abstract *parameters* base at all, so `ConcreteExternalDistortionParametersUnion` was a single-member union over nothing. Introduce `ExternalDistortionParameters` as the abstract base, carrying the JSON (de)serialization interface and a non-abstract `type()` exactly as `CameraModelParameters` does, and derive `BivariateWindshieldModelParameters` from it. `CameraModelParameters` can then declare its `external_distortion_parameters` field, and the four `get_parameters` casts can name, the abstract type rather than the concrete union. `ExternalDistortionModel.from_parameters` was a static method on the abstract base holding a closed dispatch table over every concrete subclass, inherited by all of them and unable to construct a model defined outside NCore. Replace it with a module-level `external_distortion_model_from_parameters()` dispatching via `functools.singledispatch`, plus `register_external_distortion_model` for out-of-tree models, keeping the static method as a deprecated forwarder. As with the camera factory, the registry sits behind a separate private symbol so the public entry point can carry `typing.overload` signatures. Make `ExternalDistortionModel` generic in its parameter type, so `get_parameters()` returns the concrete type instead of the union. The parameter type is covariant: it appears only in a return position, and invariance would leave concrete instantiations with no common supertype. Widening the `external_distortion_parameters` field annotation changes what `dataclasses_json` resolves for it, so the encode/decode round-trip of a camera carrying windshield distortion is covered explicitly in addition to the existing parameterized round-trip.
janickm
force-pushed
the
dev/janickm/external-distortion-factory
branch
from
September 9, 2026 12:06
17b3d73 to
7ec1a95
Compare
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.
Applies the treatment the camera model hierarchy received in #175 / #177 to the external distortion hierarchy. Companion to #178, which does the same for lidar; the two are independent.
This was the most asymmetric of the three hierarchies: it had an abstract model base but no abstract parameters base at all, so
ConcreteExternalDistortionParametersUnionwas a single-member union over nothing.A parameters base to hang the interface on
ExternalDistortionParametersis introduced as the abstract base, carrying the JSON (de)serialization interface and a non-abstracttype()exactly asCameraModelParametersdoes, withBivariateWindshieldModelParametersderived from it.CameraModelParameters.external_distortion_parametersand the fourget_parameterscasts can then name the abstract type instead of the concrete union.This is the one genuinely new piece of public API here, rather than a re-annotation.
The closed dispatch table
ExternalDistortionModel.from_parameterswas a static method on the abstract base holding a closed table over every concrete subclass, inherited by all of them and unable to construct a model defined outside NCore. Replaced by a module-levelexternal_distortion_model_from_parameters()dispatching viafunctools.singledispatch, withregister_external_distortion_modelfor out-of-tree models; the static method stays as a deprecated forwarder.Generic model
ExternalDistortionModel.get_parameters()was abstract but returned the union rather than the concrete type. It is now generic in its parameter type, covariant for the usual reason (return position only).Risk called out explicitly
Widening the
external_distortion_parametersfield annotation changes whatdataclasses_jsonresolves for it, which is a behavioural risk rather than a pure typing one. The existing parameterized round-trip over the windshield fixtures already covers it and passes unchanged; a direct encode/decode round-trip of a camera carrying windshield distortion is added on top so the property is pinned by name.Verified: 33/33 tests on 3.8 and 3.11,
tyaspect clean,//:format.checkclean.