BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
def.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/def.cpp
6 //! @brief Definitions
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 #include "GUI/ba3d/def.h"
16 
17 static_assert(QT_VERSION >= QT_VERSION_CHECK(5, 5, 1),
18  "requires Qt >= 5.5.1, have " QT_VERSION_STR);
19 
20 namespace GUI::RealSpace {
21 
23  : Vector3D(0, 0, 0)
24 {
25 }
26 
28  : Vector3D(v, v, v)
29 {
30 }
31 
32 Vector3D::Vector3D(float x_, float y_, float z_)
33  : x(x_)
34  , y(y_)
35  , z(z_)
36 {
37 }
38 
39 Vector3D::Vector3D(QVector3D const& v)
40  : Vector3D(v.x(), v.y(), v.z())
41 {
42 }
43 
44 float Vector3D::length() const
45 {
46  return QVector3D(*this).length();
47 }
48 
50 {
51  return QVector3D(*this).normalized();
52 }
53 
54 Vector3D Vector3D::interpolateTo(const Vector3D& to, float rat) const
55 {
56  return *this * (1 - rat) + to * rat;
57 }
58 
59 GUI::RealSpace::Vector3D::operator QVector3D() const
60 {
61  return QVector3D(x, y, z);
62 }
63 
64 Vector3D const Vector3D::_0(0, 0, 0), Vector3D::_1(1, 1, 1), Vector3D::_x(1, 0, 0),
65  Vector3D::_y(0, 1, 0), Vector3D::_z(0, 0, 1);
66 
67 Vector3D cross(const Vector3D& v1, const Vector3D& v2)
68 {
69  return QVector3D::crossProduct(v1, v2);
70 }
71 
72 float dot(const Vector3D& v1, const Vector3D& v2)
73 {
74  return QVector3D::dotProduct(v1, v2);
75 }
76 
78 {
79  return v;
80 }
81 
83 {
84  return Vector3D::_0 - v;
85 }
86 
87 Vector3D operator*(const Vector3D& v, float f)
88 {
89  return Vector3D(v.x * f, v.y * f, v.z * f);
90 }
91 
92 Vector3D operator+(const Vector3D& _1, const Vector3D& _2)
93 {
94  return Vector3D(_1.x + _2.x, _1.y + _2.y, _1.z + _2.z);
95 }
96 
97 Vector3D operator-(const Vector3D& _1, const Vector3D& _2)
98 {
99  return Vector3D(_1.x - _2.x, _1.y - _2.y, _1.z - _2.z);
100 }
101 
102 
103 Range::Range(float r1, float r2)
104  : min(qMin(r1, r2))
105  , max(qMax(r1, r2))
106 {
107 }
108 
109 float Range::size() const
110 {
111  return max - min;
112 }
113 
114 float Range::mid() const
115 {
116  return (min + max) / 2;
117 }
118 
119 
121  : x(x_)
122  , y(y_)
123  , z(z_)
124 {
125 }
126 
128  : x(Range(_1.x, _2.x))
129  , y(Range(_1.y, _2.y))
130  , z(Range(_1.z, _2.z))
131 {
132 }
133 
135 {
136  return Vector3D(x.size(), y.size(), z.size());
137 }
138 
140 {
141  return Vector3D(x.mid(), y.mid(), z.mid());
142 }
143 
144 float VectorRange::length() const
145 {
146  return Vector3D(x.size(), y.size(), z.size()).length();
147 }
148 
149 } // namespace GUI::RealSpace
Definitions in namespace GUI::RealSpace.
Vector3D operator*(const Vector3D &v, float f)
Definition: def.cpp:87
Vector3D cross(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:67
Vector3D operator-(const Vector3D &v)
Definition: def.cpp:82
Vector3D operator+(const Vector3D &v)
Definition: def.cpp:77
float dot(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:72
Range of float.
Definition: def.h:61
float mid() const
Definition: def.cpp:114
float size() const
Definition: def.cpp:109
Range(float, float)
Definition: def.cpp:103
static Vector3D const _y
Definition: def.h:46
static Vector3D const _x
Definition: def.h:46
static Vector3D const _z
Definition: def.h:46
static Vector3D const _0
Definition: def.h:46
Vector3D normalized() const
Definition: def.cpp:49
Vector3D interpolateTo(const Vector3D &, float) const
Definition: def.cpp:54
static Vector3D const _1
Definition: def.h:46
float length() const
Definition: def.cpp:44
VectorRange(Range, Range, Range)
Definition: def.cpp:120
float length() const
Definition: def.cpp:144
Vector3D mid() const
Definition: def.cpp:139
Vector3D size() const
Definition: def.cpp:134