Skip to content

BUG: Clamp cosines before acos in Compute Twin Boundaries - #1972

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/twin-boundaries-acos-clamp
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:fix/twin-boundaries-acos-clamp

Conversation

@imikejackson

Copy link
Copy Markdown
Contributor

Summary

Compute Twin Boundaries called acos() on two cosines without clamping them (ComputeTwinBoundaries.cpp):

  • the cosine between the twin axis and the crystal-frame face normal, from GeometryMath::CosThetaBetweenVectors() (FindTwinBoundaryIncoherence()), and
  • the cosine between the misorientation axis and <111> (IsTwinBoundary() and FindTwinBoundaryIncoherence()).

For a parallel pair, rounding can give 1 + 1 ulp. acos() then returns NaN, every comparison with the tolerance is false, and a coherent Σ3 twin boundary is reported as no twin (flag 0, no incoherence), with no error or warning.

Change: both cosines are clamped to [-1, 1] with std::clamp before acos(). A value inside [-1, 1] is unchanged, so valid output does not change; the existing exemplar tests pass unchanged. No new error codes.

EbsdLib #80 adds the same clamp inside EbsdLib; this call site computes its own cosines, so it needs its own clamp.

Existing branches and open pull requests: no branch on origin or fork other than this one has commits that touch ComputeTwinBoundaries.cpp or its test, and no open pull request changes them.

Test Plan

  • New test OrientationAnalysis::ComputeTwinBoundariesFilter: Exact Sigma 3 Twin With Parallel Normal fails on develop (0cd2009) and passes with this change. It builds 4000 faces between an identity Feature and its Σ3 twin (60° about [111]), each with a face normal that is a positive multiple of [111]. By hand calculation every face is a coherent twin with incoherence 0. On develop, 20 of the 4000 faces (for example faces 43, 170, 184, 253) are reported as not twin.
  • Full Compute Twin Boundaries test set passes, 6/6: ctest -R "OrientationAnalysis::ComputeTwinBoundariesFilter".
  • Linux x64, Release, Ninja, in-core build. Synthetic data written by the test; no new data archives.
  • Out-of-core validation NOT run (no out-of-core build on this machine). A maintainer needs to run the dual-build protocol.
  • Skills that could not be loaded (not available in this environment): bluequartz-skills:cpp-best-practices, bluequartz-skills:simplnx-best-practices, filter-implementation, implement-filter-tests, dual-build-protocol, clang-format, github-workflow. docs/Coding_Knowledge_Base.md was followed instead.

Related Issue

Related to #1875 (item ComputeTwinBoundariesFilter#4) and BlueQuartzSoftware/EbsdLib#80.

🤖 Generated with Claude Code

- ComputeTwinBoundaries passed the cosine between the misorientation axis and
  the crystal-frame face normal, and the cosine between the axis and <111>,
  to acos() without clamping. A parallel pair can round to 1 + 1 ulp, acos()
  returns NaN, and the comparison with the tolerance fails, so a coherent
  Sigma 3 twin was reported as no twin.
- Both cosines are now clamped to [-1, 1] before acos(), in the incoherence
  path and in the twin-only path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@imikejackson

Copy link
Copy Markdown
Contributor Author

Closed in favor of #1973, which merges this branch (with its history) together with the other EBSD fixes that need the next EbsdLib release (BlueQuartzSoftware/EbsdLib#86). The branch is kept.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant