1+ #pragma once
2+
3+ #include " TSignalLine.h"
4+
5+ #include < cstdint>
6+
7+ /* *
8+ * @enum IntegrationMethod
9+ * @brief Specifies the available methods for numerical integration.
10+ *
11+ * This enumeration defines several methods for performing numerical
12+ * integration:
13+ *
14+ * - `Trapezoidal`:
15+ * This method uses the trapezoidal rule for numerical integration. It
16+ * approximates the area under the curve by dividing the curve into trapezoids.
17+ * This method requires at least two points for computation and works well for
18+ * functions that are linear or approximately linear between points. The
19+ * trapezoidal rule calculates the area of each trapezoid and sums them up.
20+ * - Minimum points required: 2.
21+ *
22+ * - `Simpson`:
23+ * This method uses Simpson's rule, which is based on approximating the
24+ * function by a quadratic polynomial on each segment. It requires an odd number
25+ * of points (at least 3) because it calculates the area using pairs of
26+ * intervals, forming parabolic segments that give a higher level of accuracy
27+ * than the trapezoidal rule for smooth functions.
28+ * - Minimum points required: 3 (must be an odd number).
29+ *
30+ * - `Boole`:
31+ * This method uses Boole's rule (also known as the fifth-degree polynomial
32+ * rule), which is a higher-order numerical integration method. It approximates
33+ * the function using a polynomial of degree 5 on each segment. Boole's rule
34+ * requires that the number of points satisfies the condition \(4k + 1\),
35+ * meaning the number of points must be equal to 5, 9, 13, etc.
36+ * - Minimum points required: 5 (must satisfy \(4k + 1\) condition).
37+ */
38+ enum class IntegrationMethod : std::uint8_t {
39+ Trapezoidal, // /< Trapezoidal rule (requires at least 2 points).
40+ Simpson, // /< Simpson's rule (requires at least 3 points, and the number must
41+ // /< be odd).
42+ Boole // /< Boole's rule (requires at least 5 points, and the number must
43+ // /< satisfy 4k + 1).
44+ };
45+
46+ /* *
47+ * @struct TIntegratorParams
48+ * @brief Defines the parameters used for numerical integration.
49+ */
50+ struct TIntegratorParams {
51+ const TSignalLine* signalLine =
52+ nullptr ; // /< Pointer to the signal line to be integrated.
53+ IntegrationMethod method =
54+ IntegrationMethod::Trapezoidal; // /< (optional) Integration method.
55+ };
56+
57+ /* *
58+ * @class TIntegrator
59+ * @brief Class for performing numerical integration on a signal line.
60+ */
61+ class TIntegrator {
62+ public:
63+ /* *
64+ * @brief Constructs a TIntegrator with a signal line and an integration
65+ * method.
66+ *
67+ * @param signalLine Pointer to the signal line to integrate.
68+ * @param method (optional) The method to use for integration.
69+ */
70+ TIntegrator (const TSignalLine* signalLine,
71+ IntegrationMethod method = IntegrationMethod::Trapezoidal);
72+
73+ /* *
74+ * @brief Constructs a TIntegrator with integration parameters.
75+ *
76+ * @param params Structure containing the parameters for signal integration.
77+ */
78+ TIntegrator (TIntegratorParams params);
79+
80+ /* *
81+ * @brief Default destructor.
82+ */
83+ ~TIntegrator () = default ;
84+
85+ /* *
86+ * @brief Default copy constructor.
87+ */
88+ TIntegrator (const TIntegrator&) = default ;
89+
90+ /* *
91+ * @brief Default move constructor.
92+ */
93+ TIntegrator (TIntegrator&&) noexcept = default ;
94+
95+ /* *
96+ * @brief Default copy assignment operator.
97+ */
98+ TIntegrator& operator =(const TIntegrator&) = default ;
99+
100+ /* *
101+ * @brief Default move assignment operator.
102+ */
103+ TIntegrator& operator =(TIntegrator&&) noexcept = default ;
104+
105+ /* *
106+ * @brief Retrieves the computed integral.
107+ *
108+ * @return double The result of the numerical integration.
109+ */
110+ [[nodiscard]] double getIntegral () const ;
111+
112+ /* *
113+ * @brief Retrieves the parameters used for integration.
114+ *
115+ * @return const TIntegratorParams& Reference to the integration parameters.
116+ */
117+ [[nodiscard]] const TIntegratorParams& getParams () const ;
118+
119+ /* *
120+ * @brief Checks whether the integration has been executed.
121+ *
122+ * @return bool True if the integration process has been executed, false
123+ * otherwise.
124+ */
125+ [[nodiscard]] bool isExecuted () const ;
126+
127+ /* *
128+ * @brief Executes the numerical integration of the signal line.
129+ */
130+ void execute ();
131+
132+ private:
133+ double _integral = 0.0 ; // /< Stores the computed integral value.
134+ TIntegratorParams _params = {}; // /< Parameters for integration.
135+ bool _isExecuted =
136+ false ; // /< Indicates if the integration has been executed.
137+ };
0 commit comments