Skip to content
Snippets Groups Projects
Commit e84d7225 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

IAxis + sanity checks

parent 2d0320f2
No related branches found
No related tags found
1 merge request!1621Scale (IAxis) now without children
......@@ -39,7 +39,6 @@ DiscreteAxis::DiscreteAxis(const std::string& name, const std::vector<double>& p
{
ASSERT(size() == points.size());
ASSERT(size() == m_coordinates.size());
sanityCheck();
}
DiscreteAxis::DiscreteAxis(const std::string& name, size_t n, double first, double last)
......@@ -57,25 +56,6 @@ void DiscreteAxis::checkIndex(size_t index) const
throw std::runtime_error(message);
}
void DiscreteAxis::sanityCheck() const
{
if (m_coordinates.size() < 1)
throw std::runtime_error(
"Error in DiscreteAxis::DiscreteAxis: the size of passed coordinate array is "
"less than minimum acceptable value");
const auto begin = m_coordinates.begin();
const auto end = m_coordinates.end();
if (!std::is_sorted(begin, end))
throw std::runtime_error("Error in DiscreteAxis::DiscreteAxis: passed coordinates are "
"not sorted in ascending order");
if (std::adjacent_find(begin, end) != end)
throw std::runtime_error("Error in DiscreteAxis::DiscreteAxis: passed coordinate vector "
"contains repeating values");
}
IAxis* newDiscreteAxis(const std::string& name, const std::vector<double>& points)
{
return new IAxis(name, centers2bins(points));
......
......@@ -26,7 +26,6 @@ public:
private:
void checkIndex(size_t index) const;
void sanityCheck() const;
std::vector<double> m_coordinates;
};
......
......@@ -13,7 +13,6 @@
// ************************************************************************************************
#include "Base/Axis/IAxis.h"
#include "Base/Util/Algorithms.h"
#include "Base/Util/Assert.h"
#include <iomanip>
......@@ -21,6 +20,11 @@ IAxis::IAxis(std::string name, const std::vector<Bin1D>& bins)
: m_name(name)
, m_bins(bins)
{
ASSERT(size() > 0);
for (size_t i = 0; i < size() - 1; ++i) {
ASSERT(bin(i).upperBound() <= bin(i + 1).lowerBound()); // bins must not overlap
ASSERT(bin(i) != bin(i + 1)); // no duplicate bins
}
}
size_t IAxis::size() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment