From a47bb66b221a8f8fe2e1eeb0a17e2fbb2db291c8 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 2 Dec 2021 16:14:33 +0100
Subject: [PATCH] rm unused c'tor (and a few trivial tests along)

---
 Sample/Particle/Particle.cpp                  | 10 +----
 Sample/Particle/Particle.h                    |  1 -
 Tests/Unit/Core/ParticleLayoutTest.cpp        | 41 ++++++++++-------
 Tests/Unit/Sample/ParticleCompositionTest.cpp |  3 +-
 Tests/Unit/Sample/ParticleCoreShellTest.cpp   | 27 +----------
 auto/Wrap/libBornAgainSample.py               |  1 -
 auto/Wrap/libBornAgainSample_wrap.cpp         | 45 ++-----------------
 7 files changed, 34 insertions(+), 94 deletions(-)

diff --git a/Sample/Particle/Particle.cpp b/Sample/Particle/Particle.cpp
index 2f81971aedf..6207f51f315 100644
--- a/Sample/Particle/Particle.cpp
+++ b/Sample/Particle/Particle.cpp
@@ -23,11 +23,6 @@
 
 Particle::~Particle() = default;
 
-Particle::Particle(Material material) : m_material(std::move(material))
-{
-    initialize();
-}
-
 Particle::Particle(Material material, const IFormFactor& form_factor)
     : m_material(std::move(material)), m_form_factor(form_factor.clone())
 {
@@ -43,10 +38,9 @@ Particle::Particle(Material material, const IFormFactor& form_factor, const IRot
 
 Particle* Particle::clone() const
 {
-    auto* p_result = new Particle(m_material);
+    ASSERT(m_form_factor);
+    auto* p_result = new Particle(m_material, *m_form_factor);
     p_result->setAbundance(m_abundance);
-    if (m_form_factor)
-        p_result->setFormFactor(*m_form_factor);
     if (m_rotation)
         p_result->setRotation(*m_rotation);
     p_result->setPosition(m_position);
diff --git a/Sample/Particle/Particle.h b/Sample/Particle/Particle.h
index 136a1a9c5d4..c3e56ed9344 100644
--- a/Sample/Particle/Particle.h
+++ b/Sample/Particle/Particle.h
@@ -25,7 +25,6 @@ class Particle : public IParticle {
 public:
     std::string className() const override { return "Particle"; }
 
-    Particle(Material material);
     Particle(Material material, const IFormFactor& form_factor);
     Particle(Material material, const IFormFactor& form_factor, const IRotation& rotation);
     ~Particle() override;
diff --git a/Tests/Unit/Core/ParticleLayoutTest.cpp b/Tests/Unit/Core/ParticleLayoutTest.cpp
index cf2f70ec5f3..fc20d959cfe 100644
--- a/Tests/Unit/Core/ParticleLayoutTest.cpp
+++ b/Tests/Unit/Core/ParticleLayoutTest.cpp
@@ -3,6 +3,7 @@
 #include "Param/Node/NodeUtils.h"
 #include "Sample/Aggregate/Interference1DLattice.h"
 #include "Sample/Aggregate/InterferenceNone.h"
+#include "Sample/HardParticle/FormFactorFullSphere.h"
 #include "Sample/Material/MaterialFactoryFuncs.h"
 #include "Sample/Particle/Particle.h"
 #include "Tests/GTestWrapper/google_test.h"
@@ -23,7 +24,9 @@ TEST_F(ParticleLayoutTest, ParticleLayoutInitial)
 
 TEST_F(ParticleLayoutTest, ParticleLayoutInitByValue)
 {
-    Particle particle(HomogeneousMaterial());
+    FormFactorFullSphere ff(5.);
+
+    Particle particle(HomogeneousMaterial(), ff);
 
     ParticleLayout particleDecoration(particle, 2.0);
     const auto* p_iff = NodeUtils::OnlyChildOfType<IInterference>(particleDecoration);
@@ -40,10 +43,12 @@ TEST_F(ParticleLayoutTest, ParticleLayoutAddParticle)
 {
     ParticleLayout particleDecoration;
 
-    Particle particle1(HomogeneousMaterial());
-    Particle particle2(HomogeneousMaterial());
-    Particle particle3(HomogeneousMaterial());
-    Particle particle4(HomogeneousMaterial());
+    FormFactorFullSphere ff(5.);
+
+    Particle particle1(HomogeneousMaterial(), ff);
+    Particle particle2(HomogeneousMaterial(), ff);
+    Particle particle3(HomogeneousMaterial(), ff);
+    Particle particle4(HomogeneousMaterial(), ff);
 
     RotationZ transform3(45. * Units::deg);
     RotationZ transform4(45. * Units::deg);
@@ -77,10 +82,12 @@ TEST_F(ParticleLayoutTest, ParticleLayoutAbundanceFraction)
 {
     ParticleLayout particleDecoration;
 
-    Particle particle1(HomogeneousMaterial());
-    Particle particle2(HomogeneousMaterial());
-    Particle particle3(HomogeneousMaterial());
-    Particle particle4(HomogeneousMaterial());
+    FormFactorFullSphere ff(5.);
+
+    Particle particle1(HomogeneousMaterial(), ff);
+    Particle particle2(HomogeneousMaterial(), ff);
+    Particle particle3(HomogeneousMaterial(), ff);
+    Particle particle4(HomogeneousMaterial(), ff);
 
     RotationY transform3(45. * Units::deg);
     RotationZ transform4(45. * Units::deg);
@@ -96,10 +103,12 @@ TEST_F(ParticleLayoutTest, ParticleLayoutClone)
 {
     ParticleLayout particleDecoration;
 
-    Particle particle1(HomogeneousMaterial());
-    Particle particle2(HomogeneousMaterial());
-    Particle particle3(HomogeneousMaterial());
-    Particle particle4(HomogeneousMaterial());
+    FormFactorFullSphere ff(5.);
+
+    Particle particle1(HomogeneousMaterial(), ff);
+    Particle particle2(HomogeneousMaterial(), ff);
+    Particle particle3(HomogeneousMaterial(), ff);
+    Particle particle4(HomogeneousMaterial(), ff);
 
     RotationY transform3(45. * Units::deg);
     RotationZ transform4(45. * Units::deg);
@@ -110,7 +119,7 @@ TEST_F(ParticleLayoutTest, ParticleLayoutClone)
     particleDecoration.addParticle(particle4, 4.0, R3(0, 0, 0), transform4);
 
     Material mat5 = HomogeneousMaterial("core", 0, 0);
-    Particle particle5(mat5);
+    Particle particle5(mat5, ff);
     particleDecoration.addParticle(particle5, 0.0);
 
     InterferenceNone iff_none;
@@ -164,7 +173,9 @@ TEST_F(ParticleLayoutTest, getChildren)
     std::vector<const INode*> children = layout.getChildren();
     EXPECT_EQ(children.size(), 0u);
 
-    layout.addParticle(Particle(HomogeneousMaterial()));
+    FormFactorFullSphere ff(5.);
+
+    layout.addParticle(Particle(HomogeneousMaterial(), ff));
     layout.setInterference(Interference1DLattice(1.0, 2.0));
     children = layout.getChildren();
     EXPECT_EQ(children.size(), 2u);
diff --git a/Tests/Unit/Sample/ParticleCompositionTest.cpp b/Tests/Unit/Sample/ParticleCompositionTest.cpp
index 5eee24e7f11..1edc5085e33 100644
--- a/Tests/Unit/Sample/ParticleCompositionTest.cpp
+++ b/Tests/Unit/Sample/ParticleCompositionTest.cpp
@@ -22,7 +22,8 @@ TEST_F(ParticleCompositionTest, ParticleCompositionClone)
     ParticleComposition composition;
     R3 position = R3(1.0, 1.0, 1.0);
     Material material = HomogeneousMaterial("Vacuum", 0.0, 0.0);
-    Particle particle(material);
+    FormFactorFullSphere ff(5.);
+    Particle particle(material, ff);
     composition.addParticle(particle, position);
 
     std::unique_ptr<ParticleComposition> clone(composition.clone());
diff --git a/Tests/Unit/Sample/ParticleCoreShellTest.cpp b/Tests/Unit/Sample/ParticleCoreShellTest.cpp
index f1168a4e978..7cacedcddc3 100644
--- a/Tests/Unit/Sample/ParticleCoreShellTest.cpp
+++ b/Tests/Unit/Sample/ParticleCoreShellTest.cpp
@@ -7,32 +7,7 @@
 #include "Sample/Scattering/Rotations.h"
 #include "Tests/GTestWrapper/google_test.h"
 
-class ParticleCoreShellTest : public ::testing::Test {
-protected:
-    ParticleCoreShellTest();
-    ~ParticleCoreShellTest() override;
-
-    ParticleCoreShell* m_coreshell{nullptr};
-};
-
-ParticleCoreShellTest::ParticleCoreShellTest() : m_coreshell(nullptr)
-{
-    Material mat = HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7);
-    Particle core(mat);
-    Particle shell(mat);
-    R3 position;
-    m_coreshell = new ParticleCoreShell(shell, core, position);
-}
-
-ParticleCoreShellTest::~ParticleCoreShellTest()
-{
-    delete m_coreshell;
-}
-
-TEST_F(ParticleCoreShellTest, InitialState)
-{
-    EXPECT_EQ(nullptr, m_coreshell->rotation());
-}
+class ParticleCoreShellTest : public ::testing::Test {};
 
 TEST_F(ParticleCoreShellTest, ComplexCoreShellClone)
 {
diff --git a/auto/Wrap/libBornAgainSample.py b/auto/Wrap/libBornAgainSample.py
index a39f37d3c18..5acd990c5fd 100644
--- a/auto/Wrap/libBornAgainSample.py
+++ b/auto/Wrap/libBornAgainSample.py
@@ -4720,7 +4720,6 @@ class Particle(IParticle):
 
     def __init__(self, *args):
         r"""
-        __init__(Particle self, Material material) -> Particle
         __init__(Particle self, Material material, IFormFactor form_factor) -> Particle
         __init__(Particle self, Material material, IFormFactor form_factor, IRotation rotation) -> Particle
         Particle::Particle(Material material, const IFormFactor &form_factor, const IRotation &rotation)
diff --git a/auto/Wrap/libBornAgainSample_wrap.cpp b/auto/Wrap/libBornAgainSample_wrap.cpp
index 4042bfba724..e354d2abc6a 100644
--- a/auto/Wrap/libBornAgainSample_wrap.cpp
+++ b/auto/Wrap/libBornAgainSample_wrap.cpp
@@ -45159,35 +45159,6 @@ fail:
 
 
 SWIGINTERN PyObject *_wrap_new_Particle__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
-  PyObject *resultobj = 0;
-  SwigValueWrapper< Material > arg1 ;
-  void *argp1 ;
-  int res1 = 0 ;
-  Particle *result = 0 ;
-  
-  if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
-  {
-    res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_Material,  0  | 0);
-    if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Particle" "', argument " "1"" of type '" "Material""'"); 
-    }  
-    if (!argp1) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_Particle" "', argument " "1"" of type '" "Material""'");
-    } else {
-      Material * temp = reinterpret_cast< Material * >(argp1);
-      arg1 = *temp;
-      if (SWIG_IsNewObj(res1)) delete temp;
-    }
-  }
-  result = (Particle *)new Particle(arg1);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Particle, SWIG_POINTER_NEW |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_new_Particle__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   SwigValueWrapper< Material > arg1 ;
   IFormFactor *arg2 = 0 ;
@@ -45227,7 +45198,7 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_new_Particle__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_new_Particle__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   SwigValueWrapper< Material > arg1 ;
   IFormFactor *arg2 = 0 ;
@@ -45286,14 +45257,6 @@ SWIGINTERN PyObject *_wrap_new_Particle(PyObject *self, PyObject *args) {
   
   if (!(argc = SWIG_Python_UnpackTuple(args, "new_Particle", 0, 3, argv))) SWIG_fail;
   --argc;
-  if (argc == 1) {
-    int _v;
-    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_Material, SWIG_POINTER_NO_NULL | 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      return _wrap_new_Particle__SWIG_0(self, argc, argv);
-    }
-  }
   if (argc == 2) {
     int _v;
     int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_Material, SWIG_POINTER_NO_NULL | 0);
@@ -45302,7 +45265,7 @@ SWIGINTERN PyObject *_wrap_new_Particle(PyObject *self, PyObject *args) {
       int res = SWIG_ConvertPtr(argv[1], 0, SWIGTYPE_p_IFormFactor, SWIG_POINTER_NO_NULL | 0);
       _v = SWIG_CheckState(res);
       if (_v) {
-        return _wrap_new_Particle__SWIG_1(self, argc, argv);
+        return _wrap_new_Particle__SWIG_0(self, argc, argv);
       }
     }
   }
@@ -45317,7 +45280,7 @@ SWIGINTERN PyObject *_wrap_new_Particle(PyObject *self, PyObject *args) {
         int res = SWIG_ConvertPtr(argv[2], 0, SWIGTYPE_p_IRotation, SWIG_POINTER_NO_NULL | 0);
         _v = SWIG_CheckState(res);
         if (_v) {
-          return _wrap_new_Particle__SWIG_2(self, argc, argv);
+          return _wrap_new_Particle__SWIG_1(self, argc, argv);
         }
       }
     }
@@ -45326,7 +45289,6 @@ SWIGINTERN PyObject *_wrap_new_Particle(PyObject *self, PyObject *args) {
 fail:
   SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_Particle'.\n"
     "  Possible C/C++ prototypes are:\n"
-    "    Particle::Particle(Material)\n"
     "    Particle::Particle(Material,IFormFactor const &)\n"
     "    Particle::Particle(Material,IFormFactor const &,IRotation const &)\n");
   return 0;
@@ -72888,7 +72850,6 @@ static PyMethodDef SwigMethods[] = {
 		"\n"
 		""},
 	 { "new_Particle", _wrap_new_Particle, METH_VARARGS, "\n"
-		"Particle(Material material)\n"
 		"Particle(Material material, IFormFactor form_factor)\n"
 		"new_Particle(Material material, IFormFactor form_factor, IRotation rotation) -> Particle\n"
 		"Particle::Particle(Material material, const IFormFactor &form_factor, const IRotation &rotation)\n"
-- 
GitLab