From 554be94c23fcfb6b7b0517070944c707f73087e0 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Fri, 5 May 2023 10:21:51 +0200
Subject: [PATCH] IDetector rm begin/endNonMaskedPoints

---
 Device/Detector/IDetector.cpp               | 13 +----
 Device/Detector/IDetector.h                 |  8 ---
 Tests/Unit/Device/SimulationAreaTest.cpp    | 54 ++++-----------------
 Tests/Unit/Device/SphericalDetectorTest.cpp |  6 +--
 4 files changed, 15 insertions(+), 66 deletions(-)

diff --git a/Device/Detector/IDetector.cpp b/Device/Detector/IDetector.cpp
index 0cf1f0dc7cd..522f437a7b7 100644
--- a/Device/Detector/IDetector.cpp
+++ b/Device/Detector/IDetector.cpp
@@ -188,20 +188,11 @@ std::vector<const INode*> IDetector::nodeChildren() const
 
 void IDetector::iterateOverNonMaskedPoints(std::function<void(const_iterator)> func) const
 {
-    for (auto it = beginNonMaskedPoints(); it != endNonMaskedPoints(); ++it)
+    for (auto it = SimulationAreaIterator::createBegin(this);
+         it != SimulationAreaIterator::createEnd(this); ++it)
         func(it);
 }
 
-SimulationAreaIterator IDetector::beginNonMaskedPoints() const
-{
-    return SimulationAreaIterator::createBegin(this);
-}
-
-SimulationAreaIterator IDetector::endNonMaskedPoints() const
-{
-    return SimulationAreaIterator::createEnd(this);
-}
-
 size_t IDetector::regionOfInterestIndexToDetectorIndex(const size_t regionOfInterestIndex) const
 {
     if (m_explicitROI.size() != 2)
diff --git a/Device/Detector/IDetector.h b/Device/Detector/IDetector.h
index 04991568610..4e15099e083 100644
--- a/Device/Detector/IDetector.h
+++ b/Device/Detector/IDetector.h
@@ -146,14 +146,6 @@ public:
     std::pair<double, double> regionOfInterestBounds(size_t iAxis) const;
 
 #ifndef SWIG
-    //! Create begin-iterator to iterate over all points which are not masked and lay
-    //! within the "Region of Interest"
-    SimulationAreaIterator beginNonMaskedPoints() const;
-
-    //! Create end-iterator to iterate over all points which are not masked and lay
-    //! within the "Region of Interest"
-    SimulationAreaIterator endNonMaskedPoints() const;
-
     //! Returns empty detector map in given axes units.
     //! This map is a data array limited to the size of the "Region of interest"
     Datafield createDetectorMap() const;
diff --git a/Tests/Unit/Device/SimulationAreaTest.cpp b/Tests/Unit/Device/SimulationAreaTest.cpp
index 6efed8353b9..7b5bb9578d3 100644
--- a/Tests/Unit/Device/SimulationAreaTest.cpp
+++ b/Tests/Unit/Device/SimulationAreaTest.cpp
@@ -5,37 +5,6 @@
 #include <iostream>
 #include <memory>
 
-// Iterators test
-
-TEST(SimulationAreaTest, iteratorOperations)
-{
-    SphericalDetector detector(4, -1.0, 3.0, 2, 0.0, 2.0);
-
-    // begin iterator
-    SimulationAreaIterator it_begin = detector.beginNonMaskedPoints();
-    EXPECT_EQ(it_begin.roiIndex(), 0u);
-    EXPECT_TRUE(it_begin == detector.beginNonMaskedPoints());
-    EXPECT_FALSE(it_begin != detector.beginNonMaskedPoints());
-
-    // end iterator
-    SimulationAreaIterator it_end = detector.endNonMaskedPoints();
-    EXPECT_EQ(it_end.roiIndex(), detector.totalSize());
-
-    // begin/end comparison
-    EXPECT_TRUE(it_begin != it_end);
-    EXPECT_FALSE(it_begin == it_end);
-
-    // assignment
-    SimulationAreaIterator it = detector.beginNonMaskedPoints();
-    EXPECT_TRUE(it == it_begin);
-    EXPECT_FALSE(it != it_begin);
-
-    // incrementing well behind the end
-    for (size_t i = 0; i < 100; ++i)
-        ++it;
-    EXPECT_EQ(it.roiIndex(), detector.totalSize());
-}
-
 //! Iteration over non-masked detector
 
 TEST(SimulationAreaTest, detectorIteration)
@@ -46,10 +15,10 @@ TEST(SimulationAreaTest, detectorIteration)
 
     std::vector<size_t> indexes;
     std::vector<size_t> detectorIndexes;
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it) {
+    detector.iterateOverNonMaskedPoints([&](const auto it) {
         indexes.push_back(it.roiIndex());
         detectorIndexes.push_back(it.detectorIndex());
-    }
+    });
     EXPECT_EQ(indexes, expectedIndexes);
     EXPECT_EQ(detectorIndexes, expectedIndexes);
 }
@@ -64,8 +33,7 @@ TEST(SimulationAreaTest, maskedIteration)
 
     std::vector<size_t> expectedIndexes = {0, 1, 2, 3, 4, 7, 8, 11, 12, 15, 16, 17, 18};
     std::vector<size_t> indexes;
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it)
-        indexes.push_back(it.roiIndex());
+    detector.iterateOverNonMaskedPoints([&](const auto it) { indexes.push_back(it.roiIndex()); });
     EXPECT_EQ(indexes, expectedIndexes);
 }
 
@@ -81,8 +49,7 @@ TEST(SimulationAreaTest, maskedCornerIteration)
                                            10, 11, 12, 13, 14, 15, 16, 17, 18};
     std::vector<size_t> indexes;
     std::vector<size_t> elementIndexes;
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it)
-        indexes.push_back(it.roiIndex());
+    detector.iterateOverNonMaskedPoints([&](const auto it) { indexes.push_back(it.roiIndex()); });
     EXPECT_EQ(indexes, expectedIndexes);
 }
 
@@ -95,8 +62,7 @@ TEST(SimulationAreaTest, allMaskedIteration)
 
     std::vector<size_t> indexes;
 
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it)
-        indexes.push_back(it.roiIndex());
+    detector.iterateOverNonMaskedPoints([&](const auto it) { indexes.push_back(it.roiIndex()); });
 
     EXPECT_EQ(indexes.size(), size_t(0));
 }
@@ -115,11 +81,11 @@ TEST(SimulationAreaTest, maskAndRoiIteration)
     std::vector<size_t> elementIndexes;
     std::vector<size_t> detectorIndexes;
     std::vector<size_t> roiIndexes;
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it) {
+    detector.iterateOverNonMaskedPoints([&](const auto it) {
         indexes.push_back(it.roiIndex());
         detectorIndexes.push_back(it.detectorIndex());
         roiIndexes.push_back(it.roiIndex());
-    }
+    });
     EXPECT_EQ(indexes, expectedRoiIndexes);
     EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
     EXPECT_EQ(roiIndexes, expectedRoiIndexes);
@@ -128,7 +94,7 @@ TEST(SimulationAreaTest, maskAndRoiIteration)
     indexes.clear();
     detectorIndexes.clear();
     roiIndexes.clear();
-    detector.iterateOverNonMaskedPoints([&](IDetector::const_iterator it) {
+    detector.iterateOverNonMaskedPoints([&](const auto it) {
         indexes.push_back(it.roiIndex());
         detectorIndexes.push_back(it.detectorIndex());
         roiIndexes.push_back(it.roiIndex());
@@ -152,11 +118,11 @@ TEST(SimulationAreaTest, indexInRoi)
     std::vector<size_t> indexes;
     std::vector<size_t> roiIndexes;
     std::vector<size_t> detectorIndexes;
-    for (auto it = detector.beginNonMaskedPoints(); it != detector.endNonMaskedPoints(); ++it) {
+    detector.iterateOverNonMaskedPoints([&](const auto it) {
         indexes.push_back(it.roiIndex());
         roiIndexes.push_back(it.roiIndex());
         detectorIndexes.push_back(it.detectorIndex());
-    }
+    });
     EXPECT_EQ(indexes, expectedIndexes);
     EXPECT_EQ(roiIndexes, expectedRoi);
     EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
diff --git a/Tests/Unit/Device/SphericalDetectorTest.cpp b/Tests/Unit/Device/SphericalDetectorTest.cpp
index 4a43f1d5718..0cca5f28322 100644
--- a/Tests/Unit/Device/SphericalDetectorTest.cpp
+++ b/Tests/Unit/Device/SphericalDetectorTest.cpp
@@ -2,7 +2,7 @@
 #include "Base/Axis/FixedBinAxis.h"
 #include "Base/Const/Units.h"
 #include "Device/Beam/Beam.h"
-#include "Device/Detector/SimulationAreaIterator.h" // beginNonMaskedPoints
+#include "Device/Detector/SimulationAreaIterator.h"
 #include "Device/Mask/DetectorMask.h"
 #include "Device/Mask/Polygon.h"
 #include "Device/Mask/Rectangle.h"
@@ -130,7 +130,7 @@ TEST(SphericalDetectorTest, Clone)
     // checking iteration over the map of cloned detector
     std::vector<size_t> expectedDetectorIndexes = {6, 9, 10, 13, 14, 17};
     std::vector<size_t> detectorIndexes;
-    for (auto it = clone->beginNonMaskedPoints(); it != clone->endNonMaskedPoints(); ++it)
-        detectorIndexes.push_back(it.detectorIndex());
+    clone->iterateOverNonMaskedPoints(
+        [&](const auto it) { detectorIndexes.push_back(it.detectorIndex()); });
     EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
 }
-- 
GitLab