Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:02

0001 // Copyright (c) 2025 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Geom2dEval_RepCurveDesc_HeaderFile
0015 #define _Geom2dEval_RepCurveDesc_HeaderFile
0016 
0017 #include <Geom2d_Curve.hxx>
0018 #include <Precision.hxx>
0019 #include <Standard_Transient.hxx>
0020 
0021 #include <cmath>
0022 #include <cstddef>
0023 #include <optional>
0024 
0025 namespace Geom2dEval_RepCurveDesc
0026 {
0027 //! 1D affine parameter map: uRep = Scale * u + Offset.
0028 struct Map1d
0029 {
0030   double Scale  = 1.0;
0031   double Offset = 0.0;
0032 
0033   bool IsIdentity() const
0034   {
0035     return std::abs(Scale - 1.0) < Precision::Confusion()
0036            && std::abs(Offset) < Precision::Confusion();
0037   }
0038 
0039   bool IsValid() const { return std::abs(Scale) > Precision::Confusion(); }
0040 
0041   double Map(const double theU) const { return Scale * theU + Offset; }
0042 };
0043 
0044 //! 1D parameter domain interval.
0045 struct Domain1d
0046 {
0047   double First = 0.0;
0048   double Last  = 1.0;
0049 
0050   bool Contains(const double theU) const
0051   {
0052     return (theU >= First - Precision::Confusion()) && (theU <= Last + Precision::Confusion());
0053   }
0054 };
0055 
0056 //! Abstract base descriptor for 2D curve evaluation representation.
0057 //! Holds the representation handle and a Kind tag for switch-based dispatch.
0058 class Base : public Standard_Transient
0059 {
0060 public:
0061   //! Descriptor kind for switch-based dispatch (no RTTI needed).
0062   enum class Kind
0063   {
0064     Full,         //!< fully equivalent, no derivative limit, no domain, no map
0065     DerivBounded, //!< full domain + identity map, limited to MaxDerivOrder
0066     Mapped        //!< has MaxDerivOrder + optional Domain + ParamMap
0067   };
0068 
0069   occ::handle<Geom2d_Curve> Representation; //!< geometry used for evaluation
0070 
0071   //! Returns the descriptor kind.
0072   virtual Kind GetKind() const = 0;
0073 
0074   DEFINE_STANDARD_RTTI_INLINE(Base, Standard_Transient)
0075 
0076 protected:
0077   Base() = default;
0078 };
0079 
0080 //! Fully equivalent descriptor: no derivative limit, no domain, no map.
0081 //! Fastest evaluation path - direct delegation to Representation.
0082 class Full : public Base
0083 {
0084 public:
0085   Kind GetKind() const override { return Kind::Full; }
0086 
0087   DEFINE_STANDARD_RTTI_INLINE(Full, Base)
0088 };
0089 
0090 //! Derivative-bounded descriptor: full domain, identity map, limited to MaxDerivOrder.
0091 class DerivBounded : public Base
0092 {
0093 public:
0094   std::size_t MaxDerivOrder = 3; //!< max supported derivative order
0095 
0096   Kind GetKind() const override { return Kind::DerivBounded; }
0097 
0098   DEFINE_STANDARD_RTTI_INLINE(DerivBounded, Base)
0099 };
0100 
0101 //! Mapped descriptor for 2D curve evaluation representation.
0102 //! Adds optional bounded domain and affine parameter map.
0103 class Mapped : public Base
0104 {
0105 public:
0106   std::size_t             MaxDerivOrder = 3; //!< max supported derivative order
0107   std::optional<Domain1d> Domain;            //!< nullopt = full domain
0108   Map1d                   ParamMap;          //!< affine parameter transform
0109 
0110   Kind GetKind() const override { return Kind::Mapped; }
0111 
0112   DEFINE_STANDARD_RTTI_INLINE(Mapped, Base)
0113 };
0114 } // namespace Geom2dEval_RepCurveDesc
0115 
0116 #endif // _Geom2dEval_RepCurveDesc_HeaderFile