Files
OCCT/tests/bugs
Pasukhin Dmitry 7295facb87 Modeling Data, Algorithms - Add std::optional evaluation API to Geom/Geom2d/Surface hierarchies (#1064)
Introduce exception-safe evaluation methods (EvalD0/EvalD1/EvalD2/EvalD3/EvalDN) returning std::optional across the entire Geom_Curve, Geom2d_Curve, and Geom_Surface class hierarchies. These replace the old throwing D0/D1/D2/D3/DN as the primary virtual dispatch points. The old output-parameter methods are retained as non-virtual inline backward-compatible wrappers that throw on failure.

Key design decisions:
- std::optional<T> chosen over embedded-bool structs: identical performance (same 8-byte alignment overhead for POD types), but provides standard C++17 vocabulary, sanitizer-detectable invalid access, and natural return of gp_Pnt for D0 / gp_Vec for DN without wrapper types.
- NRVO optimization: always-succeeding classes (25 of 29) use std::optional<T>{std::in_place} as the local variable, enabling Named Return Value Optimization for zero-copy returns. Failure-path classes (Offset*, GeomPlate, Bisectors) retain early-return std::nullopt pattern.

New headers:
- Geom.hxx: POD result structs Geom_CurveD1/D2/D3, Geom_SurfD1/D2/D3 bundling point + derivative vectors for 3D curves and surfaces.
- Geom2d.hxx: POD result structs Geom2d_CurveD1/D2/D3 for 2D curves.

Base class changes (Geom_Curve, Geom_Surface, Geom2d_Curve):
- New pure virtual EvalD0/EvalD1/EvalD2/EvalD3/EvalDN returning std::optional; std::nullopt signals evaluation failure without exceptions.
- Old void D0(U,P) / void D1(U,P,V1) / gp_Vec DN(U,N) etc. become non-virtual inline wrappers that throw Geom_UndefinedValue/Geom_UndefinedDerivative on nullopt, preserving all existing call sites unchanged.

Leaf class implementations (32 classes, 87 files):
- 7 Geom_Curve leaves: Line, Circle, Ellipse, Hyperbola, Parabola, BSplineCurve, BezierCurve - always succeed, NRVO-optimized.
- 2 Geom_Curve delegators: TrimmedCurve, OffsetCurve - forward to basis curve.
- 11 Geom_Surface leaves: Plane, CylindricalSurface, ConicalSurface, SphericalSurface, ToroidalSurface, BSplineSurface, BezierSurface, SurfaceOfLinearExtrusion, SurfaceOfRevolution - always succeed, NRVO-optimized.
- 2 Geom_Surface delegators: RectangularTrimmedSurface, OffsetSurface.
- 7 Geom2d_Curve leaves: Line, Circle, Ellipse, Hyperbola, Parabola, BSplineCurve, BezierCurve - always succeed, NRVO-optimized.
- 2 Geom2d_Curve delegators: TrimmedCurve, OffsetCurve.
- 3 external subclasses: Bisector_BisecAna, Bisector_BisecCC, Bisector_BisecPC, ShapeExtend_ComplexCurve, ShapeExtend_CompositeSurface, GeomPlate_Surface.

Additional changes:
- GeomGridEval.hxx: replaced duplicated struct definitions with type aliases (using CurveD1 = Geom_CurveD1, etc.).
- GeomAdaptor_Surface.cxx: updated to use new EvalD* API.

GTests added (3 files, 15 test cases):
- Geom_CurveEval_Test.cxx: Circle D0/D1/D2/D3, Line D2, BSpline consistency with old API, EvalDN vs EvalD1 consistency, OffsetCurve nullopt/throw paths.
- Geom_SurfaceEval_Test.cxx: Plane D0/D1, Sphere D1, BSplineSurface D2 consistency with old API, OffsetSurface on regular surface.
- Geom2d_CurveEval_Test.cxx: Circle D0/D1, OffsetCurve nullopt path, BSpline consistency with old API.
2026-02-13 16:08:55 +00:00
..
2018-11-02 17:06:40 +03:00