BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Rectangle.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Mask/Rectangle.cpp
6 //! @brief Implements class Rectangle.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #include "Device/Mask/Rectangle.h"
16 #include "Base/Axis/Bin.h"
17 #include "Base/Types/Exceptions.h"
18 
19 //! @param xlow x-coordinate of lower left corner
20 //! @param ylow y-coordinate of lower left corner
21 //! @param xup x-coordinate of upper right corner
22 //! @param yup y-coordinate of upper right corner
23 Rectangle::Rectangle(double xlow, double ylow, double xup, double yup) : IShape2D("Rectangle")
24 {
25  if (xup <= xlow) {
26  std::ostringstream message;
27  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
28  message << " xup <= xlow" << std::endl;
29  throw Exceptions::LogicErrorException(message.str());
30  }
31  if (yup <= ylow) {
32  std::ostringstream message;
33  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
34  message << " yup <= ylow" << std::endl;
35  throw Exceptions::LogicErrorException(message.str());
36  }
37  m_xlow = xlow;
38  m_ylow = ylow;
39  m_xup = xup;
40  m_yup = yup;
41 }
42 
43 bool Rectangle::contains(double x, double y) const
44 {
45  return x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
46 }
47 
48 bool Rectangle::contains(const Bin1D& binx, const Bin1D& biny) const
49 {
50  return contains(binx.getMidPoint(), biny.getMidPoint());
51 }
52 
53 double Rectangle::getArea() const
54 {
55  return (m_xup - m_xlow) * (m_yup - m_ylow);
56 }
Defines structs Bin1D, Bin1DCVector.
Defines many exception classes in namespace Exceptionss.
Defines class Rectangle.
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
double m_xup
Definition: Rectangle.h:40
double m_ylow
Definition: Rectangle.h:40
Rectangle(double xlow, double ylow, double xup, double yup)
Definition: Rectangle.cpp:23
double m_xlow
Definition: Rectangle.h:40
bool contains(double x, double y) const
Returns true if point with given coordinates is inside or on border of the shape.
Definition: Rectangle.cpp:43
double getArea() const
Definition: Rectangle.cpp:53
double m_yup
Definition: Rectangle.h:40
Definition: Bin.h:20
double getMidPoint() const
Definition: Bin.h:25