Reject non-finite look_along directions and fix the camera-convention docs - #90
Merged
Conversation
The direction guard left the up vector unchecked: a non-finite up ([nan, ...] or [inf, 0, 0]) produced a silent all-NaN rotation and an overflowing up ([1e308, ...]) a silent rank-deficient one, the same failure the direction guard removes. A zero up raised, but with a misleading 'parallel to the viewing direction' message. Guard up symmetrically (finite and non-zero), leaving the genuine parallel case to the existing check.
- Add a depth-sign test: a point along +direction is nearer the viewer than one along -direction, pinning the documented out-of-the-screen convention that the existing direction-maps-to-z test (which discards depth) leaves unpinned. - Parametrise the non-finite direction test over NaN and inf components, not only the overflowing-norm case. - Add a zero-direction test for the finite-and-non-zero message. - Tighten the Raises doc: only a caller-supplied up parallel to the direction raises; a default parallel up falls back.
bjmorgan
added a commit
that referenced
this pull request
Aug 17, 2026
Address the PR review: - Add Oblique.__post_init__ rejecting a non-finite angle and a non-finite or negative foreshortening, with a rejection test. This is the same silent-degenerate guard Perspective carries and look_along gained in #90: a non-finite parameter otherwise builds a NaN screen matrix that poisons every drawn position with an obscure, far-from-cause crash. A foreshortening is the length of a unit step, so negative is rejected; angle alone controls the receding direction. - Test the axes-widget inset factor (the screen matrix's spectral norm -- 1.0 for the non-oblique modes, sqrt(1+f^2) for oblique) and that it bounds the sheared tips. - Correct the screen-frame comments: the projection is not a plain drop of z under perspective; the batch's 2D positions come from the projected xy, not camera space; the axes comment labelled a rotation-only line as also applying the screen matrix. Note in the ABC that screen_matrix is the linear part only and does not reproduce to_screen under Perspective.
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.
Two small corrections to
ViewState.look_along.A direction whose length overflows
float64— for example[1e308, 1e308, 1e308]— previously slipped past the zero-length guard: the norm overflowed to infinity, the forward axis divided to zero, the cross products degenerated, and an all-NaN rotation was assigned silently. Extend the guard to reject a non-finite length (which also catches NaN components), raising a clear error instead. The norm is computed undererrstateso the overflow itself does not leak a bare numpy warning alongside the error.The docstring and inline comment also documented the camera convention backwards, and the summary line contradicted the "looking back towards the origin" line. The tested behaviour is that
look_along([0, 0, 1])gives the identity rotation and a point along the direction projects to positive depth (nearest the viewer), so the direction points out of the screen towards the viewer, with the camera on the +direction side looking back at the origin. The docstring is rewritten so every part agrees; behaviour and the existing tests are unchanged.