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

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

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

Public Member Functions

 Polygon (const PolygonPrivate *d)
 
 Polygon (const std::vector< double > x, const std::vector< double > y)
 
 Polygon (const std::vector< std::vector< double >> points)
 Polygon defined by two dimensional array with (x,y) coordinates of polygon points. More...
 
virtual ~Polygon ()
 
virtual Polygonclone () const
 
virtual 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...
 
virtual 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
 
void getPoints (std::vector< double > &xpos, std::vector< double > &ypos) 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

PolygonPrivatem_d
 
const char *const m_name
 

Detailed Description

A polygon, for use in detector masks.

Polygon defined by two arrays with x and y coordinates of points. Sizes of arrays should coincide. If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically.

Definition at line 30 of file Polygon.h.

Constructor & Destructor Documentation

◆ Polygon() [1/3]

Polygon::Polygon ( const std::vector< double >  x,
const std::vector< double >  y 
)
Parameters
xVector of x-coordinates of polygon points.
yVector of y-coordinates of polygon points.

Definition at line 63 of file Polygon.cpp.

64  : IShape2D("Polygon"), m_d(new PolygonPrivate)
65 {
66  m_d->init_from(x, y);
67 }
IShape2D(const char *name)
Definition: IShape2D.h:29
The private data for polygons to hide boost dependency from the header.
Definition: Polygon.cpp:25
void init_from(const std::vector< double > &x, const std::vector< double > &y)
Definition: Polygon.cpp:34
PolygonPrivate * m_d
Definition: Polygon.h:51

References PolygonPrivate::init_from(), and m_d.

Referenced by clone().

Here is the call graph for this function:

◆ Polygon() [2/3]

Polygon::Polygon ( const std::vector< std::vector< double >>  points)

Polygon defined by two dimensional array with (x,y) coordinates of polygon points.

The size of second dimension should be 2. If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically.

Parameters
pointsTwo dimensional vector of (x,y) coordinates of polygon points.

Definition at line 75 of file Polygon.cpp.

76  : IShape2D("Polygon"), m_d(new PolygonPrivate)
77 {
78  std::vector<double> x;
79  std::vector<double> y;
80  for (size_t i = 0; i < points.size(); ++i) {
81  if (points[i].size() != 2)
82  throw std::runtime_error(
83  "Polygon(const std::vector<std::vector<double> >& points) -> Error. "
84  " Should be two-dimensional array with second dimension of 2 size.");
85  x.push_back(points[i][0]);
86  y.push_back(points[i][1]);
87  }
88  m_d->init_from(x, y);
89 }

References PolygonPrivate::init_from(), and m_d.

Here is the call graph for this function:

◆ Polygon() [3/3]

Polygon::Polygon ( const PolygonPrivate d)

Definition at line 91 of file Polygon.cpp.

91 : IShape2D("Polygon"), m_d(new PolygonPrivate(*d)) {}

◆ ~Polygon()

Polygon::~Polygon ( )
virtual

Definition at line 93 of file Polygon.cpp.

94 {
95  delete m_d;
96 }

References m_d.

Member Function Documentation

◆ clone()

virtual Polygon* Polygon::clone ( ) const
inlinevirtual

Implements IShape2D.

Definition at line 38 of file Polygon.h.

38 { return new Polygon(m_d); }
Polygon(const std::vector< double > x, const std::vector< double > y)
Definition: Polygon.cpp:63

References Polygon(), and m_d.

Here is the call graph for this function:

◆ contains() [1/2]

bool Polygon::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 104 of file Polygon.cpp.

105 {
106  return contains(binx.center(), biny.center());
107 }
virtual bool contains(double x, double y) const
Returns true if point with given coordinates is inside or on border of the shape.
Definition: Polygon.cpp:98
double center() const
Definition: Bin.h:25

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

Here is the call graph for this function:

◆ contains() [2/2]

bool Polygon::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 98 of file Polygon.cpp.

99 {
100  // return within(PolygonPrivate::point_t(x, y), m_d->polygon); // not including borders
101  return covered_by(PolygonPrivate::point_t(x, y), m_d->polygon); // including borders
102 }
model::d2::point_xy< double > point_t
Definition: Polygon.cpp:27
polygon_t polygon
Definition: Polygon.cpp:29

References m_d, and PolygonPrivate::polygon.

Referenced by contains().

◆ getArea()

double Polygon::getArea ( ) const

Definition at line 109 of file Polygon.cpp.

110 {
111  return area(m_d->polygon);
112 }

References m_d, and PolygonPrivate::polygon.

◆ getPoints()

void Polygon::getPoints ( std::vector< double > &  xpos,
std::vector< double > &  ypos 
) const

Definition at line 114 of file Polygon.cpp.

115 {
116  m_d->get_points(xpos, ypos);
117 }
void get_points(std::vector< double > &xpos, std::vector< double > &ypos)
Definition: Polygon.cpp:47

References PolygonPrivate::get_points(), and m_d.

Here is the call graph for this function:

◆ print()

void Polygon::print ( std::ostream &  ostr) const
protectedvirtual

Reimplemented from IShape2D.

Definition at line 119 of file Polygon.cpp.

120 {
121  ostr << wkt<PolygonPrivate::polygon_t>(m_d->polygon);
122 }

References m_d, and PolygonPrivate::polygon.

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

PolygonPrivate* Polygon::m_d
private

Definition at line 51 of file Polygon.h.

Referenced by Polygon(), ~Polygon(), clone(), contains(), getArea(), getPoints(), and print().

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