Newer
Older
// ************************************************************************************************
// BornAgain: simulate and fit reflection and scattering
//! @file Device/Mask/Rectangle.cpp
//! @brief Implements class Rectangle.
//!
//! @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/Mask/Rectangle.h"

Wuttke, Joachim
committed
//! @param xlow x-coordinate of lower left corner
//! @param ylow y-coordinate of lower left corner
//! @param xup x-coordinate of upper right corner
//! @param yup y-coordinate of upper right corner
Rectangle::Rectangle(double xlow, double ylow, double xup, double yup, bool inverted)
: IShape2D("Rectangle"), m_inverted(inverted)
std::ostringstream message;
message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
message << " xup <= xlow" << std::endl;
throw std::runtime_error(message.str());
std::ostringstream message;
message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
message << " yup <= ylow" << std::endl;
throw std::runtime_error(message.str());
}
m_xlow = xlow;
m_ylow = ylow;
m_xup = xup;
m_yup = yup;
}
void Rectangle::setInverted(bool inverted /*= true*/)
{
m_inverted = inverted;
}
bool Rectangle::contains(double x, double y) const
{
const bool inRect = x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
return m_inverted ? !inRect : inRect;
bool Rectangle::contains(const Bin1D& binx, const Bin1D& biny) const
{
return contains(binx.center(), biny.center());
double Rectangle::getArea() const
{