Skip to content

Modeling Data - Bound Extrema_ExtSS::Points and Extrema_ExtCS::Points by the point sequence - #1596

Open
gsdali wants to merge 1 commit into
Open-Cascade-SAS:IRfrom
SecondMouseAU:fix/extrema-extss-extcs-points-bound
Open

gsdali wants to merge 1 commit into
Open-Cascade-SAS:IRfrom
SecondMouseAU:fix/extrema-extss-extcs-points-bound

Conversation

@gsdali

@gsdali gsdali commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Pre-Submission Checks

  • I checked existing issues, pull requests, discussions, and forum topics for related work.
  • I followed the contribution guidance in .github/CONTRIBUTING.md.
  • I used a PR title in the Group - Summary format.

Problem / Motivation

Extrema_ExtSS and Extrema_ExtCS count their extrema with mySqDist.Length() and bound Points() against that count alone:

int Extrema_ExtSS::NbExt() const { ...; return mySqDist.Length(); }

void Extrema_ExtSS::Points(const int N, Extrema_POnSurf& P1, Extrema_POnSurf& P2) const
{
  if (N < 1 || N > NbExt())
  {
    throw Standard_OutOfRange();
  }
  P1 = myPOnS1.Value(N);
  P2 = myPOnS2.Value(N);
}

The analytic branch for a parallel pair appends a distance and no point pair:

myIsPar = myExtElSS.IsParallel();
if (myIsPar)
{
  mySqDist.Append(myExtElSS.SquareDistance(1));
}

An equidistant family has no unique witness point, so there is nothing to append. NbExt() then reports 1, Points(1, ...) passes its range test and reads an empty NCollection_Sequence. Extrema_ExtCS has the same shape (myExtElCS.IsParallel(), myPOnC/myPOnS).

In a release build NCollection_Sequence::Value has its range check compiled out (No_Exception), so the read faults instead of raising: two parallel planes, or a line parallel to a plane, end the process with SIGSEGV. Extrema_ExtCC::Points has the same defect and is handled in #1445.

Proposed Solution

  • Bound Points() against the point sequence (myPOnS1.Length(), myPOnC.Length()), so a parallel pair raises Standard_OutOfRange for the point it does not have. NbExt() and SquareDistance() are unchanged and still report the distance of the parallel pair.
  • For a non-parallel result mySqDist and the point sequences are appended together in every other branch, so the new bound is the same number and nothing changes there.
  • Say so in the Points() documentation of both classes.
  • Add Extrema_ExtSS_Test and Extrema_ExtCS_Test: a parallel pair (distance kept, Points() raises) and a non-parallel pair (every extremum still has its points), so the tighter bound is shown not to refuse a result that has points.

Extrema_ExtCC2d and Extrema_ExtElC2d bound Points() against counters that move in step with their point containers, and Extrema_ExtElC, Extrema_ExtElCS and Extrema_ExtElSS append no distances of their own, so these two classes are the remaining ones with the mismatch.

Validation

Local build of current IR (Release, BUILD_RELEASE_DISABLE_EXCEPTIONS on as CI builds it, macOS arm64, clang), OpenCascadeGTest:

test IR without the source change with the change
Extrema_ExtSS_Test.ParallelPlanesHaveADistanceButNoPoints SIGSEGV, exit 139 pass
Extrema_ExtCS_Test.LineParallelToPlaneHasADistanceButNoPoints SIGSEGV, exit 139 pass
Extrema_ExtSS_Test.SeparatedSpheresStillReportTheirPoints pass pass
Extrema_ExtCS_Test.LineAboveSphereStillReportsItsPoints pass pass

The two controls pass on both sides, so the first two rows are about the parallel branch and not about Points() in general. With exceptions enabled the same call raises Standard_OutOfRange from NCollection_Sequence instead of faulting, so the EXPECT_THROW also passes there; the change makes the exception come from the bound test of Points() itself.

Neighbouring suites (*Extrema*, GeomAPI*, *Distance*) with the change: 608 tests, 607 passed, 1 skipped by the test itself (ExtremaPC2d_GridEvaluatorTest.UniformParamsRejectInvalidSampleCount), none failed.

Checks performed:

  • Relevant tests were added or updated when applicable.
  • Relevant local tests were run.

clang-format 18.1.8 with the repository .clang-format, the license check and the include cleanup of the formatting job report no change on the touched files, and none contains a non-ASCII character.

Review Notes

Independent of #1445, which changes only Extrema_ExtCC. The two touch different files and do not conflict.

… by the point sequence

Both classes count their extrema with mySqDist.Length() and bound Points()
against that count alone. The analytic branch for a parallel pair appends a
distance and no point pair, so NbExt() reports 1 while the point sequences are
empty, and Points(1, ...) reads an empty NCollection_Sequence.

Bound Points() against the point sequence, as Extrema_ExtCC::Points does. Both
classes keep the sequences in step with mySqDist in every other branch, so a
non-parallel result is unchanged.

Add GTests for the parallel pair and for a non-parallel pair of each class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant