From 3f0880b40f9287eeb38ce834f4d567b5f00f4ba0 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 25 May 2022 22:38:49 +0200 Subject: [PATCH] prefer static c'tor fcts over complicated, similar c'tors --- Resample/Element/SpecularElement.cpp | 30 ++++++++++++++++++---------- Resample/Element/SpecularElement.h | 9 ++++++--- Sim/Scan/AlphaScan.cpp | 3 ++- Sim/Scan/QzScan.cpp | 3 ++- auto/Wrap/doxygenResample.i | 6 ------ 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Resample/Element/SpecularElement.cpp b/Resample/Element/SpecularElement.cpp index de01fe01e72..c3c3c0ea64b 100644 --- a/Resample/Element/SpecularElement.cpp +++ b/Resample/Element/SpecularElement.cpp @@ -16,23 +16,31 @@ #include "Base/Vector/Direction.h" #include "Resample/Slice/KzComputation.h" -SpecularElement::SpecularElement(double kz, const PolMatrices& polMatrices, bool computable) - : IElement(polMatrices) - , m_intensity(0.0) - , m_computable(computable) - , m_kz_computation( - [kz](const SliceStack& slices) { return Compute::Kz::computeKzFromSLDs(slices, kz); }) +SpecularElement SpecularElement::FromQzScan( + double kz, const PolMatrices& polMatrices, bool computable) +{ + return SpecularElement(computable, polMatrices, + [kz](const SliceStack& slices) { + return Compute::Kz::computeKzFromSLDs(slices, kz); + }); +} + +SpecularElement SpecularElement::FromAlphaScan( + double wavelength, double alpha, const PolMatrices& polMatrices, bool computable) { + return SpecularElement( + computable, polMatrices, + [k = vecOfLambdaAlphaPhi(wavelength, alpha, 0.0)](const SliceStack& slices) { + return Compute::Kz::computeKzFromRefIndices(slices, k); + }); } -SpecularElement::SpecularElement(double wavelength, double alpha, const PolMatrices& polMatrices, - bool computable) +SpecularElement::SpecularElement(bool computable, const PolMatrices& polMatrices, + std::function<std::vector<complex_t>(const SliceStack&)> kz_comp) : IElement(polMatrices) , m_intensity(0.0) , m_computable(computable) - , m_kz_computation([k = vecOfLambdaAlphaPhi(wavelength, alpha, 0.0)](const SliceStack& slices) { - return Compute::Kz::computeKzFromRefIndices(slices, k); - }) + , m_kz_computation(kz_comp) { } diff --git a/Resample/Element/SpecularElement.h b/Resample/Element/SpecularElement.h index 50078d6807b..b25c5465466 100644 --- a/Resample/Element/SpecularElement.h +++ b/Resample/Element/SpecularElement.h @@ -34,9 +34,9 @@ class SliceStack; class SpecularElement : public IElement { public: - SpecularElement(double kz, const PolMatrices& polMatrices, bool computable); - SpecularElement(double wavelength, double alpha, const PolMatrices& polMatrices, - bool computable); + static SpecularElement FromQzScan(double kz, const PolMatrices& polMatrices, bool computable); + static SpecularElement FromAlphaScan(double wavelength, double alpha, + const PolMatrices& polMatrices, bool computable); SpecularElement(const SpecularElement& other) = delete; SpecularElement(SpecularElement&& other); @@ -53,6 +53,9 @@ public: std::vector<complex_t> produceKz(const SliceStack& slices); private: + SpecularElement(bool computable, const PolMatrices& polMatrices, + std::function<std::vector<complex_t>(const SliceStack&)> kz_comp); + double m_intensity; //!< simulated intensity for detector cell const bool m_computable; const std::function<std::vector<complex_t>(const SliceStack&)> m_kz_computation; diff --git a/Sim/Scan/AlphaScan.cpp b/Sim/Scan/AlphaScan.cpp index db72883e07b..f10f5adb0a8 100644 --- a/Sim/Scan/AlphaScan.cpp +++ b/Sim/Scan/AlphaScan.cpp @@ -102,7 +102,8 @@ std::vector<SpecularElement> AlphaScan::generateElements() const for (size_t j = 0, size_wls = wls[i].size(); j < size_wls; ++j) { const double wl = wls[i][j]; result.emplace_back( - SpecularElement(wl, -inc, polMatrices(), wl >= 0 && inc >= 0 && inc <= M_PI_2)); + SpecularElement::FromAlphaScan( + wl, -inc, polMatrices(), wl >= 0 && inc >= 0 && inc <= M_PI_2)); } } } diff --git a/Sim/Scan/QzScan.cpp b/Sim/Scan/QzScan.cpp index eb12197f55d..163d1784d80 100644 --- a/Sim/Scan/QzScan.cpp +++ b/Sim/Scan/QzScan.cpp @@ -66,7 +66,8 @@ std::vector<SpecularElement> QzScan::generateElements() const std::vector<SpecularElement> result; result.reserve(qz.size()); for (size_t i = 0, size = qz.size(); i < size; ++i) - result.emplace_back(SpecularElement(-(qz[i] + m_offset) / 2.0, polMatrices(), qz[i] >= 0)); + result.emplace_back(SpecularElement::FromQzScan( + -(qz[i] + m_offset) / 2.0, polMatrices(), qz[i] >= 0)); return result; } diff --git a/auto/Wrap/doxygenResample.i b/auto/Wrap/doxygenResample.i index 9b78aae4632..955196c965f 100644 --- a/auto/Wrap/doxygenResample.i +++ b/auto/Wrap/doxygenResample.i @@ -911,12 +911,6 @@ Data stucture containing both input and output of a single image pixel for specu C++ includes: SpecularElement.h "; -%feature("docstring") SpecularElement::SpecularElement "SpecularElement::SpecularElement(double kz, const PolMatrices &polMatrices, bool computable) -"; - -%feature("docstring") SpecularElement::SpecularElement "SpecularElement::SpecularElement(double wavelength, double alpha, const PolMatrices &polMatrices, bool computable) -"; - %feature("docstring") SpecularElement::SpecularElement "SpecularElement::SpecularElement(const SpecularElement &other)=delete "; -- GitLab