Repository navigation
Fix GetArbitraryAxis threshold for normals near +Z - #28
Open
jarrett-meyer wants to merge 1 commit into
Open
jarrett-meyer wants to merge 1 commit into
jarrett-meyer wants to merge 1 commit into
Conversation
`1 / 64` is integer division and evaluates to 0, so the near-Z branch of the arbitrary axis algorithm was never taken and normals close to +Z got an X axis from Wz x N instead of Wy x N. Use `1.0 / 64`, as Matrix3.ArbitraryAxis already does. Co-Authored-By: Claude Opus 5.5 <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.
Bug
Matrix4.GetArbitraryAxis(XYZ zaxis)decides which world axis to cross with the normal using:1 / 64is integer division, so the threshold is always0and the condition can never be true. For any normal whose X and Y components are both below 1/64 (but which is not exactly +Z or -Z), the method computes the X axis fromWz x Ninstead ofWy x N. This does not follow the DXF arbitrary axis algorithm, so entities with a normal close to +Z get an OCS rotated by about 90 degrees.Matrix3.ArbitraryAxisalready uses1 / 64.0and is not affected.How to reproduce
Fix
Use
1.0 / 64so the comparison is done in floating point.Tests
Added
CSMath.Tests/Matrix4Tests.cswith two cases: a normal near +Z (usesWy x N; fails before this change) and a general normal (usesWz x N). The fullCSMath.Testssuite passes (292 tests).🤖 Generated with Claude Code