BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
FramUtil Namespace Reference

Functions

double coordinateFromBinf (double value, const IAxis &axis)
 Transforms bin-fraction-coordinate into axis coordinate. More...
 
void coordinatesFromBinf (double &x, double &y, const Frame &frame)
 Transforms x,y coordinate from bin-fraction-coordinates to Datafield's axes coordinates. More...
 
void coordinatesToBinf (double &x, double &y, const Frame &frame)
 Transforms x,y coordinate from Datafield axes coordinates to bin-fraction-coordinates. More...
 
double coordinateToBinf (double coordinate, const IAxis &axis)
 Transforms coordinate on axis into the bin-fraction-coordinate. More...
 

Function Documentation

◆ coordinateFromBinf()

double FramUtil::coordinateFromBinf ( double  value,
const IAxis axis 
)

Transforms bin-fraction-coordinate into axis coordinate.

Definition at line 34 of file FrameUtil.cpp.

35 {
36  int index = static_cast<int>(value);
37 
38  double result(0);
39  if (index < 0) {
40  Bin1D bin = axis.bin(0);
41  result = bin.m_lower + value * bin.binSize();
42  } else if (index >= static_cast<int>(axis.size())) {
43  Bin1D bin = axis.bin(axis.size() - 1);
44  result = bin.m_upper + (value - axis.size()) * bin.binSize();
45  } else {
46  Bin1D bin = axis.bin(static_cast<size_t>(index));
47  result = bin.m_lower + (value - static_cast<double>(index)) * bin.binSize();
48  }
49 
50  return result;
51 }
Definition: Bin.h:20
double binSize() const
Definition: Bin.h:31
double m_upper
upper bound of the bin
Definition: Bin.h:29
double m_lower
lower bound of the bin
Definition: Bin.h:28
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
virtual size_t size() const =0
Returns the number of bins.

References IAxis::bin(), Bin1D::binSize(), Bin1D::m_lower, Bin1D::m_upper, and IAxis::size().

Referenced by coordinatesFromBinf().

Here is the call graph for this function:

◆ coordinatesFromBinf()

void FramUtil::coordinatesFromBinf ( double &  x,
double &  y,
const Frame frame 
)

Transforms x,y coordinate from bin-fraction-coordinates to Datafield's axes coordinates.

Definition at line 59 of file FrameUtil.cpp.

60 {
61  x = coordinateFromBinf(x, data.xAxis());
62  y = coordinateFromBinf(y, data.yAxis());
63 }
double coordinateFromBinf(double value, const IAxis &axis)
Transforms bin-fraction-coordinate into axis coordinate.
Definition: FrameUtil.cpp:34

References coordinateFromBinf(), Frame::xAxis(), and Frame::yAxis().

Here is the call graph for this function:

◆ coordinatesToBinf()

void FramUtil::coordinatesToBinf ( double &  x,
double &  y,
const Frame frame 
)

Transforms x,y coordinate from Datafield axes coordinates to bin-fraction-coordinates.

Definition at line 53 of file FrameUtil.cpp.

54 {
55  x = coordinateToBinf(x, data.xAxis());
56  y = coordinateToBinf(y, data.yAxis());
57 }
double coordinateToBinf(double coordinate, const IAxis &axis)
Transforms coordinate on axis into the bin-fraction-coordinate.
Definition: FrameUtil.cpp:26

References coordinateToBinf(), Frame::xAxis(), and Frame::yAxis().

Here is the call graph for this function:

◆ coordinateToBinf()

double FramUtil::coordinateToBinf ( double  coordinate,
const IAxis axis 
)

Transforms coordinate on axis into the bin-fraction-coordinate.

Definition at line 26 of file FrameUtil.cpp.

27 {
28  size_t index = axis.findClosestIndex(coordinate);
29  Bin1D bin = axis.bin(index);
30  double f = (coordinate - bin.m_lower) / bin.binSize();
31  return static_cast<double>(index) + f;
32 }
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value

References IAxis::bin(), Bin1D::binSize(), IAxis::findClosestIndex(), and Bin1D::m_lower.

Referenced by coordinatesToBinf().

Here is the call graph for this function: