Mantid
Loading...
Searching...
No Matches
LinearScale.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10
13
14namespace Mantid::API {
15
16DECLARE_TRANSFORMSCALE(LinearScale)
17
18/* Transform the grid to adopt a linear scale
19 * @param gd a grid object
20 */
21void LinearScale::transform(std::vector<double> &gd) {
22 size_t n = gd.size();
23 if (n < 3)
24 return; // no need to process
25 double startX = gd.front();
26 double endX = gd.back();
27 double spacing = (endX - startX) / double(n);
28 double x = startX + spacing;
29 for (auto it = gd.begin() + 1; it != gd.end() - 1; it++) {
30 *it = x;
31 x += spacing;
32 }
33}
34
35} // namespace Mantid::API
#define DECLARE_TRANSFORMSCALE(classname)
STL namespace.