//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Device/Resolution/ResolutionFunction2DGaussian.cpp
//! @brief     Implements class ResolutionFunction2DGaussian.
//!
//! @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 "Device/Resolution/ResolutionFunction2DGaussian.h"
#include "Base/Math/Functions.h"
#include "Base/Util/Assert.h"

ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(double sigma_x, double sigma_y)
    : m_sigma_x(sigma_x)
    , m_sigma_y(sigma_y)
{
    ResolutionFunction2DGaussian::validate();
}

void ResolutionFunction2DGaussian::validate() const
{
    if (m_sigma_x < 0)
        throw std::runtime_error("sigma_x < 0");
    if (m_sigma_y < 0)
        throw std::runtime_error("sigma_y < 0");
    m_validated = true;
}
double ResolutionFunction2DGaussian::evaluateCDF(double x, double y) const
{
    ASSERT(m_validated);
    return Math::integratedGaussian(x, 0.0, m_sigma_x)
           * Math::integratedGaussian(y, 0.0, m_sigma_y);
}
