forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BinEdges.cpp
41 lines (36 loc) · 1.35 KB
/
BinEdges.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidHistogramData/BinEdges.h"
#include "MantidHistogramData/Points.h"
namespace Mantid::HistogramData {
/// Constructs BinEdges from points, approximating each bin edges as mid-point
/// between two points.
BinEdges::BinEdges(const Points &points) {
if (!points)
return;
const size_t numPoints = points.size();
size_t numEdges = numPoints + 1;
if (numPoints == 0) {
m_data = Kernel::make_cow<HistogramX>(numPoints);
return;
}
if (numPoints == 1) {
auto data = {points[0] - 0.5, points[0] + 0.5};
m_data = Kernel::make_cow<HistogramX>(data);
return;
}
std::vector<double> data(numEdges);
// Handle the front and back points outside
for (size_t i = 0; i < numPoints - 1; ++i) {
data[i + 1] = 0.5 * (points[i + 1] + points[i]);
}
// Now deal with the end points
data[0] = points[0] - (data[1] - points[0]);
data[numPoints] = points[numPoints - 1] + (points[numPoints - 1] - data[numEdges - 2]);
m_data = Kernel::make_cow<HistogramX>(std::move(data));
}
} // namespace Mantid::HistogramData