BornAgain  1.19.0
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 RealSpace {
21 //------------------------------------------------------------------------------
22 
24 
25 Vector3D::Vector3D(float v) : Vector3D(v, v, v) {}
26 
27 Vector3D::Vector3D(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
28 
29 Vector3D::Vector3D(QVector3D const& v) : Vector3D(v.x(), v.y(), v.z()) {}
30 
31 float Vector3D::length() const
32 {
33  return QVector3D(*this).length();
34 }
35 
37 {
38  return QVector3D(*this).normalized();
39 }
40 
41 Vector3D Vector3D::interpolateTo(const Vector3D& to, float rat) const
42 {
43  return *this * (1 - rat) + to * rat;
44 }
45 
46 RealSpace::Vector3D::operator QVector3D() const
47 {
48  return QVector3D(x, y, z);
49 }
50 
51 Vector3D const Vector3D::_0(0, 0, 0), Vector3D::_1(1, 1, 1), Vector3D::_x(1, 0, 0),
52  Vector3D::_y(0, 1, 0), Vector3D::_z(0, 0, 1);
53 
54 Vector3D cross(const Vector3D& v1, const Vector3D& v2)
55 {
56  return QVector3D::crossProduct(v1, v2);
57 }
58 
59 float dot(const Vector3D& v1, const Vector3D& v2)
60 {
61  return QVector3D::dotProduct(v1, v2);
62 }
63 
65 {
66  return v;
67 }
68 
70 {
71  return Vector3D::_0 - v;
72 }
73 
74 Vector3D operator*(const Vector3D& v, float f)
75 {
76  return Vector3D(v.x * f, v.y * f, v.z * f);
77 }
78 
79 Vector3D operator+(const Vector3D& _1, const Vector3D& _2)
80 {
81  return Vector3D(_1.x + _2.x, _1.y + _2.y, _1.z + _2.z);
82 }
83 
84 Vector3D operator-(const Vector3D& _1, const Vector3D& _2)
85 {
86  return Vector3D(_1.x - _2.x, _1.y - _2.y, _1.z - _2.z);
87 }
88 
89 //------------------------------------------------------------------------------
90 
91 Range::Range(float r1, float r2) : min(qMin(r1, r2)), max(qMax(r1, r2)) {}
92 
93 float Range::size() const
94 {
95  return max - min;
96 }
97 
98 float Range::mid() const
99 {
100  return (min + max) / 2;
101 }
102 
103 //------------------------------------------------------------------------------
104 
105 VectorRange::VectorRange(Range x_, Range y_, Range z_) : x(x_), y(y_), z(z_) {}
106 
108  : x(Range(_1.x, _2.x)), y(Range(_1.y, _2.y)), z(Range(_1.z, _2.z))
109 {
110 }
111 
113 {
114  return Vector3D(x.size(), y.size(), z.size());
115 }
116 
118 {
119  return Vector3D(x.mid(), y.mid(), z.mid());
120 }
121 
122 float VectorRange::length() const
123 {
124  return Vector3D(x.size(), y.size(), z.size()).length();
125 }
126 
127 //------------------------------------------------------------------------------
128 } // namespace RealSpace
Definitions.
float dot(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:59
Vector3D cross(const Vector3D &v1, const Vector3D &v2)
Definition: def.cpp:54
Vector3D operator-(const Vector3D &v)
Definition: def.cpp:69
Vector3D operator+(const Vector3D &v)
Definition: def.cpp:64
Vector3D operator*(const Vector3D &v, float f)
Definition: def.cpp:74
float mid() const
Definition: def.cpp:98
float size() const
Definition: def.cpp:93
float min
Definition: def.h:67
float max
Definition: def.h:67
Range(float, float)
Definition: def.cpp:91
Vector3D interpolateTo(const Vector3D &, float) const
Definition: def.cpp:41
static Vector3D const _1
Definition: def.h:49
static Vector3D const _z
Definition: def.h:49
Vector3D normalized() const
Definition: def.cpp:36
static Vector3D const _0
Definition: def.h:49
static Vector3D const _y
Definition: def.h:49
float length() const
Definition: def.cpp:31
static Vector3D const _x
Definition: def.h:49
VectorRange(Range, Range, Range)
Definition: def.cpp:105
Vector3D mid() const
Definition: def.cpp:117
float length() const
Definition: def.cpp:122
Vector3D size() const
Definition: def.cpp:112