BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Polygon.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Mask/Polygon.h
6 //! @brief Defines class Polygon.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_CORE_MASK_POLYGON_H
16 #define BORNAGAIN_CORE_MASK_POLYGON_H
17 
18 #include "Device/Mask/IShape2D.h"
19 #include <vector>
20 
21 class PolygonPrivate;
22 
23 //! A polygon in 2D space.
24 //! @ingroup mask
25 
26 //! Polygon defined by two arrays with x and y coordinates of points.
27 //! Sizes of arrays should coincide. If polygon is unclosed (the last point
28 //! doesn't repeat the first one), it will be closed automatically.
29 
30 class Polygon : public IShape2D
31 {
32 public:
33  Polygon(const std::vector<double> x, const std::vector<double> y);
34  Polygon(const std::vector<std::vector<double>> points);
35  Polygon(const PolygonPrivate* d);
36 
37  virtual ~Polygon();
38 
39  virtual Polygon* clone() const { return new Polygon(m_d); }
40 
41  virtual bool contains(double x, double y) const;
42  virtual bool contains(const Bin1D& binx, const Bin1D& biny) const;
43 
44  double getArea() const;
45 
46  void getPoints(std::vector<double>& xpos, std::vector<double>& ypos) const;
47 
48 protected:
49  virtual void print(std::ostream& ostr) const;
50 
51 private:
53 };
54 
55 #endif // BORNAGAIN_CORE_MASK_POLYGON_H
Defines basic class for all 2D shapes.
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
The private data for polygons to hide boost dependency from the header.
Definition: Polygon.cpp:27
A polygon in 2D space.
Definition: Polygon.h:31
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
PolygonPrivate * m_d
Definition: Polygon.h:52
virtual Polygon * clone() const
Definition: Polygon.h:39
void getPoints(std::vector< double > &xpos, std::vector< double > &ypos) const
Definition: Polygon.cpp:116
virtual void print(std::ostream &ostr) const
Definition: Polygon.cpp:121
Polygon(const std::vector< double > x, const std::vector< double > y)
Definition: Polygon.cpp:65
virtual ~Polygon()
Definition: Polygon.cpp:95
double getArea() const
Definition: Polygon.cpp:111
Definition: Bin.h:20