Skip to content
Snippets Groups Projects
IAxis.cpp 1.55 KiB
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Base/Axis/IAxis.cpp
//! @brief     Implements interface IAxis.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Base/Axis/IAxis.h"
#include "Base/Util/Assert.h"

IAxis::~IAxis() = default;

IAxis::IAxis(std::string name, const std::vector<Bin1D>& bins)
    : m_name(name)
    , m_bins(bins)
{
}

bool IAxis::equals(const IAxis& other) const
{
    return axisName() == other.axisName();
}

std::vector<double> IAxis::binCenters() const
{
    ASSERT(false); // not implemented
}

std::vector<double> IAxis::binBoundaries() const
{
    ASSERT(false); // not implemented
}

void IAxis::clip(double /*lower*/, double /*upper*/)
{
    ASSERT(false); // not implemented
}

void IAxis::clip(const std::pair<double, double> bounds)
{
    return clip(bounds.first, bounds.second);
}

bool IAxis::contains(double value) const
{
    return value >= min() && value < max();
}

std::pair<double, double> IAxis::bounds() const
{
    ASSERT(min() < max());
    return {min(), max()};
}

double IAxis::span() const
{
    return max() - min();
}

double IAxis::center() const
{
    return (max() + min()) / 2;
}