Public Member Functions | Private Attributes | List of all members
evd::details::GridAxisClass Class Reference

Manages a cell-like division of a coordinate. More...

Public Member Functions

 GridAxisClass ()
 Default constructor: an invalid range. More...
 
 GridAxisClass (size_t nDiv, float new_min, float new_max)
 Constructor: sets the limits and the number of cells. More...
 
bool hasCell (std::ptrdiff_t iCell) const
 Returns whether the cell is present or not. More...
 
bool hasCoord (float coord) const
 Returns whether the coordinate is included in the range or not. More...
 
float Length () const
 Returns the length of the axis. More...
 
size_t NCells () const
 Returns the length of the axis. More...
 
bool isEmpty () const
 Returns whether minimum and maximum match. More...
 
float CellSize () const
 Returns the cell size. More...
 
float LowerEdge (std::ptrdiff_t iCell) const
 Returns the lower edge of the cell. More...
 
float UpperEdge (std::ptrdiff_t iCell) const
 Returns the upper edge of the cell. More...
 
bool Init (size_t nDiv, float new_min, float new_max)
 Initialize the axis, returns whether cell size is finite. More...
 
bool SetLimits (float new_min, float new_max)
 Initialize the axis limits, returns whether cell size is finite. More...
 
bool SetMinCellSize (float min_size)
 
bool SetMaxCellSize (float max_size)
 
bool SetCellSizeBoundary (float min_size, float max_size)
 
template<typename Stream >
void Dump (Stream &&out) const
 
std::ptrdiff_t GetCell (float coord) const
 Returns the index of the specified cell. More...
 
std::ptrdiff_t operator() (float coord) const
 
float Min () const
 Returns the extremes of the axis. More...
 
float Max () const
 

Private Attributes

size_t n_cells
 number of cells in the axis More...
 
float min
 
float max
 extremes of the axis More...
 
float cell_size
 size of each cell More...
 

Detailed Description

Manages a cell-like division of a coordinate.

Definition at line 370 of file RawDataDrawer.cxx.

Constructor & Destructor Documentation

evd::details::GridAxisClass::GridAxisClass ( )
inline

Default constructor: an invalid range.

Definition at line 373 of file RawDataDrawer.cxx.

373 { Init(0, 0., 0.); }
bool Init(size_t nDiv, float new_min, float new_max)
Initialize the axis, returns whether cell size is finite.
evd::details::GridAxisClass::GridAxisClass ( size_t  nDiv,
float  new_min,
float  new_max 
)
inline

Constructor: sets the limits and the number of cells.

Definition at line 376 of file RawDataDrawer.cxx.

376 { Init(nDiv, new_min, new_max); }
bool Init(size_t nDiv, float new_min, float new_max)
Initialize the axis, returns whether cell size is finite.

Member Function Documentation

float evd::details::GridAxisClass::CellSize ( ) const
inline

Returns the cell size.

Definition at line 439 of file RawDataDrawer.cxx.

440  {
441  return cell_size;
442  }
float cell_size
size of each cell
template<typename Stream >
void evd::details::GridAxisClass::Dump ( Stream &&  out) const

Definition at line 2078 of file RawDataDrawer.cxx.

2079  {
2080  out << NCells() << " cells from " << Min() << " to " << Max() << " (length: " << Length()
2081  << ")";
2082  } // GridAxisClass::Dump()
float Min() const
Returns the extremes of the axis.
float Length() const
Returns the length of the axis.
size_t NCells() const
Returns the length of the axis.
std::ptrdiff_t evd::details::GridAxisClass::GetCell ( float  coord) const

Returns the index of the specified cell.

Definition at line 2019 of file RawDataDrawer.cxx.

2020  {
2021  return std::ptrdiff_t((coord - min) / cell_size); // truncate
2022  } // GridAxisClass::GetCell()
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
float cell_size
size of each cell
bool evd::details::GridAxisClass::hasCell ( std::ptrdiff_t  iCell) const
inline

Returns whether the cell is present or not.

Definition at line 390 of file RawDataDrawer.cxx.

391  {
392  return (iCell >= 0) && ((size_t)iCell < NCells());
393  }
size_t NCells() const
Returns the length of the axis.
bool evd::details::GridAxisClass::hasCoord ( float  coord) const
inline

Returns whether the coordinate is included in the range or not.

Definition at line 397 of file RawDataDrawer.cxx.

398  {
399  return (coord >= Min()) && (coord < Max());
400  }
float Min() const
Returns the extremes of the axis.
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
bool evd::details::GridAxisClass::Init ( size_t  nDiv,
float  new_min,
float  new_max 
)

Initialize the axis, returns whether cell size is finite.

Definition at line 2026 of file RawDataDrawer.cxx.

2027  {
2028 
2029  n_cells = std::max(nDiv, size_t(1));
2030  return SetLimits(new_min, new_max);
2031 
2032  } // GridAxisClass::Init()
size_t n_cells
number of cells in the axis
bool SetLimits(float new_min, float new_max)
Initialize the axis limits, returns whether cell size is finite.
static int max(int a, int b)
bool evd::details::GridAxisClass::isEmpty ( ) const
inline

Returns whether minimum and maximum match.

Definition at line 432 of file RawDataDrawer.cxx.

433  {
434  return max == min;
435  }
float max
extremes of the axis
float evd::details::GridAxisClass::Length ( ) const
inline

Returns the length of the axis.

Definition at line 418 of file RawDataDrawer.cxx.

419  {
420  return max - min;
421  }
float max
extremes of the axis
float evd::details::GridAxisClass::LowerEdge ( std::ptrdiff_t  iCell) const
inline

Returns the lower edge of the cell.

Definition at line 446 of file RawDataDrawer.cxx.

447  {
448  return Min() + CellSize() * iCell;
449  }
float Min() const
Returns the extremes of the axis.
float CellSize() const
Returns the cell size.
float evd::details::GridAxisClass::Max ( ) const
inline

Definition at line 410 of file RawDataDrawer.cxx.

411  {
412  return max;
413  }
float max
extremes of the axis
float evd::details::GridAxisClass::Min ( ) const
inline

Returns the extremes of the axis.

Definition at line 405 of file RawDataDrawer.cxx.

406  {
407  return min;
408  }
size_t evd::details::GridAxisClass::NCells ( ) const
inline

Returns the length of the axis.

Definition at line 425 of file RawDataDrawer.cxx.

426  {
427  return n_cells;
428  }
size_t n_cells
number of cells in the axis
std::ptrdiff_t evd::details::GridAxisClass::operator() ( float  coord) const
inline

Definition at line 382 of file RawDataDrawer.cxx.

383  {
384  return GetCell(coord);
385  }
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
std::ptrdiff_t GetCell(float coord) const
Returns the index of the specified cell.
bool evd::details::GridAxisClass::SetCellSizeBoundary ( float  min_size,
float  max_size 
)
inline

Expands the cell (at fixed range) to meet maximum cell size

Returns
Whether the cell size was changed

Definition at line 475 of file RawDataDrawer.cxx.

476  {
477  return SetMinCellSize(min_size) || SetMaxCellSize(max_size);
478  }
bool SetMaxCellSize(float max_size)
bool SetMinCellSize(float min_size)
bool evd::details::GridAxisClass::SetLimits ( float  new_min,
float  new_max 
)

Initialize the axis limits, returns whether cell size is finite.

Definition at line 2036 of file RawDataDrawer.cxx.

2037  {
2038  min = new_min;
2039  max = new_max;
2040  cell_size = Length() / float(n_cells);
2041 
2042  return std::isnormal(cell_size);
2043  } // GridAxisClass::SetLimits()
float cell_size
size of each cell
size_t n_cells
number of cells in the axis
float Length() const
Returns the length of the axis.
float max
extremes of the axis
bool evd::details::GridAxisClass::SetMaxCellSize ( float  max_size)

Expands the cell (at fixed range) to meet maximum cell size

Returns
Whether the cell size was changed

Definition at line 2062 of file RawDataDrawer.cxx.

2063  {
2064  if (cell_size <= max_size) return false;
2065 
2066  // n_cells gets rounded up
2067  n_cells = (size_t)std::max(std::ceil(Length() / max_size), 1.0F);
2068 
2069  // reevaluate cell size, that might be different than max_size
2070  // because of n_cells rounding or minimum value
2071  cell_size = Length() / float(n_cells);
2072  return true;
2073  } // GridAxisClass::SetMaxCellSize()
float cell_size
size of each cell
size_t n_cells
number of cells in the axis
float Length() const
Returns the length of the axis.
static int max(int a, int b)
bool evd::details::GridAxisClass::SetMinCellSize ( float  min_size)

Expands the cell (at fixed range) to meet minimum cell size

Returns
Whether the cell size was changed

Definition at line 2047 of file RawDataDrawer.cxx.

2048  {
2049  if (cell_size >= min_size) return false;
2050 
2051  // n_cells gets truncated
2052  n_cells = (size_t)std::max(std::floor(Length() / min_size), 1.0F);
2053 
2054  // reevaluate cell size, that might be different than min_size
2055  // because of n_cells truncation or minimum value
2056  cell_size = Length() / float(n_cells);
2057  return true;
2058  } // GridAxisClass::SetMinCellSize()
float cell_size
size of each cell
size_t n_cells
number of cells in the axis
float Length() const
Returns the length of the axis.
static int max(int a, int b)
float evd::details::GridAxisClass::UpperEdge ( std::ptrdiff_t  iCell) const
inline

Returns the upper edge of the cell.

Definition at line 453 of file RawDataDrawer.cxx.

454  {
455  return LowerEdge(iCell + 1);
456  }
float LowerEdge(std::ptrdiff_t iCell) const
Returns the lower edge of the cell.

Member Data Documentation

float evd::details::GridAxisClass::cell_size
private

size of each cell

Definition at line 487 of file RawDataDrawer.cxx.

float evd::details::GridAxisClass::max
private

extremes of the axis

Definition at line 485 of file RawDataDrawer.cxx.

float evd::details::GridAxisClass::min
private

Definition at line 485 of file RawDataDrawer.cxx.

size_t evd::details::GridAxisClass::n_cells
private

number of cells in the axis

Definition at line 484 of file RawDataDrawer.cxx.


The documentation for this class was generated from the following file: