BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Polygon.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
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_DEVICE_MASK_POLYGON_H
16 #define BORNAGAIN_DEVICE_MASK_POLYGON_H
17 
18 #include "Device/Mask/IShape2D.h"
19 #include <vector>
20 
21 class PolygonPrivate;
22 
23 //! A polygon, for use in detector masks.
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 public:
32  Polygon(std::vector<double> x, std::vector<double> y);
33  Polygon(std::vector<std::pair<double, double>> points);
34  Polygon(const PolygonPrivate* d);
35 
36  ~Polygon() override;
37 
38  Polygon* clone() const override { return new Polygon(m_d); }
39 
40  bool contains(double x, double y) const override;
41  bool contains(const Bin1D& binx, const Bin1D& biny) const override;
42 
43  double getArea() const;
44 
45  void getPoints(std::vector<double>& xpos, std::vector<double>& ypos) const;
46 
47 protected:
48  void print(std::ostream& ostr) const override;
49 
50 private:
51  PolygonPrivate* m_d;
52 };
53 
54 #endif // BORNAGAIN_DEVICE_MASK_POLYGON_H
Defines basic class for all 2D shapes.
Definition: Bin.h:20
Basic class for all shapes in 2D.
Definition: IShape2D.h:26
A polygon, for use in detector masks.
Definition: Polygon.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
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
PolygonPrivate * m_d
Definition: Polygon.h:51
Polygon * clone() const override
Definition: Polygon.h:38
void getPoints(std::vector< double > &xpos, std::vector< double > &ypos) const
Definition: Polygon.cpp:115
void print(std::ostream &ostr) const override
Definition: Polygon.cpp:120
~Polygon() override
Definition: Polygon.cpp:94
double getArea() const
Definition: Polygon.cpp:110