Skip to content
Snippets Groups Projects
Commit 6f8fb814 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

[flat7] minor cleanup SImulationAreaIterator ()

Merging branch 'flat7'  into 'main'.

See merge request !1906
parents a874e750 0e0aa545
No related branches found
No related tags found
1 merge request!1906minor cleanup SImulationAreaIterator
Pipeline #110026 passed
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "Device/Detector/SimulationAreaIterator.h"
#include "Base/Util/Assert.h"
#include "Device/Detector/IDetector.h"
#include "Device/Mask/DetectorMask.h"
......@@ -21,10 +22,7 @@ SimulationAreaIterator::SimulationAreaIterator(const IDetector* detector, size_t
, m_index(start_at_index)
, m_maxIndex(m_detector->sizeOfRegionOfInterest())
{
if (m_index > m_maxIndex)
throw std::runtime_error("SimulationAreaIterator::SimulationAreaIterator() "
"-> Error. Invalid initial index");
ASSERT(m_index <= m_maxIndex);
if (m_index != m_maxIndex && isMasked(m_index))
m_index = nextIndex(m_index);
}
......@@ -39,11 +37,6 @@ SimulationAreaIterator SimulationAreaIterator::createEnd(const IDetector* detect
return SimulationAreaIterator(detector, detector->sizeOfRegionOfInterest());
}
SimulationAreaIterator SimulationAreaIterator::createEnd() const
{
return createEnd(m_detector);
}
size_t SimulationAreaIterator::roiIndex() const
{
return m_index;
......@@ -84,5 +77,16 @@ bool SimulationAreaIterator::isMasked(size_t index) const
{
const auto* masks = m_detector->detectorMask();
const auto detectorIndex = m_detector->regionOfInterestIndexToDetectorIndex(index);
return (masks && masks->isMasked(detectorIndex));
return masks && masks->isMasked(detectorIndex);
}
bool SimulationAreaIterator::operator==(const SimulationAreaIterator& other) const
{
ASSERT(m_detector == other.m_detector);
return m_index == other.m_index;
}
bool SimulationAreaIterator::operator!=(const SimulationAreaIterator& right) const
{
return !(*this == right);
}
......@@ -25,9 +25,6 @@ class IDetector;
//! An iterator for SimulationArea.
class SimulationAreaIterator {
private:
explicit SimulationAreaIterator(const IDetector* detector, size_t start_at_index);
public:
//! Create begin-iterator to iterate over all points according to the given mode.
static SimulationAreaIterator createBegin(const IDetector* detector);
......@@ -35,9 +32,6 @@ public:
//! Create end-iterator to iterate over all points according to the given mode.
static SimulationAreaIterator createEnd(const IDetector* detector);
//! Convenience function to create an end-iterator matching to this iterator.
SimulationAreaIterator createEnd() const;
size_t roiIndex() const;
size_t detectorIndex() const;
......@@ -48,6 +42,8 @@ public:
SimulationAreaIterator& operator++();
private:
explicit SimulationAreaIterator(const IDetector* detector, size_t start_at_index);
size_t nextIndex(size_t currentIndex);
bool isMasked(size_t index) const;
......@@ -57,14 +53,4 @@ private:
size_t m_maxIndex; //!< ROI related maximum index
};
inline bool SimulationAreaIterator::operator==(const SimulationAreaIterator& other) const
{
return m_detector == other.m_detector && m_index == other.m_index;
}
inline bool SimulationAreaIterator::operator!=(const SimulationAreaIterator& right) const
{
return !(*this == right);
}
#endif // BORNAGAIN_DEVICE_DETECTOR_SIMULATIONAREAITERATOR_H
......@@ -50,8 +50,7 @@ void Rectangle::setInverted(bool inverted /*= true*/)
bool Rectangle::contains(double x, double y) const
{
const bool inRect = x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
return m_inverted ? !inRect : inRect;
return m_inverted ^ (x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow);
}
bool Rectangle::contains(const Bin1D& binx, const Bin1D& biny) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment