Skip to content

Foundation Classes - Refactor CSLib package and add GTests - #857

Merged
dpasukhi merged 8 commits into
Open-Cascade-SAS:IRfrom
dpasukhi:cslib_impr
Dec 6, 2025
Merged

dpasukhi merged 8 commits into
Open-Cascade-SAS:IRfrom
dpasukhi:cslib_impr

Conversation

@dpasukhi

Copy link
Copy Markdown
Member

Refactored all CSLib package files to modern C++17 standards:

  • Use native C++ types (double, int, bool) instead of OCCT typedefs
  • Apply OCCT naming conventions (theParam, aLocal, myMember)
  • Add Doxygen documentation for all public APIs
  • Use std:: prefix for standard library functions
  • Add method separators and improve code structure

Bug fixes:

  • CSLib_NormalPolyDef::Derivative: Fixed missing multiplication
    by myTABli(i) coefficient in derivative calculation
  • CSLib::Normal: Fixed uninitialized theStatus on early return
    when no non-null derivative is found (now returns CSLib_Singular)
  • CSLib::Normal: Fixed sign change detection logic that was
    overwriting previous true value instead of preserving it
  • CSLib_Class2d: Added Precision::PConfusion() check for vertical
    edges to prevent division by zero

Code cleanup:

  • Removed dead code (unused aYmin variable in CSLib_Class2d)
  • Replaced manual insertion sort with std::sort() in CSLib::Normal
  • Used constexpr for compile-time constants

Added comprehensive GTest coverage (29 tests):

  • CSLibNormalTest: Normal computation from surface derivatives
  • CSLibClass2dTest: Point-in-polygon classification
  • CSLibNormalPolyDefTest: Polynomial evaluation and derivatives
  • CSLibEnumTest: Enum value validation
  • CSLibIntegrationTest: Real surface scenarios

@dpasukhi dpasukhi added this to the Release 8.0 milestone Nov 26, 2025
@dpasukhi
dpasukhi requested a review from Copilot November 26, 2025 16:13
@dpasukhi dpasukhi self-assigned this Nov 26, 2025
@dpasukhi dpasukhi added 2. Enhancement New feature or request 1. Foundation Classes Containers, system calls wrappers, smart pointers and other low level of OCCT code 1. Coding Coding rules, trivial changes and misprints labels Nov 26, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR comprehensively refactors the CSLib package to modern C++17 standards while fixing critical bugs and adding extensive test coverage. The refactoring modernizes the codebase by replacing OCCT typedefs with native C++ types (double, int, bool), applying consistent naming conventions (theParam, aLocal, myMember), and adding comprehensive Doxygen documentation. Critical bug fixes include correcting derivative calculations, initializing status variables, fixing sign change detection logic, and preventing division by zero. The PR also introduces 29 GTests covering normal computation, point-in-polygon classification, polynomial evaluation, and real surface scenarios.

Key changes:

  • Modernized C++17 syntax: native types, std:: prefix, constexpr, auto, structured bindings
  • Fixed 4 critical bugs in derivative calculations and edge detection
  • Added 614 lines of comprehensive GTest coverage (29 tests across 5 test suites)

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
CSLib_Test.cxx New GTest file with 29 comprehensive tests for CSLib functionality
FILES.cmake Added CSLib_Test.cxx to build system
CSLib_NormalStatus.hxx Updated enum documentation with clearer descriptions
CSLib_DerivativeStatus.hxx Updated enum documentation with clearer descriptions
CSLib_NormalPolyDef.hxx Modernized signatures (int, double, bool) and added comprehensive documentation
CSLib_NormalPolyDef.cxx Fixed derivative bug (missing multiplication), modernized code with std:: functions
CSLib_Class2d.hxx Modernized signatures and added detailed documentation
CSLib_Class2d.cxx Fixed division-by-zero bug, removed dead code, modernized implementation
CSLib.hxx Modernized function signatures and added comprehensive documentation
CSLib.cxx Fixed status initialization bug, fixed sign change logic bug, replaced manual sort with std::sort

@dpasukhi
dpasukhi requested a review from Copilot November 26, 2025 16:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (1)

src/FoundationClasses/TKMath/GTests/CSLib_Test.cxx:1

  • The variable types Standard_Real should be replaced with double to follow the C++17 modernization guidelines.
// Copyright (c) 2025 OPEN CASCADE SAS

Comment on lines +37 to +39
void checkDirEqual(const gp_Dir& theDir1,
const gp_Dir& theDir2,
const Standard_Real theTolerance = 1e-10)

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter type Standard_Real should be replaced with double to follow the C++17 modernization guidelines. The function is a new helper in the test file and should use native types consistently.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +47 to +49
void checkVecEqual(const gp_Vec& theVec1,
const gp_Vec& theVec2,
const Standard_Real theTolerance = 1e-10)

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter type Standard_Real should be replaced with double to follow the C++17 modernization guidelines. The function is a new helper in the test file and should use native types consistently.

Copilot generated this review using guidance from repository custom instructions.

CSLib_NormalPolyDef aPoly(0, aLambda);

Standard_Real aValue;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.

CSLib_NormalPolyDef aPoly(1, aLambda);

Standard_Real aValue;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.

CSLib_NormalPolyDef aPoly(2, aLambda);

Standard_Real aValue;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.

CSLib_NormalPolyDef aPoly(2, aLambda);

Standard_Real aDeriv;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.

CSLib_NormalPolyDef aPoly(2, aLambda);

Standard_Real aDeriv;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +459 to +460
Standard_Real aF1, aD1;
Standard_Real aF2, aD2;

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable types Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.
EXPECT_TRUE(aPoly.Value(aX + aH, aFPlus));
EXPECT_TRUE(aPoly.Derivative(aX, aAnalyticDeriv));

const Standard_Real aNumericDeriv = (aFPlus - aFMinus) / (2.0 * aH);

Copilot AI Nov 26, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable type Standard_Real should be replaced with double to follow the C++17 modernization guidelines.

Copilot generated this review using guidance from repository custom instructions.
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib.cxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib.cxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib.cxx Outdated
i = 0;
Standard_Boolean definie = Standard_False;
while (i <= Order && !definie)
double r = aDerVec.Magnitude() / aVk0.Magnitude();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nondescript name that doesn't follow naming convention. Please, consider renaming.

Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.cxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.cxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.cxx Outdated
Comment thread src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.cxx Outdated
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Maintenance Dec 2, 2025
…erformance

- Updated CSLib_Class2d to enhance documentation and improve parameter types for constructors.
- Refined point classification methods with clearer return types and improved comments.
- Modified CSLib_DerivativeStatus to clarify the status of surface derivatives computation.
- Enhanced CSLib_NormalPolyDef for better readability and efficiency in polynomial evaluations.
- Updated CSLib_NormalStatus to provide clearer descriptions of normal computation statuses.
- Updated point classification methods to return clearer result types.
- Enhanced input validation and array management for polygon vertices.
- Improved documentation for methods and parameters.
- Refactored internal methods for consistency and readability.
- Changed test cases in CSLib_Class2dTest to utilize actual coordinates instead of normalized coordinates for point classification.
- Updated expected results to reflect the new testing approach, enhancing clarity and accuracy of the tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

src/FoundationClasses/TKMath/GTests/CSLib_Test.cxx:1

  • Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.
// Copyright (c) 2025 OPEN CASCADE SAS


CSLib_NormalPolyDef aPoly(1, aLambda);

Standard_Real aValue;

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.

Copilot uses AI. Check for mistakes.

CSLib_NormalPolyDef aPoly(2, aLambda);

Standard_Real aDeriv;

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.

Copilot uses AI. Check for mistakes.

CSLib_NormalPolyDef aPoly(2, aLambda);

Standard_Real aDeriv;

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.

Copilot uses AI. Check for mistakes.
Comment on lines +458 to +459
Standard_Real aF1, aD1;
Standard_Real aF2, aD2;

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.

Suggested change
Standard_Real aF1, aD1;
Standard_Real aF2, aD2;
double aF1, aD1;
double aF2, aD2;

Copilot uses AI. Check for mistakes.
Comment on lines +483 to +492
const Standard_Real aX = 0.8; // Away from singular points
const Standard_Real aH = 1e-6;

Standard_Real aFMinus, aFPlus, aAnalyticDeriv;

EXPECT_TRUE(aPoly.Value(aX - aH, aFMinus));
EXPECT_TRUE(aPoly.Value(aX + aH, aFPlus));
EXPECT_TRUE(aPoly.Derivative(aX, aAnalyticDeriv));

const Standard_Real aNumericDeriv = (aFPlus - aFMinus) / (2.0 * aH);

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple variable declarations use Standard_Real instead of double. For consistency with the modernization effort documented in the PR description, all test code should use native C++ types.

Suggested change
const Standard_Real aX = 0.8; // Away from singular points
const Standard_Real aH = 1e-6;
Standard_Real aFMinus, aFPlus, aAnalyticDeriv;
EXPECT_TRUE(aPoly.Value(aX - aH, aFMinus));
EXPECT_TRUE(aPoly.Value(aX + aH, aFPlus));
EXPECT_TRUE(aPoly.Derivative(aX, aAnalyticDeriv));
const Standard_Real aNumericDeriv = (aFPlus - aFMinus) / (2.0 * aH);
const double aX = 0.8; // Away from singular points
const double aH = 1e-6;
double aFMinus, aFPlus, aAnalyticDeriv;
EXPECT_TRUE(aPoly.Value(aX - aH, aFMinus));
EXPECT_TRUE(aPoly.Value(aX + aH, aFPlus));
EXPECT_TRUE(aPoly.Derivative(aX, aAnalyticDeriv));
const double aNumericDeriv = (aFPlus - aFMinus) / (2.0 * aH);

Copilot uses AI. Check for mistakes.
{
aSol(aRootIdx) = aFindRoots.Value(aRootIdx);
}
std::sort(&aSol(1), &aSol(aNbSol) + 1);

Copilot AI Dec 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement of manual insertion sort with std::sort() is a good modernization, but there's a potential issue: the code takes the address of array elements using &aSol(1) which works for TColStd_Array1OfReal but is not the most robust approach. Consider using std::sort(aSol.begin() + 1, aSol.begin() + aNbSol + 1) if TColStd_Array1OfReal provides iterators, or document why direct pointer arithmetic is safe here.

Suggested change
std::sort(&aSol(1), &aSol(aNbSol) + 1);
std::sort(aSol.begin() + 1, aSol.begin() + aNbSol + 1);

Copilot uses AI. Check for mistakes.
@dpasukhi
dpasukhi merged commit aa65507 into Open-Cascade-SAS:IR Dec 6, 2025
24 checks passed
@dpasukhi
dpasukhi deleted the cslib_impr branch December 6, 2025 00:34
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Maintenance Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Coding Coding rules, trivial changes and misprints 1. Foundation Classes Containers, system calls wrappers, smart pointers and other low level of OCCT code 2. Enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants