BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Rectangle Class Reference

A rectangle, for use in detector masks. More...

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

Public Member Functions

 Rectangle (double xlow, double ylow, double xup, double yup)
 
Rectangleclone () const
 
bool contains (const Bin1D &binx, const Bin1D &biny) const
 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
 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
 
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

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

Detailed Description

A rectangle, for use in detector masks.

Edges are along the coordinate axes.

Definition at line 25 of file Rectangle.h.

Constructor & Destructor Documentation

◆ Rectangle()

Rectangle::Rectangle ( double  xlow,
double  ylow,
double  xup,
double  yup 
)
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

Definition at line 22 of file Rectangle.cpp.

22  : 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 }
IShape2D(const char *name)
Definition: IShape2D.h:29
double m_xup
Definition: Rectangle.h:41
double m_ylow
Definition: Rectangle.h:41
double m_xlow
Definition: Rectangle.h:41
double m_yup
Definition: Rectangle.h:41

References m_xlow, m_xup, m_ylow, and m_yup.

Referenced by clone().

Member Function Documentation

◆ clone()

Rectangle* Rectangle::clone ( ) const
inlinevirtual

Implements IShape2D.

Definition at line 28 of file Rectangle.h.

28 { return new Rectangle(m_xlow, m_ylow, m_xup, m_yup); }
Rectangle(double xlow, double ylow, double xup, double yup)
Definition: Rectangle.cpp:22

References Rectangle(), 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
virtual

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 47 of file Rectangle.cpp.

48 {
49  return contains(binx.center(), biny.center());
50 }
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 center() const
Definition: Bin.h:25

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

Here is the call graph for this function:

◆ contains() [2/2]

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

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

Implements IShape2D.

Definition at line 42 of file Rectangle.cpp.

43 {
44  return x <= m_xup && x >= m_xlow && y <= m_yup && y >= m_ylow;
45 }

References m_xlow, and m_ylow.

Referenced by contains().

◆ getArea()

double Rectangle::getArea ( ) const

Definition at line 52 of file Rectangle.cpp.

53 {
54  return (m_xup - m_xlow) * (m_yup - m_ylow);
55 }

References m_xlow, m_xup, m_ylow, and m_yup.

◆ getXlow()

double Rectangle::getXlow ( ) const
inline

Definition at line 35 of file Rectangle.h.

35 { return m_xlow; }

References m_xlow.

◆ getXup()

double Rectangle::getXup ( ) const
inline

Definition at line 37 of file Rectangle.h.

37 { return m_xup; }

References m_xup.

◆ getYlow()

double Rectangle::getYlow ( ) const
inline

Definition at line 36 of file Rectangle.h.

36 { return m_ylow; }

References m_ylow.

◆ getYup()

double Rectangle::getYup ( ) const
inline

Definition at line 38 of file Rectangle.h.

38 { return m_yup; }

References m_yup.

◆ print()

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

Reimplemented in Polygon.

Definition at line 46 of file IShape2D.h.

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

References IShape2D::m_name.

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

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

Definition at line 34 of file ICloneable.h.

Member Data Documentation

◆ m_name

const char* const IShape2D::m_name
privateinherited

Definition at line 49 of file IShape2D.h.

Referenced by IShape2D::print().

◆ m_xlow

double Rectangle::m_xlow
private

Definition at line 41 of file Rectangle.h.

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

◆ m_xup

double Rectangle::m_xup
private

Definition at line 41 of file Rectangle.h.

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

◆ m_ylow

double Rectangle::m_ylow
private

Definition at line 41 of file Rectangle.h.

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

◆ m_yup

double Rectangle::m_yup
private

Definition at line 41 of file Rectangle.h.

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


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