Modeling - Fix array indexing bug in IntAna_IntQuadQuad::NextCurve method#703
Conversation
…ethod Fixed a critical indexing bug in IntAna_IntQuadQuad::NextCurve where the method incorrectly used nextcurve[I] instead of nextcurve[I-1] for determining the theOpposite parameter. This mismatch between 1-indexed API parameters and 0-indexed array access could lead to out-of-bounds memory access and incorrect curve connectivity determination. Changes: - Fix IntAna_IntQuadQuad::NextCurve to use consistent I-1 indexing for both condition check and return value - Add comprehensive GTests covering NextCurve functionality, edge cases, and performance - Ensure proper error handling for invalid curve indices
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a critical array indexing bug in the IntAna_IntQuadQuad::NextCurve method where inconsistent indexing between 1-indexed API parameters and 0-indexed array access could cause memory safety issues and incorrect results.
Key changes:
- Corrected the indexing inconsistency in
NextCurvemethod by usingI-1for both condition check and return value - Added comprehensive test coverage for the
NextCurvefunctionality with edge cases and performance validation - Simplified the conditional logic while maintaining the same behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/ModelingData/TKGeomBase/IntAna/IntAna_IntQuadQuad.cxx |
Fixed array indexing bug by using consistent I-1 indexing and simplified conditional logic |
src/ModelingData/TKGeomBase/GTests/IntAna_IntQuadQuad_Test.cxx |
Added comprehensive test suite covering NextCurve functionality, boundary conditions, and performance |
src/ModelingData/TKGeomBase/GTests/FILES.cmake |
Updated build configuration to include the new test file |
| cylinder1 = gp_Cylinder(axis, 3.0); | ||
|
|
||
| // Create cone with semi-angle 30 degrees | ||
| cone1 = gp_Cone(axis, M_PI / 6, 2.0); |
There was a problem hiding this comment.
Use Standard_Real instead of double for floating-point values. According to OCCT conventions, geometric calculations should use Standard_Real type.
| for (Standard_Integer i = 1; i <= intersector.NbCurve(); i++) | ||
| { | ||
| const IntAna_Curve& aCurve = intersector.Curve(i); | ||
| EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant() || !aCurve.IsOpen()); |
There was a problem hiding this comment.
This assertion is always true due to the logical structure A || B || !A. The condition aCurve.IsOpen() || !aCurve.IsOpen() will always evaluate to true regardless of the IsConstant() result, making this test meaningless.
| EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant() || !aCurve.IsOpen()); | |
| EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant()); |
| gp_Sphere sphere1(axis1, 2.0); | ||
| gp_Sphere sphere2(axis2, 2.0); |
There was a problem hiding this comment.
Use Standard_Real instead of double literals. These should be 2.0 should be written as Standard_Real(2.0) or defined as Standard_Real variables to follow OCCT type conventions.
| IntAna_Quadric aSphere2Quad(sphere2); | ||
|
|
||
| IntAna_IntQuadQuad anIntersector; | ||
| anIntersector.Perform(gp_Cylinder(axis1, 2.0), aSphere2Quad, 1e-7); |
There was a problem hiding this comment.
Use Standard_Real for tolerance value. The literal 1e-7 should be Standard_Real(1e-7) to follow OCCT type conventions.
…thod (#703) Fixed a critical indexing bug in IntAna_IntQuadQuad::NextCurve where the method incorrectly used nextcurve[I] instead of nextcurve[I-1] for determining the theOpposite parameter. This mismatch between 1-indexed API parameters and 0-indexed array access could lead to out-of-bounds memory access and incorrect curve connectivity determination. Changes: - Fix IntAna_IntQuadQuad::NextCurve to use consistent I-1 indexing for both condition check and return value - Add comprehensive GTests covering NextCurve functionality, edge cases, and performance - Ensure proper error handling for invalid curve indices
…thod (#703) Fixed a critical indexing bug in IntAna_IntQuadQuad::NextCurve where the method incorrectly used nextcurve[I] instead of nextcurve[I-1] for determining the theOpposite parameter. This mismatch between 1-indexed API parameters and 0-indexed array access could lead to out-of-bounds memory access and incorrect curve connectivity determination. Changes: - Fix IntAna_IntQuadQuad::NextCurve to use consistent I-1 indexing for both condition check and return value - Add comprehensive GTests covering NextCurve functionality, edge cases, and performance - Ensure proper error handling for invalid curve indices
Fixed a critical indexing bug in IntAna_IntQuadQuad::NextCurve where the
method incorrectly used nextcurve[I] instead of nextcurve[I-1] for
determining the theOpposite parameter.
This mismatch between 1-indexed API
parameters and 0-indexed array access could lead to out-of-bounds memory
access and incorrect curve connectivity determination.
Changes: