BornAgain  1.19.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 reflection and scattering
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 
18 //! @param xlow x-coordinate of lower left corner
19 //! @param ylow y-coordinate of lower left corner
20 //! @param xup x-coordinate of upper right corner
21 //! @param yup y-coordinate of upper right corner
22 Rectangle::Rectangle(double xlow, double ylow, double xup, double yup) : IShape2D("Rectangle")
23 {
24  if (xup <= xlow) {
25  std::ostringstream message;
26  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
27  message << " xup <= xlow" << std::endl;
28  throw std::runtime_error(message.str());
29  }
30  if (yup <= ylow) {
31  std::ostringstream message;
32  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
33  message << " yup <= ylow" << std::endl;
34  throw std::runtime_error(message.str());
35  }
36  m_xlow = xlow;
37  m_ylow = ylow;
38  m_xup = xup;
39  m_yup = yup;
40 }
41 
42 bool Rectangle::contains(double x, double y) const
43 {
44  return x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
45 }
46 
47 bool Rectangle::contains(const Bin1D& binx, const Bin1D& biny) const
48 {
49  return contains(binx.center(), biny.center());
50 }
51 
52 double Rectangle::getArea() const
53 {
54  return (m_xup - m_xlow) * (m_yup - m_ylow);
55 }
Defines structs Bin1D, Bin1DCVector.
Defines class Rectangle.
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
double m_xup
Definition: Rectangle.h:41
double m_ylow
Definition: Rectangle.h:41
Rectangle(double xlow, double ylow, double xup, double yup)
Definition: Rectangle.cpp:22
double m_xlow
Definition: Rectangle.h:41
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:42
double getArea() const
Definition: Rectangle.cpp:52
double m_yup
Definition: Rectangle.h:41
Definition: Bin.h:20
double center() const
Definition: Bin.h:25