BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ISelectionRule.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Lattice/ISelectionRule.h
6 //! @brief Defines classes ISelectionRule, SimpleSelectionRule
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 USER_API
16 #ifndef BORNAGAIN_SAMPLE_LATTICE_ISELECTIONRULE_H
17 #define BORNAGAIN_SAMPLE_LATTICE_ISELECTIONRULE_H
18 
19 #include "Base/Vector/Vectors3D.h"
20 
21 //! Abstract base class for selection rules.
22 //! @ingroup samples_internal
23 
25 public:
26  virtual ~ISelectionRule() {}
27 
28  virtual ISelectionRule* clone() const = 0;
29 
30  virtual bool coordinateSelected(const ivector_t& coordinate) const = 0;
31 };
32 
33 //! Selection rule (v*q)%modulus!=0, defined by vector v(a,b,c) and modulus.
34 //! @ingroup samples_internal
35 
37 public:
38  SimpleSelectionRule(int a, int b, int c, int modulus);
39  virtual ~SimpleSelectionRule() {}
40 
41  virtual SimpleSelectionRule* clone() const;
42 
43  virtual bool coordinateSelected(const ivector_t& coordinate) const;
44 
45 private:
46  int m_a, m_b, m_c;
47  int m_mod;
48 };
49 
50 inline SimpleSelectionRule::SimpleSelectionRule(int a, int b, int c, int modulus)
51  : m_a(a), m_b(b), m_c(c), m_mod(modulus)
52 {
53 }
54 
56 {
57  return new SimpleSelectionRule(m_a, m_b, m_c, m_mod);
58 }
59 
60 inline bool SimpleSelectionRule::coordinateSelected(const ivector_t& coordinate) const
61 {
62  return (m_a * coordinate[0] + m_b * coordinate[1] + m_c * coordinate[2]) % m_mod == 0;
63 }
64 
65 #endif // BORNAGAIN_SAMPLE_LATTICE_ISELECTIONRULE_H
66 #endif // USER_API
Defines basic vectors in Z^3, R^3, C^3.
Three-dimensional vector template, for use with integer, double, or complex components.
Definition: BasicVector3D.h:27
Abstract base class for selection rules.
virtual bool coordinateSelected(const ivector_t &coordinate) const =0
virtual ISelectionRule * clone() const =0
virtual ~ISelectionRule()
Selection rule (v*q)modulus!=0, defined by vector v(a,b,c) and modulus.
SimpleSelectionRule(int a, int b, int c, int modulus)
virtual SimpleSelectionRule * clone() const
virtual bool coordinateSelected(const ivector_t &coordinate) const
virtual ~SimpleSelectionRule()