1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// ************************************************************************************************
//
// 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"
#include "Base/Axis/Bin.h"
#include <sstream>
//! @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
//! @param inverted swap inside/outside
Rectangle::Rectangle(double xlow, double ylow, double xup, double yup, bool inverted)
: IShape2D("Rectangle")
, m_inverted(inverted)
{
if (xup < xlow) {
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());
}
if (yup < ylow) {
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)
{
m_inverted = inverted;
}
bool Rectangle::contains(double x, double y) const
{
return m_inverted ^ (x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow);
}
bool Rectangle::contains(const Bin1D& binx, const Bin1D& biny) const
{
return m_inverted
^ (binx.max() > m_xlow && binx.min() < m_xup && biny.max() > m_ylow
&& biny.min() < m_yup);
}
double Rectangle::getArea() const
{
return (m_xup - m_xlow) * (m_yup - m_ylow);
}
|