BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Rectangle Class Reference
Inheritance diagram for Rectangle:
Collaboration diagram for Rectangle:

Public Member Functions

 Rectangle (double xlow, double ylow, double xup, double yup)
 
Rectangleclone () const
 
bool contains (double x, double y) const
 
bool contains (const Bin1D &binx, const Bin1D &biny) const
 
double getArea () const
 
double getXlow () const
 
double getYlow () const
 
double getXup () const
 
double getYup () const
 
virtual void transferToCPP ()
 

Protected Member Functions

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

Private Attributes

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

Detailed Description

The rectangle shape having its axis aligned to the (non-rotated) coordinate system.

Definition at line 23 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 23 of file Rectangle.cpp.

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

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 27 of file Rectangle.h.

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

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

Here is the call graph for this function:

◆ contains() [1/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 43 of file Rectangle.cpp.

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

References m_xlow, and m_ylow.

Referenced by contains().

◆ contains() [2/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 48 of file Rectangle.cpp.

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

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

Here is the call graph for this function:

◆ getArea()

double Rectangle::getArea ( ) const

Definition at line 53 of file Rectangle.cpp.

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

References m_xlow, m_xup, m_ylow, and m_yup.

◆ getXlow()

double Rectangle::getXlow ( ) const
inline

Definition at line 34 of file Rectangle.h.

34 { return m_xlow; }

References m_xlow.

◆ getYlow()

double Rectangle::getYlow ( ) const
inline

Definition at line 35 of file Rectangle.h.

35 { return m_ylow; }

References m_ylow.

◆ getXup()

double Rectangle::getXup ( ) const
inline

Definition at line 36 of file Rectangle.h.

36 { return m_xup; }

References m_xup.

◆ getYup()

double Rectangle::getYup ( ) const
inline

Definition at line 37 of file Rectangle.h.

37 { 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_xlow

double Rectangle::m_xlow
private

Definition at line 40 of file Rectangle.h.

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

◆ m_ylow

double Rectangle::m_ylow
private

Definition at line 40 of file Rectangle.h.

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

◆ m_xup

double Rectangle::m_xup
private

Definition at line 40 of file Rectangle.h.

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

◆ m_yup

double Rectangle::m_yup
private

Definition at line 40 of file Rectangle.h.

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

◆ m_name

const char* const IShape2D::m_name
privateinherited

Definition at line 49 of file IShape2D.h.

Referenced by IShape2D::print().


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