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

An ellipse, for use in detector masks. More...

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

Public Member Functions

 Ellipse (double xcenter, double ycenter, double xradius, double yradius, double theta=0.0)
 
Ellipseclone () const
 
bool contains (const Bin1D &binx, const Bin1D &biny) const
 Returns true if area defined by two bins is inside or on border of ellipse; 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 getCenterX () const
 
double getCenterY () const
 
double getRadiusX () const
 
double getRadiusY () const
 
double getTheta () 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_theta
 
double m_xc
 
double m_xr
 
double m_yc
 
double m_yr
 

Detailed Description

An ellipse, for use in detector masks.

Definition at line 23 of file Ellipse.h.

Constructor & Destructor Documentation

◆ Ellipse()

Ellipse::Ellipse ( double  xcenter,
double  ycenter,
double  xradius,
double  yradius,
double  theta = 0.0 
)
Parameters
xcenterx-coordinate of Ellipse's center
ycentery-coordinate of Ellipse's center
xradiusRadius along x-axis
yradiusRadius along y-axis
thetaAngle of Ellipse rotation in radians

Definition at line 23 of file Ellipse.cpp.

24  : IShape2D("Ellipse")
25  , m_xc(xcenter)
26  , m_yc(ycenter)
27  , m_xr(xradius)
28  , m_yr(yradius)
29  , m_theta(theta)
30 {
31  if (xradius <= 0.0 || yradius <= 0.0)
32  throw std::runtime_error(
33  "Ellipse::Ellipse(double xcenter, double ycenter, double xradius, double yradius) "
34  "-> Error. Radius can't be negative\n");
35 }
double m_xc
Definition: Ellipse.h:38
double m_xr
Definition: Ellipse.h:38
double m_yc
Definition: Ellipse.h:38
double m_yr
Definition: Ellipse.h:38
double m_theta
Definition: Ellipse.h:38
IShape2D(const char *name)
Definition: IShape2D.h:29

Referenced by clone().

Member Function Documentation

◆ clone()

Ellipse* Ellipse::clone ( ) const
inlinevirtual

Implements IShape2D.

Definition at line 26 of file Ellipse.h.

26 { return new Ellipse(m_xc, m_yc, m_xr, m_yr, m_theta); }
Ellipse(double xcenter, double ycenter, double xradius, double yradius, double theta=0.0)
Definition: Ellipse.cpp:23

References Ellipse(), m_theta, m_xc, m_xr, m_yc, and m_yr.

Here is the call graph for this function:

◆ contains() [1/2]

bool Ellipse::contains ( const Bin1D binx,
const Bin1D biny 
) const
virtual

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

Implements IShape2D.

Definition at line 47 of file Ellipse.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: Ellipse.cpp:37
double center() const
Definition: Bin.h:25

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

Here is the call graph for this function:

◆ contains() [2/2]

bool Ellipse::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 37 of file Ellipse.cpp.

38 {
39  double u = std::cos(m_theta) * (x - m_xc) + std::sin(m_theta) * (y - m_yc);
40  double v = -std::sin(m_theta) * (x - m_xc) + std::cos(m_theta) * (y - m_yc);
41  double d = (u / m_xr) * (u / m_xr) + (v / m_yr) * (v / m_yr);
42  return d <= 1;
43 }

References m_theta, m_xc, m_xr, m_yc, and m_yr.

Referenced by contains().

◆ getCenterX()

double Ellipse::getCenterX ( ) const
inline

Definition at line 31 of file Ellipse.h.

31 { return m_xc; }

References m_xc.

◆ getCenterY()

double Ellipse::getCenterY ( ) const
inline

Definition at line 32 of file Ellipse.h.

32 { return m_yc; }

References m_yc.

◆ getRadiusX()

double Ellipse::getRadiusX ( ) const
inline

Definition at line 33 of file Ellipse.h.

33 { return m_xr; }

References m_xr.

◆ getRadiusY()

double Ellipse::getRadiusY ( ) const
inline

Definition at line 34 of file Ellipse.h.

34 { return m_yr; }

References m_yr.

◆ getTheta()

double Ellipse::getTheta ( ) const
inline

Definition at line 35 of file Ellipse.h.

35 { return m_theta; }

References m_theta.

◆ 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_theta

double Ellipse::m_theta
private

Definition at line 38 of file Ellipse.h.

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

◆ m_xc

double Ellipse::m_xc
private

Definition at line 38 of file Ellipse.h.

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

◆ m_xr

double Ellipse::m_xr
private

Definition at line 38 of file Ellipse.h.

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

◆ m_yc

double Ellipse::m_yc
private

Definition at line 38 of file Ellipse.h.

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

◆ m_yr

double Ellipse::m_yr
private

Definition at line 38 of file Ellipse.h.

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


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