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

Public Member Functions

 Polygon (const std::vector< double > x, const std::vector< double > y)
 
 Polygon (const std::vector< std::vector< double >> points)
 
 Polygon (const PolygonPrivate *d)
 
virtual ~Polygon ()
 
virtual Polygonclone () const
 
virtual bool contains (double x, double y) const
 
virtual bool contains (const Bin1D &binx, const Bin1D &biny) const
 
double getArea () const
 
void getPoints (std::vector< double > &xpos, std::vector< double > &ypos) const
 
virtual void transferToCPP ()
 

Protected Member Functions

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

Private Attributes

PolygonPrivatem_d
 
const char *const m_name
 

Detailed Description

A polygon in 2D space.

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 65 of file Polygon.cpp.

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

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 77 of file Polygon.cpp.

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

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 93 of file Polygon.cpp.

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

◆ ~Polygon()

Polygon::~Polygon ( )
virtual

Definition at line 95 of file Polygon.cpp.

96 {
97  delete m_d;
98 }

References m_d.

Member Function Documentation

◆ clone()

virtual Polygon* Polygon::clone ( ) const
inlinevirtual

Implements IShape2D.

Definition at line 39 of file Polygon.h.

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

References m_d, and Polygon().

Here is the call graph for this function:

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

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

References m_d, and PolygonPrivate::polygon.

Referenced by contains().

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

107 {
108  return contains(binx.getMidPoint(), biny.getMidPoint());
109 }
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:100
double getMidPoint() const
Definition: Bin.h:25

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

Here is the call graph for this function:

◆ getArea()

double Polygon::getArea ( ) const

Definition at line 111 of file Polygon.cpp.

112 {
113  return area(m_d->polygon);
114 }

References m_d, and PolygonPrivate::polygon.

◆ getPoints()

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

Definition at line 116 of file Polygon.cpp.

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

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 121 of file Polygon.cpp.

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

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 52 of file Polygon.h.

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

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