BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IShape2D.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Mask/IShape2D.h
6 //! @brief Defines basic class for all 2D shapes.
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_ISHAPE2D_H
16 #define BORNAGAIN_DEVICE_MASK_ISHAPE2D_H
17 
18 #include "Base/Types/ICloneable.h"
19 #include <iostream>
20 
21 class Bin1D;
22 
23 //! Basic class for all shapes in 2D.
24 //! @ingroup tools
25 
26 class IShape2D : public ICloneable {
27 public:
28  IShape2D(const char* name)
29  : m_name(name)
30  {
31  }
32  ~IShape2D() override = default;
33  IShape2D* clone() const override = 0;
34 
35  //! Returns true if point with given coordinates is inside or on border of the shape.
36  virtual bool contains(double x, double y) const = 0;
37 
38  //! Returns true if area defined by two bins is inside or on border of polygon
39  //! (more precisely, if mid point of two bins satisfy this condition).
40  virtual bool contains(const Bin1D& binx, const Bin1D& biny) const = 0;
41 
42  friend std::ostream& operator<<(std::ostream& ostr, const IShape2D& shape)
43  {
44  shape.print(ostr);
45  return ostr;
46  }
47 
48 protected:
49  virtual void print(std::ostream& ostr) const { ostr << m_name; }
50 
51 private:
52  const char* const m_name;
53 };
54 
55 #endif // BORNAGAIN_DEVICE_MASK_ISHAPE2D_H
Defines and implements the standard mix-in ICloneable.
Definition: Bin.h:20
Interface for polymorphic classes that should not be copied, except by explicit cloning.
Definition: ICloneable.h:23
Basic class for all shapes in 2D.
Definition: IShape2D.h:26
const char *const m_name
Definition: IShape2D.h:52
virtual void print(std::ostream &ostr) const
Definition: IShape2D.h:49
virtual bool contains(const Bin1D &binx, const Bin1D &biny) const =0
Returns true if area defined by two bins is inside or on border of polygon (more precisely,...
~IShape2D() override=default
IShape2D * clone() const override=0
IShape2D(const char *name)
Definition: IShape2D.h:28
virtual bool contains(double x, double y) const =0
Returns true if point with given coordinates is inside or on border of the shape.
friend std::ostream & operator<<(std::ostream &ostr, const IShape2D &shape)
Definition: IShape2D.h:42