Skip to content

ENH: Add a range-checked LaueOps lookup by crystal structure - #77

Closed
imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:enh/laueops-checked-index-lookup
Closed

imikejackson wants to merge 1 commit into
BlueQuartzSoftware:developfrom
imikejackson:enh/laueops-checked-index-lookup

Conversation

@imikejackson

Copy link
Copy Markdown
Collaborator

Summary

Callers take a crystal-structure value from a file (where UnknownCrystalStructure is 999) or from a phase's determineOrientationOpsIndex() and index LaueOps::GetAllOrientationOps() with it. A value outside the vector reads out of bounds. EbsdLib had no range-checked accessor: the only static lookups were GetAllOrientationOps() (unchecked vector) and GetLaueOpsFromSpaceGroupNumber() (takes a space-group number, not a crystal structure).

  • New additive API, named after GetLaueOpsFromSpaceGroupNumber() from BUG: Map space groups 1-230 to the correct Laue class #67:
    static LaueOps::Pointer LaueOps::GetOrientationOpsFromCrystalStructure(uint32_t crystalStructure)
  • It returns the same LaueOps subclass as GetAllOrientationOps()[crystalStructure] for each ebsdlib::CrystalStructure constant 0-10, and NullPointer() for LaueGroupEnd (11), UnknownCrystalStructure (999) and every other value.
  • LaueGroupEnd (11) is rejected on purpose. GetAllOrientationOps() has a 12th entry (an OrthoRhombicOps labelled "Axis OrthorhombicOps"), but 11 is the end marker of the Laue groups, not a crystal structure. Callers that want the legacy entry can still index the vector.
  • Performance note (no change here): GetAllOrientationOps() builds a new vector of 12 newly allocated LaueOps objects on every call. The new accessor creates only the requested object.
  • No EbsdLib-internal call site indexes GetAllOrientationOps() with an unchecked value from a file: the readers' printSelf() already use GetLaueOpsFromSpaceGroupNumber() with a null check, and PoleFigureCompositor / DiscretePoleFigureCompositor already compare laueOpsIndex with the vector size. The apps index it with literals. So no call sites change.
  • No error codes are added.

Test Plan

  • New test EbsdLib::ebsdlib::LaueOpsTest::GetOrientationOpsFromCrystalStructure (in LaueOpsTest.cpp). On develop it does not compile ('GetOrientationOpsFromCrystalStructure' is not a member of 'ebsdlib::LaueOps'): there is no checked accessor. With this change it passes. It checks every valid constant against an independent table of class names and against GetAllOrientationOps(), and that 11, 12, 999 and UINT32_MAX return null. (LaueOps has no getCrystalStructure() method, so the test compares class names.)
  • Linux x64, Release: full ctest suite passes, 430/430.

Related Issue

Related to BlueQuartzSoftware/simplnx#1867 (class C07e), BlueQuartzSoftware/simplnx#1879, and the unchecked index in simplnx WriteGBCDGMTFile.cpp. simplnx can switch those call sites to this accessor once this is merged.

Overlaps: open PRs #60, #61, #64 and #74 also change LaueOps.cpp (and #60/#61 LaueOps.h and LaueOpsTest.cpp). This change only adds a function and a test case, so any conflict is textual; merge order does not matter.

The bluequartz-skills skills (cpp-best-practices, simplnx-best-practices) could not be loaded in this environment; the repository's CLAUDE.md coding standards were followed.

🤖 Generated with Claude Code

* Callers that read a crystal-structure value from a file (where
  UnknownCrystalStructure is 999) or take one from a phase's
  determineOrientationOpsIndex() index GetAllOrientationOps() with it
  directly. A value outside the vector reads out of bounds, and EbsdLib
  had no checked accessor.
* Add LaueOps::GetOrientationOpsFromCrystalStructure(uint32_t). It
  returns the same LaueOps subclass as GetAllOrientationOps()[value] for
  every CrystalStructure constant 0-10, and NullPointer() for
  LaueGroupEnd (11), UnknownCrystalStructure and every other value.
* It creates only the requested object instead of the 12 objects that
  GetAllOrientationOps() creates on each call.
* GetAllOrientationOps() and GetLaueOpsFromSpaceGroupNumber() do not
  change.

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

Copy link
Copy Markdown
Collaborator Author

Overlap note: feature/odf_generation (#60) and topic/synthetic_changes (#61) remove the obsolete [11] axis-orthorhombic entry from GetAllOrientationOps() (commit 0e91c89). This PR already returns null for 11, so the behavior agrees either way; the only conflict is textual in LaueOps.cpp. Whichever merges second rebases.

🤖 Generated with Claude Code

@imikejackson imikejackson mentioned this pull request Nov 13, 2026
7 tasks done
@imikejackson

Copy link
Copy Markdown
Collaborator Author

Closed in favor of #86, which merges this branch (with its history) together with the other open EbsdLib fixes for the next release, so simplnx can build against one EbsdLib branch. The branch is kept.

🤖 Generated with Claude Code

@imikejackson
imikejackson deleted the enh/laueops-checked-index-lookup branch November 13, 2026 16:28
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