BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Rectangle Class Reference

Description

A rectangle, for use in detector masks.

Edges are along the coordinate axes.

Definition at line 25 of file Rectangle.h.

Inheritance diagram for Rectangle:
[legend]
Collaboration diagram for Rectangle:
[legend]

Public Member Functions

 Rectangle (double xlow, double ylow, double xup, double yup, bool inverted=false)
 
Rectangleclone () const override
 
bool contains (const Bin1D &binx, const Bin1D &biny) const override
 Returns true if area defined by two bins is inside or on border of polygon (more precisely, if mid point of two bins satisfy this condition). More...
 
bool contains (double x, double y) const override
 Returns true if point with given coordinates is inside or on border of the shape. More...
 
double getArea () const
 
double getXlow () const
 
double getXup () const
 
double getYlow () const
 
double getYup () const
 
void setInverted (bool inverted=true)
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 

Protected Member Functions

virtual void print (std::ostream &ostr) const
 

Private Attributes

bool m_inverted
 
const char *const m_name
 
double m_xlow
 
double m_xup
 
double m_ylow
 
double m_yup
 

Constructor & Destructor Documentation

◆ Rectangle()

Rectangle::Rectangle ( double  xlow,
double  ylow,
double  xup,
double  yup,
bool  inverted = false 
)
Parameters
xlowx-coordinate of lower left corner
ylowy-coordinate of lower left corner
xupx-coordinate of upper right corner
yupy-coordinate of upper right corner
invertedswap inside/outside

Definition at line 23 of file Rectangle.cpp.

24  : IShape2D("Rectangle")
25  , m_inverted(inverted)
26 {
27  if (xup <= xlow) {
28  std::ostringstream message;
29  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
30  message << " xup <= xlow" << std::endl;
31  throw std::runtime_error(message.str());
32  }
33  if (yup <= ylow) {
34  std::ostringstream message;
35  message << "Rectangle(double xlow, double ylow, double xup, double yup) -> Error. ";
36  message << " yup <= ylow" << std::endl;
37  throw std::runtime_error(message.str());
38  }
39  m_xlow = xlow;
40  m_ylow = ylow;
41  m_xup = xup;
42  m_yup = yup;
43 }
IShape2D(const char *name)
Definition: IShape2D.h:28
double m_xup
Definition: Rectangle.h:46
double m_ylow
Definition: Rectangle.h:46
bool m_inverted
Definition: Rectangle.h:47
double m_xlow
Definition: Rectangle.h:46
double m_yup
Definition: Rectangle.h:46

References m_xlow, m_xup, m_ylow, and m_yup.

Referenced by clone().

Member Function Documentation

◆ clone()

Rectangle* Rectangle::clone ( ) const
inlineoverridevirtual

Implements IShape2D.

Definition at line 28 of file Rectangle.h.

29  {
30  return new Rectangle(m_xlow, m_ylow, m_xup, m_yup, m_inverted);
31  }
Rectangle(double xlow, double ylow, double xup, double yup, bool inverted=false)
Definition: Rectangle.cpp:23

References Rectangle(), m_inverted, m_xlow, m_xup, m_ylow, and m_yup.

Here is the call graph for this function:

◆ contains() [1/2]

bool Rectangle::contains ( const Bin1D binx,
const Bin1D biny 
) const
overridevirtual

Returns true if area defined by two bins is inside or on border of polygon (more precisely, if mid point of two bins satisfy this condition).

Implements IShape2D.

Definition at line 56 of file Rectangle.cpp.

57 {
58  return contains(binx.center(), biny.center());
59 }
double center() const
Definition: Bin.h:30
bool contains(double x, double y) const override
Returns true if point with given coordinates is inside or on border of the shape.
Definition: Rectangle.cpp:50

References Bin1D::center(), and contains().

Here is the call graph for this function:

◆ contains() [2/2]

bool Rectangle::contains ( double  x,
double  y 
) const
overridevirtual

Returns true if point with given coordinates is inside or on border of the shape.

Implements IShape2D.

Definition at line 50 of file Rectangle.cpp.

51 {
52  const bool inRect = x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
53  return m_inverted ? !inRect : inRect;
54 }

References m_inverted, m_xlow, and m_ylow.

Referenced by contains().

◆ getArea()

double Rectangle::getArea ( ) const

Definition at line 61 of file Rectangle.cpp.

62 {
63  return (m_xup - m_xlow) * (m_yup - m_ylow);
64 }

References m_xlow, m_xup, m_ylow, and m_yup.

◆ getXlow()

double Rectangle::getXlow ( ) const
inline

Definition at line 40 of file Rectangle.h.

40 { return m_xlow; }

References m_xlow.

◆ getXup()

double Rectangle::getXup ( ) const
inline

Definition at line 42 of file Rectangle.h.

42 { return m_xup; }

References m_xup.

◆ getYlow()

double Rectangle::getYlow ( ) const
inline

Definition at line 41 of file Rectangle.h.

41 { return m_ylow; }

References m_ylow.

◆ getYup()

double Rectangle::getYup ( ) const
inline

Definition at line 43 of file Rectangle.h.

43 { return m_yup; }

References m_yup.

◆ print()

virtual void IShape2D::print ( std::ostream &  ostr) const
inlineprotectedvirtualinherited

Reimplemented in Polygon.

Definition at line 49 of file IShape2D.h.

49 { ostr << m_name; }
const char *const m_name
Definition: IShape2D.h:52

References IShape2D::m_name.

◆ setInverted()

void Rectangle::setInverted ( bool  inverted = true)

Definition at line 45 of file Rectangle.cpp.

46 {
47  m_inverted = inverted;
48 }

References m_inverted.

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 32 of file ICloneable.h.

Member Data Documentation

◆ m_inverted

bool Rectangle::m_inverted
private

Definition at line 47 of file Rectangle.h.

Referenced by clone(), contains(), and setInverted().

◆ m_name

const char* const IShape2D::m_name
privateinherited

Definition at line 52 of file IShape2D.h.

Referenced by IShape2D::print().

◆ m_xlow

double Rectangle::m_xlow
private

Definition at line 46 of file Rectangle.h.

Referenced by Rectangle(), clone(), contains(), getArea(), and getXlow().

◆ m_xup

double Rectangle::m_xup
private

Definition at line 46 of file Rectangle.h.

Referenced by Rectangle(), clone(), getArea(), and getXup().

◆ m_ylow

double Rectangle::m_ylow
private

Definition at line 46 of file Rectangle.h.

Referenced by Rectangle(), clone(), contains(), getArea(), and getYlow().

◆ m_yup

double Rectangle::m_yup
private

Definition at line 46 of file Rectangle.h.

Referenced by Rectangle(), clone(), getArea(), and getYup().


The documentation for this class was generated from the following files: