From 1109ff9e44696896bc346ab70441d4b706226b34 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Tue, 22 Nov 2022 11:30:20 +0100
Subject: [PATCH] little optimization for Cone

---
 Sample/HardParticle/Cone.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/Sample/HardParticle/Cone.cpp b/Sample/HardParticle/Cone.cpp
index 27eb4dde90a..479d3be49bd 100644
--- a/Sample/HardParticle/Cone.cpp
+++ b/Sample/HardParticle/Cone.cpp
@@ -38,23 +38,25 @@ Cone::Cone(double radius, double height, double alpha)
 complex_t Cone::formfactor_at_bottom(C3 q) const
 {
     ASSERT(m_validated);
+    const double R = m_radius;
+    const double H = m_height;
+
     if (std::abs(q.mag()) < std::numeric_limits<double>::epsilon()) {
-        double R = m_radius;
-        double H = m_height;
         if (m_cot_alpha == 0.0)
             return M_PI * R * R * H; // cylinder case
         double R2 = R - H * m_cot_alpha;
         double apex_height = R / m_cot_alpha;
         return M_PI / 3. * (R * R * H + (R * R - R2 * R2) * (apex_height - H));
     }
-    complex_t integral = ComplexIntegrator().integrate(
+
+    const complex_t q_p = std::sqrt(q.x() * q.x() + q.y() * q.y());
+
+    return M_TWOPI * ComplexIntegrator().integrate(
         [=](double Z) {
-            double Rz = m_radius - Z * m_cot_alpha;
-            complex_t q_p = std::sqrt(q.x() * q.x() + q.y() * q.y()); // sqrt(x*x + y*y)
+            const double Rz = R - Z * m_cot_alpha;
             return Rz * Rz * Math::Bessel::J1c(q_p * Rz) * exp_I(q.z() * Z);
         },
-        0., m_height);
-    return M_TWOPI * integral;
+        0., H);
 }
 
 std::string Cone::validate() const
-- 
GitLab