| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "dergynov_s_trapezoid_integration/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include "dergynov_s_trapezoid_integration/common/include/common.hpp" | ||
| 4 | |||
| 5 | namespace dergynov_s_trapezoid_integration { | ||
| 6 | |||
| 7 | ✗ | DergynovSTrapezoidIntegrationSEQ::DergynovSTrapezoidIntegrationSEQ(const InType &in) { | |
| 8 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 9 | ✗ | GetInput() = in; | |
| 10 | GetOutput() = 0.0; | ||
| 11 | ✗ | } | |
| 12 | |||
| 13 | ✗ | bool DergynovSTrapezoidIntegrationSEQ::ValidationImpl() { | |
| 14 | const auto &in = GetInput(); | ||
| 15 | ✗ | return (in.n > 0) && (in.a < in.b) && IsValidFunctionId(in.func_id); | |
| 16 | } | ||
| 17 | |||
| 18 | ✗ | bool DergynovSTrapezoidIntegrationSEQ::PreProcessingImpl() { | |
| 19 | ✗ | GetOutput() = 0.0; | |
| 20 | ✗ | return true; | |
| 21 | } | ||
| 22 | |||
| 23 | ✗ | bool DergynovSTrapezoidIntegrationSEQ::RunImpl() { | |
| 24 | const auto &in = GetInput(); | ||
| 25 | |||
| 26 | ✗ | const double a = in.a; | |
| 27 | ✗ | const double b = in.b; | |
| 28 | ✗ | const int n = in.n; | |
| 29 | |||
| 30 | ✗ | if (n <= 0 || !(a < b)) { | |
| 31 | return false; | ||
| 32 | } | ||
| 33 | |||
| 34 | ✗ | const double h = (b - a) / static_cast<double>(n); | |
| 35 | |||
| 36 | double sum = 0.0; | ||
| 37 | ✗ | for (int i = 1; i < n; ++i) { | |
| 38 | ✗ | sum += Function(a + (h * i), in.func_id); | |
| 39 | } | ||
| 40 | |||
| 41 | ✗ | GetOutput() = h * (0.5 * (Function(a, in.func_id) + Function(b, in.func_id)) + sum); | |
| 42 | |||
| 43 | ✗ | return true; | |
| 44 | } | ||
| 45 | |||
| 46 | ✗ | bool DergynovSTrapezoidIntegrationSEQ::PostProcessingImpl() { | |
| 47 | ✗ | return true; | |
| 48 | } | ||
| 49 | |||
| 50 | } // namespace dergynov_s_trapezoid_integration | ||
| 51 |