From 1ec6e40d0cee9e8cbec7eabd453ca3eb0c561828 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Mon, 16 Nov 2020 13:02:28 +0100
Subject: [PATCH] InterferenceFunction2DLattice: retain only c'tor with
 Lattice2D argument

---
 Core/Export/SampleToPython.cpp                |  17 ++-
 .../CosineRipplesAtRectLattice.py             |   2 +-
 .../TriangularRipple.py                       |   2 +-
 .../InterferenceFunction2DLattice.cpp         |  11 --
 .../Aggregate/InterferenceFunction2DLattice.h |   1 -
 .../Performance/Core/ThreadingComponents.cpp  |   4 +-
 .../Core/Sample/MultilayerAveragingTest.cpp   |   4 +-
 auto/Wrap/doxygenSample.i                     |  20 ----
 auto/Wrap/libBornAgainSample.py               |   5 +-
 auto/Wrap/libBornAgainSample_wrap.cpp         | 108 +-----------------
 10 files changed, 24 insertions(+), 150 deletions(-)

diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp
index 0cb61951bbb..9b31c0b0da8 100644
--- a/Core/Export/SampleToPython.cpp
+++ b/Core/Export/SampleToPython.cpp
@@ -302,7 +302,7 @@ std::string SampleToPython::defineLattices2D() const
         result << indent() << indent() << pyfmt::printNm(lattice->length1()) << ", "
                << pyfmt::printNm(lattice->length2()) << ", "
                << pyfmt::printDegrees(lattice->latticeAngle()) << ", "
-               << pyfmt::printDegrees(lattice->rotationAngle()) << "),\n";
+               << pyfmt::printDegrees(lattice->rotationAngle()) << ")\n";
     }
     return result.str();
 }
@@ -391,6 +391,7 @@ std::string SampleToPython::defineInterferenceFunctions() const
 
         if (dynamic_cast<const InterferenceFunctionNone*>(interference))
             result << indent() << it->second << " = ba.InterferenceFunctionNone()\n";
+
         else if (const auto* iff =
                      dynamic_cast<const InterferenceFunction1DLattice*>(interference)) {
             result << indent() << it->second << " = ba.InterferenceFunction1DLattice("
@@ -403,6 +404,7 @@ std::string SampleToPython::defineInterferenceFunctions() const
                 result << indent() << it->second << "_pdf  = ba." << pdf->getName() << "("
                        << pyfmt2::argumentList(pdf) << ")\n"
                        << indent() << it->second << ".setDecayFunction(" << it->second << "_pdf)\n";
+
         } else if (const auto* iff =
                        dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(interference)) {
             result << indent() << it->second << " = ba.InterferenceFunctionRadialParaCrystal("
@@ -424,15 +426,13 @@ std::string SampleToPython::defineInterferenceFunctions() const
                        << pyfmt2::argumentList(pdf) << ")\n"
                        << indent() << it->second << ".setProbabilityDistribution(" << it->second
                        << "_pdf)\n";
+
         } else if (const auto* iff =
                        dynamic_cast<const InterferenceFunction2DLattice*>(interference)) {
-            const Lattice2D& lattice = iff->lattice();
-            // const auto* lattice = INodeUtils::OnlyChildOfType<Lattice2D>(*iff);
+            const auto* lattice = INodeUtils::OnlyChildOfType<Lattice2D>(*iff);
 
             result << indent() << it->second << " = ba.InterferenceFunction2DLattice("
-                   << pyfmt::printNm(lattice.length1()) << ", " << pyfmt::printNm(lattice.length2())
-                   << ", " << pyfmt::printDegrees(lattice.latticeAngle()) << ", "
-                   << pyfmt::printDegrees(lattice.rotationAngle()) << ")\n";
+                   << m_label->labelLattice2D(lattice) << ")\n";
 
             const auto* pdf = INodeUtils::OnlyChildOfType<IFTDecayFunction2D>(*iff);
 
@@ -442,6 +442,7 @@ std::string SampleToPython::defineInterferenceFunctions() const
 
             if (iff->integrationOverXi() == true)
                 result << indent() << it->second << ".setIntegrationOverXi(True)\n";
+
         } else if (const auto* iff =
                        dynamic_cast<const InterferenceFunctionFinite2DLattice*>(interference)) {
             const Lattice2D& lattice = iff->lattice();
@@ -453,6 +454,7 @@ std::string SampleToPython::defineInterferenceFunctions() const
 
             if (iff->integrationOverXi() == true)
                 result << indent() << it->second << ".setIntegrationOverXi(True)\n";
+
         } else if (const auto* iff =
                        dynamic_cast<const InterferenceFunction2DParaCrystal*>(interference)) {
             std::vector<double> domainSize = iff->domainSizes();
@@ -484,16 +486,19 @@ std::string SampleToPython::defineInterferenceFunctions() const
                    << pyfmt2::argumentList(pdf) << ")\n";
             result << indent() << it->second << ".setProbabilityDistributions(" << it->second
                    << "_pdf_1, " << it->second << "_pdf_2)\n";
+
         } else if (const auto* lattice_hd =
                        dynamic_cast<const InterferenceFunctionHardDisk*>(interference)) {
             result << indent() << it->second << " = ba.InterferenceFunctionHardDisk("
                    << pyfmt::printNm(lattice_hd->radius()) << ", "
                    << pyfmt::printDouble(lattice_hd->density()) << ")\n";
+
         } else
             throw Exceptions::NotImplementedException(
                 "Bug: ExportToPython::defineInterferenceFunctions() called with unexpected "
                 "IInterferenceFunction "
                 + interference->getName());
+
         if (interference->positionVariance() > 0.0) {
             result << indent() << it->second << ".setPositionVariance("
                    << pyfmt::printNm2(interference->positionVariance()) << ")\n";
diff --git a/Examples/python/simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice.py b/Examples/python/simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice.py
index 763fc30f52c..d0d89b53505 100644
--- a/Examples/python/simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice.py
+++ b/Examples/python/simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice.py
@@ -24,7 +24,7 @@ def get_sample():
     particle_layout.addParticle(particle, 1.0)
 
     interference = ba.InterferenceFunction2DLattice(
-        200.0*nm, 50.0*nm, 90.0*deg, 0.0*deg)
+        ba.BasicLattice(200.0*nm, 50.0*nm, 90.0*deg, 0.0*deg))
     pdf = ba.FTDecayFunction2DCauchy(1000.*nm/2./numpy.pi, 100.*nm/2./numpy.pi, 0)
     interference.setDecayFunction(pdf)
     particle_layout.setInterferenceFunction(interference)
diff --git a/Examples/python/simulation/ex03_InterferenceFunctions/TriangularRipple.py b/Examples/python/simulation/ex03_InterferenceFunctions/TriangularRipple.py
index ea813a7fc43..c9d4ea1a9a0 100644
--- a/Examples/python/simulation/ex03_InterferenceFunctions/TriangularRipple.py
+++ b/Examples/python/simulation/ex03_InterferenceFunctions/TriangularRipple.py
@@ -25,7 +25,7 @@ def get_sample():
     particle_layout.addParticle(ripple, 1.0)
 
     interference = ba.InterferenceFunction2DLattice(
-        200.0*nm, 50.0*nm, 90.0*deg, 0.0*deg)
+        ba.BasicLattice(200.0*nm, 50.0*nm, 90.0*deg, 0.0*deg))
     pdf = ba.FTDecayFunction2DGauss(1000.*nm/2./numpy.pi, 100.*nm/2./numpy.pi, 0)
     interference.setDecayFunction(pdf)
     particle_layout.setInterferenceFunction(interference)
diff --git a/Sample/Aggregate/InterferenceFunction2DLattice.cpp b/Sample/Aggregate/InterferenceFunction2DLattice.cpp
index afcb51ec7ef..86419028a95 100644
--- a/Sample/Aggregate/InterferenceFunction2DLattice.cpp
+++ b/Sample/Aggregate/InterferenceFunction2DLattice.cpp
@@ -35,17 +35,6 @@ InterferenceFunction2DLattice::InterferenceFunction2DLattice(const Lattice2D& la
     initialize_rec_vectors();
 }
 
-//! Constructor of two-dimensional interference function.
-//! @param length_1: length of the first basis vector in nanometers
-//! @param length_2: length of the second basis vector  in nanometers
-//! @param alpha: angle between the basis vectors in radians
-//! @param xi: rotation of the lattice with respect to the x-axis (beam direction) in radians
-InterferenceFunction2DLattice::InterferenceFunction2DLattice(double length_1, double length_2,
-                                                             double alpha, double xi)
-    : InterferenceFunction2DLattice(BasicLattice(length_1, length_2, alpha, xi))
-{
-}
-
 InterferenceFunction2DLattice::~InterferenceFunction2DLattice() = default;
 
 InterferenceFunction2DLattice* InterferenceFunction2DLattice::clone() const
diff --git a/Sample/Aggregate/InterferenceFunction2DLattice.h b/Sample/Aggregate/InterferenceFunction2DLattice.h
index de7c89eab92..47853415622 100644
--- a/Sample/Aggregate/InterferenceFunction2DLattice.h
+++ b/Sample/Aggregate/InterferenceFunction2DLattice.h
@@ -26,7 +26,6 @@
 class InterferenceFunction2DLattice : public IInterferenceFunction
 {
 public:
-    InterferenceFunction2DLattice(double length_1, double length_2, double alpha, double xi);
     InterferenceFunction2DLattice(const Lattice2D& lattice);
     ~InterferenceFunction2DLattice() final;
 
diff --git a/Tests/Performance/Core/ThreadingComponents.cpp b/Tests/Performance/Core/ThreadingComponents.cpp
index 1eb550587e4..4e6a5112842 100644
--- a/Tests/Performance/Core/ThreadingComponents.cpp
+++ b/Tests/Performance/Core/ThreadingComponents.cpp
@@ -50,8 +50,8 @@ std::unique_ptr<MultiLayer> createSampleSpheresDistribution(int nspheres)
                                       RealLimits::limited(5.0 * Units::nm, 15.0 * Units::nm));
     ParticleDistribution particleDistribution_1(particle_1, par_distr_1);
 
-    InterferenceFunction2DLattice interference_1(10.0 * Units::nm, 10.0 * Units::nm,
-                                                 90.0 * Units::deg, 0.0 * Units::deg);
+    InterferenceFunction2DLattice interference_1(
+        BasicLattice(10.0 * Units::nm, 10.0 * Units::nm, 90.0 * Units::deg, 0.0 * Units::deg));
     FTDecayFunction2DCauchy interference_1_pdf(47.7464829276 * Units::nm, 15.9154943092 * Units::nm,
                                                0.0 * Units::deg);
     interference_1.setDecayFunction(interference_1_pdf);
diff --git a/Tests/UnitTests/Core/Sample/MultilayerAveragingTest.cpp b/Tests/UnitTests/Core/Sample/MultilayerAveragingTest.cpp
index a47c90aa25e..31910e7dd6a 100644
--- a/Tests/UnitTests/Core/Sample/MultilayerAveragingTest.cpp
+++ b/Tests/UnitTests/Core/Sample/MultilayerAveragingTest.cpp
@@ -28,8 +28,8 @@ TEST_F(MultilayerAveragingTest, AverageMultilayer)
     Particle particle(stone, cylinder_ff);
 
     // interferences
-    InterferenceFunction2DLattice interf_1(10.0, 10.0, 120.0, 0.0);
-    InterferenceFunction2DLattice interf_2(10.0, 10.0, 120.0, 0.0);
+    InterferenceFunction2DLattice interf_1(BasicLattice(10.0, 10.0, 120.0, 0.0));
+    InterferenceFunction2DLattice interf_2(BasicLattice(10.0, 10.0, 120.0, 0.0));
 
     // layouts
     ParticleLayout layout_1;
diff --git a/auto/Wrap/doxygenSample.i b/auto/Wrap/doxygenSample.i
index 02230198739..24e85c227a8 100644
--- a/auto/Wrap/doxygenSample.i
+++ b/auto/Wrap/doxygenSample.i
@@ -3740,26 +3740,6 @@ Interference function of a 2D lattice.
 C++ includes: InterferenceFunction2DLattice.h
 ";
 
-%feature("docstring")  InterferenceFunction2DLattice::InterferenceFunction2DLattice "InterferenceFunction2DLattice::InterferenceFunction2DLattice(double length_1, double length_2, double alpha, double xi)
-
-Constructor of two-dimensional interference function.
-
-Parameters:
------------
-
-length_1: 
-length of the first basis vector in nanometers
-
-length_2: 
-length of the second basis vector in nanometers
-
-alpha: 
-angle between the basis vectors in radians
-
-xi: 
-rotation of the lattice with respect to the x-axis (beam direction) in radians 
-";
-
 %feature("docstring")  InterferenceFunction2DLattice::InterferenceFunction2DLattice "InterferenceFunction2DLattice::InterferenceFunction2DLattice(const Lattice2D &lattice)
 ";
 
diff --git a/auto/Wrap/libBornAgainSample.py b/auto/Wrap/libBornAgainSample.py
index a2d99c80baa..4034c9d9161 100644
--- a/auto/Wrap/libBornAgainSample.py
+++ b/auto/Wrap/libBornAgainSample.py
@@ -6906,14 +6906,13 @@ class InterferenceFunction2DLattice(IInterferenceFunction):
     thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
     __repr__ = _swig_repr
 
-    def __init__(self, *args):
+    def __init__(self, lattice):
         r"""
-        __init__(InterferenceFunction2DLattice self, double length_1, double length_2, double alpha, double xi) -> InterferenceFunction2DLattice
         __init__(InterferenceFunction2DLattice self, Lattice2D lattice) -> InterferenceFunction2DLattice
         InterferenceFunction2DLattice::InterferenceFunction2DLattice(const Lattice2D &lattice)
 
         """
-        _libBornAgainSample.InterferenceFunction2DLattice_swiginit(self, _libBornAgainSample.new_InterferenceFunction2DLattice(*args))
+        _libBornAgainSample.InterferenceFunction2DLattice_swiginit(self, _libBornAgainSample.new_InterferenceFunction2DLattice(lattice))
     __swig_destroy__ = _libBornAgainSample.delete_InterferenceFunction2DLattice
 
     def clone(self):
diff --git a/auto/Wrap/libBornAgainSample_wrap.cpp b/auto/Wrap/libBornAgainSample_wrap.cpp
index 7ee98b2a221..cceff942b32 100644
--- a/auto/Wrap/libBornAgainSample_wrap.cpp
+++ b/auto/Wrap/libBornAgainSample_wrap.cpp
@@ -52114,59 +52114,16 @@ SWIGINTERN PyObject *InterferenceFunction1DLattice_swiginit(PyObject *SWIGUNUSED
   return SWIG_Python_InitShadowInstance(args);
 }
 
-SWIGINTERN PyObject *_wrap_new_InterferenceFunction2DLattice__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
-  PyObject *resultobj = 0;
-  double arg1 ;
-  double arg2 ;
-  double arg3 ;
-  double arg4 ;
-  double val1 ;
-  int ecode1 = 0 ;
-  double val2 ;
-  int ecode2 = 0 ;
-  double val3 ;
-  int ecode3 = 0 ;
-  double val4 ;
-  int ecode4 = 0 ;
-  InterferenceFunction2DLattice *result = 0 ;
-  
-  if ((nobjs < 4) || (nobjs > 4)) SWIG_fail;
-  ecode1 = SWIG_AsVal_double(swig_obj[0], &val1);
-  if (!SWIG_IsOK(ecode1)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "new_InterferenceFunction2DLattice" "', argument " "1"" of type '" "double""'");
-  } 
-  arg1 = static_cast< double >(val1);
-  ecode2 = SWIG_AsVal_double(swig_obj[1], &val2);
-  if (!SWIG_IsOK(ecode2)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_InterferenceFunction2DLattice" "', argument " "2"" of type '" "double""'");
-  } 
-  arg2 = static_cast< double >(val2);
-  ecode3 = SWIG_AsVal_double(swig_obj[2], &val3);
-  if (!SWIG_IsOK(ecode3)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_InterferenceFunction2DLattice" "', argument " "3"" of type '" "double""'");
-  } 
-  arg3 = static_cast< double >(val3);
-  ecode4 = SWIG_AsVal_double(swig_obj[3], &val4);
-  if (!SWIG_IsOK(ecode4)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "new_InterferenceFunction2DLattice" "', argument " "4"" of type '" "double""'");
-  } 
-  arg4 = static_cast< double >(val4);
-  result = (InterferenceFunction2DLattice *)new InterferenceFunction2DLattice(arg1,arg2,arg3,arg4);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_InterferenceFunction2DLattice, SWIG_POINTER_NEW |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_new_InterferenceFunction2DLattice__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_new_InterferenceFunction2DLattice(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   Lattice2D *arg1 = 0 ;
   void *argp1 = 0 ;
   int res1 = 0 ;
+  PyObject *swig_obj[1] ;
   InterferenceFunction2DLattice *result = 0 ;
   
-  if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
+  if (!args) SWIG_fail;
+  swig_obj[0] = args;
   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_Lattice2D,  0  | 0);
   if (!SWIG_IsOK(res1)) {
     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_InterferenceFunction2DLattice" "', argument " "1"" of type '" "Lattice2D const &""'"); 
@@ -52183,60 +52140,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_new_InterferenceFunction2DLattice(PyObject *self, PyObject *args) {
-  Py_ssize_t argc;
-  PyObject *argv[5] = {
-    0
-  };
-  
-  if (!(argc = SWIG_Python_UnpackTuple(args, "new_InterferenceFunction2DLattice", 0, 4, argv))) SWIG_fail;
-  --argc;
-  if (argc == 1) {
-    int _v;
-    int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_Lattice2D, SWIG_POINTER_NO_NULL | 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      return _wrap_new_InterferenceFunction2DLattice__SWIG_1(self, argc, argv);
-    }
-  }
-  if (argc == 4) {
-    int _v;
-    {
-      int res = SWIG_AsVal_double(argv[0], NULL);
-      _v = SWIG_CheckState(res);
-    }
-    if (_v) {
-      {
-        int res = SWIG_AsVal_double(argv[1], NULL);
-        _v = SWIG_CheckState(res);
-      }
-      if (_v) {
-        {
-          int res = SWIG_AsVal_double(argv[2], NULL);
-          _v = SWIG_CheckState(res);
-        }
-        if (_v) {
-          {
-            int res = SWIG_AsVal_double(argv[3], NULL);
-            _v = SWIG_CheckState(res);
-          }
-          if (_v) {
-            return _wrap_new_InterferenceFunction2DLattice__SWIG_0(self, argc, argv);
-          }
-        }
-      }
-    }
-  }
-  
-fail:
-  SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_InterferenceFunction2DLattice'.\n"
-    "  Possible C/C++ prototypes are:\n"
-    "    InterferenceFunction2DLattice::InterferenceFunction2DLattice(double,double,double,double)\n"
-    "    InterferenceFunction2DLattice::InterferenceFunction2DLattice(Lattice2D const &)\n");
-  return 0;
-}
-
-
 SWIGINTERN PyObject *_wrap_delete_InterferenceFunction2DLattice(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   InterferenceFunction2DLattice *arg1 = (InterferenceFunction2DLattice *) 0 ;
@@ -72919,8 +72822,7 @@ static PyMethodDef SwigMethods[] = {
 		""},
 	 { "InterferenceFunction1DLattice_swigregister", InterferenceFunction1DLattice_swigregister, METH_O, NULL},
 	 { "InterferenceFunction1DLattice_swiginit", InterferenceFunction1DLattice_swiginit, METH_VARARGS, NULL},
-	 { "new_InterferenceFunction2DLattice", _wrap_new_InterferenceFunction2DLattice, METH_VARARGS, "\n"
-		"InterferenceFunction2DLattice(double length_1, double length_2, double alpha, double xi)\n"
+	 { "new_InterferenceFunction2DLattice", _wrap_new_InterferenceFunction2DLattice, METH_O, "\n"
 		"new_InterferenceFunction2DLattice(Lattice2D lattice) -> InterferenceFunction2DLattice\n"
 		"InterferenceFunction2DLattice::InterferenceFunction2DLattice(const Lattice2D &lattice)\n"
 		"\n"
-- 
GitLab