Mantid
Loading...
Searching...
No Matches
ExcludeRangeFinder.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include <algorithm>
10
11namespace Mantid::CurveFitting {
12
17ExcludeRangeFinder::ExcludeRangeFinder(const std::vector<double> &exclude, double startX, double endX)
18 : m_exclIndex(exclude.size()), m_startExcludedRange(), m_endExcludeRange(), m_exclude(exclude),
19 m_size(exclude.size()) {
20 // m_exclIndex is initialised with exclude.size() to be the default when
21 // there are no exclusion ranges defined.
22 if (!m_exclude.empty()) {
23 if (startX < m_exclude.back() && endX > m_exclude.front()) {
24 // In this case there are some ranges, the index starts with 0
25 // and first range is found.
26 m_exclIndex = 0;
28 }
29 }
30}
31
37 if (m_exclIndex < m_size) {
39 // If a value is below the start of the current interval
40 // it is not in any other interval by the workings of
41 // findNextExcludedRange
42 return false;
43 } else if (value <= m_endExcludeRange) {
44 // value is inside
45 return true;
46 } else {
47 // Value is past the current range. Find the next one or set the index
48 // to m_exclude.size() to stop further searches.
50 // The value can find itself inside another range.
51 return isExcluded(value);
52 }
53 }
54 return false;
55}
56
60 if (p > m_exclude.back()) {
61 // If the value is past the last point stop any searches or checks.
63 return;
64 }
65 // Starting with the current index m_exclIndex find the first value in
66 // m_exclude that is greater than p. If this point is a start than the
67 // end will be the following point. If it's an end then the start is
68 // the previous point. Keep index m_exclIndex pointing to the start.
69 for (auto it = m_exclude.begin() + m_exclIndex; it != m_exclude.end(); ++it) {
70 if (*it >= p) {
71 m_exclIndex = static_cast<std::size_t>(std::distance(m_exclude.begin(), it));
72 if (m_exclIndex % 2 == 0) {
73 // A number at an even position in m_exclude starts an exclude
74 // range
76 m_endExcludeRange = *(it + 1);
77 } else {
78 // A number at an odd position in m_exclude ends an exclude range
79 m_startExcludedRange = *(it - 1);
82 }
83 break;
84 }
85 }
86 // No need for additional checks as p < m_exclude.back()
87 // and m_exclude[m_exclIndex] < p due to conditions at the calls
88 // so the break statement will always be reached.
89}
90} // namespace Mantid::CurveFitting
size_t m_size
Maximum size of the store.
double value
The value of the point.
Definition: FitMW.cpp:51
bool isExcluded(double value)
Check if an x-value lies in an exclusion range.
const std::vector< double > m_exclude
Reference to a list of exclusion ranges.
const std::size_t m_size
Size of m_exclude.
void findNextExcludedRange(double p)
Find the range from m_exclude that may contain points x >= p.
ExcludeRangeFinder(const std::vector< double > &exclude, double startX, double endX)
Constructor.
double m_startExcludedRange
Start of current excluded range.
std::size_t m_exclIndex
Index of current excluded range.
double m_endExcludeRange
End of current excluded range.