Validate that Intrinsics width/height are positive#60
Merged
bamdadd merged 1 commit intoJul 22, 2026
Conversation
from_fov guards width/height > 0, but Intrinsics built directly (or via from_focal) accepted a zero/negative size, which silently breaks matrix(), in_image bounds and every downstream projection. Add a field_validator on width/height that rejects non-positive values with a clear ValueError, so the invariant holds no matter how the model is built (mirrors the existing shape validators on Camera). All current construction paths already pass positive sizes, so only the direct path tightens. Closes bamdadd#59
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.
Closes #59.
from_fovguardswidth > 0/height > 0, but anIntrinsicsbuilt directly (or viafrom_focal) with a zero/negative size was accepted — silently breakingmatrix(),in_imagebounds, and every downstream projection.Change: a
field_validatoronwidth/heightrejects non-positive values with a clearValueError, so the invariant holds however the model is constructed (mirrors the existing shape validators onCamera). All current construction paths (from_focal,from_fov,drifted) already pass positive sizes, so only the direct path tightens.Acceptance criteria:
Intrinsics(..., width=0, ...)and negative width/height raiseValueError. ✅Intrinsics(e.g. fromfrom_focal(100, 640, 480)) still constructs unchanged. ✅ruff check/formatandmypyclean on the changed files;pytest tests/test_cameras.pygreen. (Pre-existing mypytype-argwarnings insmoke.pyare untouched by this PR.)