Mantid
Loading...
Searching...
No Matches
Framework
CurveFitting
src
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 +
7
#include "
MantidCurveFitting/ExcludeRangeFinder.h
"
8
9
#include <algorithm>
10
11
namespace
Mantid::CurveFitting
{
12
17
ExcludeRangeFinder::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;
27
findNextExcludedRange
(startX);
28
}
29
}
30
}
31
36
bool
ExcludeRangeFinder::isExcluded
(
double
value
) {
37
if
(
m_exclIndex
<
m_size
) {
38
if
(
value
<
m_startExcludedRange
) {
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.
49
findNextExcludedRange
(
value
);
50
// The value can find itself inside another range.
51
return
isExcluded
(
value
);
52
}
53
}
54
return
false
;
55
}
56
59
void
ExcludeRangeFinder::findNextExcludedRange
(
double
p) {
60
if
(p >
m_exclude
.back()) {
61
// If the value is past the last point stop any searches or checks.
62
m_exclIndex
=
m_size
;
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
const
auto
it = std::find_if(
m_exclude
.cbegin(),
m_exclude
.cend(), [&p](
const
auto
&ex) { return ex >= p; });
70
if
(it ==
m_exclude
.cend())
71
return
;
72
m_exclIndex
=
static_cast<
std::size_t
>
(std::distance(
m_exclude
.begin(), it));
73
if
(
m_exclIndex
% 2 == 0) {
74
// A number at an even position in m_exclude starts an exclude
75
// range
76
m_startExcludedRange
= *it;
77
m_endExcludeRange
= *(it + 1);
78
}
else
{
79
// A number at an odd position in m_exclude ends an exclude range
80
m_startExcludedRange
= *(it - 1);
81
m_endExcludeRange
= *it;
82
--
m_exclIndex
;
83
}
84
// No need for additional checks as p < m_exclude.back()
85
// and m_exclude[m_exclIndex] < p due to conditions at the calls
86
// so the break statement will always be reached.
87
}
88
}
// namespace Mantid::CurveFitting
m_size
size_t m_size
Maximum size of the store.
Definition
EstimateFitParameters.cpp:111
ExcludeRangeFinder.h
value
double value
The value of the point.
Definition
FitMW.cpp:51
Mantid::CurveFitting::ExcludeRangeFinder::isExcluded
bool isExcluded(double value)
Check if an x-value lies in an exclusion range.
Definition
ExcludeRangeFinder.cpp:36
Mantid::CurveFitting::ExcludeRangeFinder::m_exclude
const std::vector< double > m_exclude
Reference to a list of exclusion ranges.
Definition
ExcludeRangeFinder.h:41
Mantid::CurveFitting::ExcludeRangeFinder::m_size
const std::size_t m_size
Size of m_exclude.
Definition
ExcludeRangeFinder.h:43
Mantid::CurveFitting::ExcludeRangeFinder::findNextExcludedRange
void findNextExcludedRange(double p)
Find the range from m_exclude that may contain points x >= p.
Definition
ExcludeRangeFinder.cpp:59
Mantid::CurveFitting::ExcludeRangeFinder::ExcludeRangeFinder
ExcludeRangeFinder(const std::vector< double > &exclude, double startX, double endX)
Constructor.
Definition
ExcludeRangeFinder.cpp:17
Mantid::CurveFitting::ExcludeRangeFinder::m_startExcludedRange
double m_startExcludedRange
Start of current excluded range.
Definition
ExcludeRangeFinder.h:37
Mantid::CurveFitting::ExcludeRangeFinder::m_exclIndex
std::size_t m_exclIndex
Index of current excluded range.
Definition
ExcludeRangeFinder.h:35
Mantid::CurveFitting::ExcludeRangeFinder::m_endExcludeRange
double m_endExcludeRange
End of current excluded range.
Definition
ExcludeRangeFinder.h:39
Mantid::CurveFitting
Definition
IFunction1D.h:19
Generated by
1.9.8