BornAgain  1.19.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 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(const std::vector<double> x, const std::vector<double> y);
33  Polygon(const std::vector<std::vector<double>> points);
34  Polygon(const PolygonPrivate* d);
35 
36  virtual ~Polygon();
37 
38  virtual Polygon* clone() const { return new Polygon(m_d); }
39 
40  virtual bool contains(double x, double y) const;
41  virtual bool contains(const Bin1D& binx, const Bin1D& biny) const;
42 
43  double getArea() const;
44 
45  void getPoints(std::vector<double>& xpos, std::vector<double>& ypos) const;
46 
47 protected:
48  virtual void print(std::ostream& ostr) const;
49 
50 private:
52 };
53 
54 #endif // BORNAGAIN_DEVICE_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:25
A polygon, for use in detector masks.
Definition: Polygon.h:30
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
PolygonPrivate * m_d
Definition: Polygon.h:51
virtual Polygon * clone() const
Definition: Polygon.h:38
void getPoints(std::vector< double > &xpos, std::vector< double > &ypos) const
Definition: Polygon.cpp:114
virtual void print(std::ostream &ostr) const
Definition: Polygon.cpp:119
Polygon(const std::vector< double > x, const std::vector< double > y)
Definition: Polygon.cpp:63
virtual ~Polygon()
Definition: Polygon.cpp:93
double getArea() const
Definition: Polygon.cpp:109
Definition: Bin.h:20