BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
geometry_inc.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/model/geometry_inc.cpp
6 //! @brief Implements geometry namespace
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 
16 #include <cmath>
17 #include <functional>
18 
19 namespace GUI::RealSpace {
20 
21 // Useful constants:
22 const float GoldenRatio = (1.f + std::sqrt(5.f)) / 2.f;
23 const float IcosahedronL2R = 4.f / (10.f + 2.f * std::sqrt(5.f));
24 const float DodecahedronL2R = 4.f / std::sqrt(3.f) / (1.f + std::sqrt(5.f));
25 
26 // Keys and hash:
27 GeometricID::Key::Key(BaseShape id_, float p1_, float p2_, float p3_)
28  : id(id_)
29  , p1(p1_)
30  , p2(p2_)
31  , p3(p3_)
32 {
33 }
34 
35 bool GeometricID::Key::operator==(Key const& other) const
36 {
37  return id == other.id && p1 == other.p1 && p2 == other.p2;
38 }
39 
40 std::size_t GeometricID::KeyHash::operator()(const GeometricID::Key& key) const noexcept
41 {
42  {
43  size_t h1 = std::hash<int>{}(static_cast<int>(key.id));
44  size_t h2 = std::hash<float>{}(key.p1);
45  size_t h3 = std::hash<float>{}(key.p2);
46  size_t h4 = std::hash<float>{}(key.p3);
47  return h1 ^ (h2 ^ (h3 ^ h4));
48  }
49 }
50 
51 } // namespace GUI::RealSpace
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
Defines namespace GUI::RealSpace::GeometricID.
BaseShape
Enum id for basic shapes.
Definition: geometry_inc.h:38
const float DodecahedronL2R
const float IcosahedronL2R
const float GoldenRatio
std::size_t operator()(const Key &key) const noexcept
Real shapes will be parameterized by BaseShape enum and possibly two floats.
Definition: geometry_inc.h:51
bool operator==(Key const &) const
Key(BaseShape, float=0.0f, float=0.0f, float=0.0f)