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