BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Polygon Class Reference

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.

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

Public Member Functions

 Polygon (const PolygonPrivate *d)
 
 Polygon (std::vector< double > x, std::vector< double > y)
 If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically. More...
 
 Polygon (std::vector< std::pair< double, double >> points)
 If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically. More...
 
 ~Polygon () override
 
Polygonclone () const override
 
bool contains (const Bin1D &binx, const Bin1D &biny) const override
 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 override
 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

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

Private Attributes

PolygonPrivate * m_d
 
const char *const m_name
 

Constructor & Destructor Documentation

◆ Polygon() [1/3]

Polygon::Polygon ( std::vector< double >  x,
std::vector< double >  y 
)

If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically.

Parameters
xVector of x-coordinates of polygon points.
yVector of y-coordinates of polygon points.

Definition at line 71 of file Polygon.cpp.

72  : IShape2D("Polygon")
73  , m_d(new PolygonPrivate(x, y))
74 {
75 }
IShape2D(const char *name)
Definition: IShape2D.h:28
PolygonPrivate * m_d
Definition: Polygon.h:51

Referenced by clone().

◆ Polygon() [2/3]

Polygon::Polygon ( std::vector< std::pair< double, double >>  points)

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

83  : IShape2D("Polygon")
84  , m_d(new PolygonPrivate(points))
85 {
86 }

◆ Polygon() [3/3]

Polygon::Polygon ( const PolygonPrivate *  d)

Definition at line 88 of file Polygon.cpp.

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

◆ ~Polygon()

Polygon::~Polygon ( )
override

Definition at line 94 of file Polygon.cpp.

95 {
96  delete m_d;
97 }

References m_d.

Member Function Documentation

◆ clone()

Polygon* Polygon::clone ( ) const
inlineoverridevirtual

Implements IShape2D.

Definition at line 38 of file Polygon.h.

38 { return new Polygon(m_d); }
Polygon(std::vector< double > x, std::vector< double > y)
If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically...
Definition: Polygon.cpp:71

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
overridevirtual

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

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

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

Here is the call graph for this function:

◆ contains() [2/2]

bool Polygon::contains ( double  x,
double  y 
) const
overridevirtual

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

Implements IShape2D.

Definition at line 99 of file Polygon.cpp.

100 {
101  // including borders
102  return boost::geometry::covered_by(PolygonPrivate::point_t(x, y), m_d->polygon);
103 }

References m_d.

Referenced by contains().

◆ getArea()

double Polygon::getArea ( ) const

Definition at line 110 of file Polygon.cpp.

111 {
112  return boost::geometry::area(m_d->polygon);
113 }

References m_d.

◆ getPoints()

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

Definition at line 115 of file Polygon.cpp.

116 {
117  m_d->get_points(xpos, ypos);
118 }

References m_d.

◆ print()

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

Reimplemented from IShape2D.

Definition at line 120 of file Polygon.cpp.

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

References m_d.

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

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

Definition at line 32 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(), clone(), contains(), getArea(), getPoints(), and print().

◆ m_name

const char* const IShape2D::m_name
privateinherited

Definition at line 52 of file IShape2D.h.

Referenced by IShape2D::print().


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