1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.vector4d;
15 extern(C++):
16 
17 import qt.config;
18 import qt.helpers;
19 version(QT_NO_VECTOR2D){}else
20 version(QT_NO_VECTOR4D){}else
21     import qt.gui.vector2d;
22 version(QT_NO_VECTOR3D){}else
23 version(QT_NO_VECTOR4D){}else
24     import qt.gui.vector3d;
25 version(QT_NO_VECTOR4D){}else
26 {
27     import qt.core.metatype;
28     import qt.core.namespace;
29     import qt.core.point;
30     import qt.core.variant;
31 }
32 
33 version(QT_NO_VECTOR4D)
34 {
35 extern(C++, class) struct QVector4D;
36 }
37 /+ class QMatrix4x4;
38 class QVector2D;
39 class QVector3D; +/
40 
41 version(QT_NO_VECTOR4D){}else
42 {
43 
44 @(QMetaType.Type.QVector4D) extern(C++, class) struct /+ Q_GUI_EXPORT +/ QVector4D
45 {
46 public:
47     @disable this();
48     /+pragma(inline, true) this()
49     {
50         this.v = [0.0f, 0.0f, 0.0f, 0.0f];
51     }+/
52     /+ explicit +/this(/+ Qt:: +/qt.core.namespace.Initialization) {}
53     pragma(inline, true) this(float xpos, float ypos, float zpos, float wpos)
54     {
55         this.v = [xpos, ypos, zpos, wpos];
56     }
57     /+ explicit +/pragma(inline, true) this(ref const(QPoint) point)
58     {
59         this.v = [float(point.x()), float(point.y()), 0.0f, 0.0f];
60     }
61     /+ explicit +/pragma(inline, true) this(ref const(QPointF) point)
62     {
63         this.v = [float(point.x()), float(point.y()), 0.0f, 0.0f];
64     }
65 /+ #ifndef QT_NO_VECTOR2D +/
66     version(QT_NO_VECTOR2D){}else
67     {
68         this(ref const(QVector2D) vector);
69         this(ref const(QVector2D) vector, float zpos, float wpos);
70     }
71 /+ #endif
72 #ifndef QT_NO_VECTOR3D +/
73     version(QT_NO_VECTOR3D){}else
74     {
75         this(ref const(QVector3D) vector);
76         this(ref const(QVector3D) vector, float wpos);
77     }
78 /+ #endif +/
79 
80     pragma(inline, true) bool isNull() const
81     {
82         import qt.core.global;
83 
84         return qIsNull(v[0]) && qIsNull(v[1]) && qIsNull(v[2]) && qIsNull(v[3]);
85     }
86 
87     pragma(inline, true) float x() const { return v[0]; }
88     pragma(inline, true) float y() const { return v[1]; }
89     pragma(inline, true) float z() const { return v[2]; }
90     pragma(inline, true) float w() const { return v[3]; }
91 
92     pragma(inline, true) void setX(float aX) { v[0] = aX; }
93     pragma(inline, true) void setY(float aY) { v[1] = aY; }
94     pragma(inline, true) void setZ(float aZ) { v[2] = aZ; }
95     pragma(inline, true) void setW(float aW) { v[3] = aW; }
96 
97     /+pragma(inline, true) ref float operator [](int i)
98     {
99         import qt.core.global;
100 
101         (mixin(Q_ASSERT(q{uint(i) < 4u})));
102         return v[i];
103     }+/
104     /+pragma(inline, true) float operator [](int i) const
105     {
106         import qt.core.global;
107 
108         (mixin(Q_ASSERT(q{uint(i) < 4u})));
109         return v[i];
110     }+/
111 
112     float length() const;
113     float lengthSquared() const; //In Qt 6 convert to inline and constexpr
114 
115     /+ Q_REQUIRED_RESULT +/ QVector4D normalized() const;
116     void normalize();
117 
118     /+pragma(inline, true) ref QVector4D operator +=(ref const(QVector4D) vector)
119     {
120         v[0] += vector.v[0];
121         v[1] += vector.v[1];
122         v[2] += vector.v[2];
123         v[3] += vector.v[3];
124         return this;
125     }+/
126     /+pragma(inline, true) ref QVector4D operator -=(ref const(QVector4D) vector)
127     {
128         v[0] -= vector.v[0];
129         v[1] -= vector.v[1];
130         v[2] -= vector.v[2];
131         v[3] -= vector.v[3];
132         return this;
133     }+/
134     /+pragma(inline, true) ref QVector4D operator *=(float factor)
135     {
136         v[0] *= factor;
137         v[1] *= factor;
138         v[2] *= factor;
139         v[3] *= factor;
140         return this;
141     }+/
142     /+pragma(inline, true) ref QVector4D operator *=(ref const(QVector4D) vector)
143     {
144         v[0] *= vector.v[0];
145         v[1] *= vector.v[1];
146         v[2] *= vector.v[2];
147         v[3] *= vector.v[3];
148         return this;
149     }+/
150     /+pragma(inline, true) ref QVector4D operator /=(float divisor)
151     {
152         v[0] /= divisor;
153         v[1] /= divisor;
154         v[2] /= divisor;
155         v[3] /= divisor;
156         return this;
157     }+/
158     /+pragma(inline, true) ref QVector4D operator /=(ref const(QVector4D) vector)
159     {
160         v[0] /= vector.v[0];
161         v[1] /= vector.v[1];
162         v[2] /= vector.v[2];
163         v[3] /= vector.v[3];
164         return this;
165     }+/
166 
167     static float dotProduct(ref const(QVector4D) v1, ref const(QVector4D) v2); //In Qt 6 convert to inline and constexpr
168 
169     /+ friend inline bool operator==(const QVector4D &v1, const QVector4D &v2); +/
170     /+ friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2); +/
171     /+ friend inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2); +/
172     /+ friend inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2); +/
173     /+ friend inline const QVector4D operator*(float factor, const QVector4D &vector); +/
174     /+ friend inline const QVector4D operator*(const QVector4D &vector, float factor); +/
175     /+ friend inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2); +/
176     /+ friend inline const QVector4D operator-(const QVector4D &vector); +/
177     /+ friend inline const QVector4D operator/(const QVector4D &vector, float divisor); +/
178     /+ friend inline const QVector4D operator/(const QVector4D &vector, const QVector4D &divisor); +/
179 
180     /+ friend inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2); +/
181 
182 /+ #ifndef QT_NO_VECTOR2D +/
183     version(QT_NO_VECTOR2D){}else
184     {
185         QVector2D toVector2D() const;
186         QVector2D toVector2DAffine() const;
187     }
188 /+ #endif
189 #ifndef QT_NO_VECTOR3D +/
190     version(QT_NO_VECTOR3D){}else
191     {
192         QVector3D toVector3D() const;
193         QVector3D toVector3DAffine() const;
194     }
195 /+ #endif +/
196 
197     pragma(inline, true) QPoint toPoint() const
198     {
199         import qt.core.global;
200 
201         return QPoint(qRound(v[0]), qRound(v[1]));
202     }
203     pragma(inline, true) QPointF toPointF() const
204     {
205         import qt.core.global;
206 
207         return QPointF(qreal(v[0]), qreal(v[1]));
208     }
209 
210     /+auto opCast(T : QVariant)() const;+/
211 
212 private:
213     float[4] v;
214 
215     /+ friend class QVector2D; +/
216     /+ friend class QVector3D; +/
217     static if(!defined!"QT_NO_MATRIX4X4")
218     {
219         /+ friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix); +/
220         /+ friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector); +/
221     }
222 }
223 
224 /+ Q_DECLARE_TYPEINFO(QVector4D, Q_PRIMITIVE_TYPE);
225 
226 QT_WARNING_PUSH
227 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
228 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
229 QT_WARNING_DISABLE_INTEL(1572) +/
230 /+pragma(inline, true) bool operator ==(ref const(QVector4D) v1, ref const(QVector4D) v2)
231 {
232     return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1] && v1.v[2] == v2.v[2] && v1.v[3] == v2.v[3];
233 }+/
234 
235 /+pragma(inline, true) bool operator !=(ref const(QVector4D) v1, ref const(QVector4D) v2)
236 {
237     return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1] || v1.v[2] != v2.v[2] || v1.v[3] != v2.v[3];
238 }+/
239 /+ QT_WARNING_POP +/
240 
241 /+pragma(inline, true) const(QVector4D) operator +(ref const(QVector4D) v1, ref const(QVector4D) v2)
242 {
243     return QVector4D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1], v1.v[2] + v2.v[2], v1.v[3] + v2.v[3]);
244 }+/
245 
246 /+pragma(inline, true) const(QVector4D) operator -(ref const(QVector4D) v1, ref const(QVector4D) v2)
247 {
248     return QVector4D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1], v1.v[2] - v2.v[2], v1.v[3] - v2.v[3]);
249 }+/
250 
251 /+pragma(inline, true) const(QVector4D) operator *(float factor, ref const(QVector4D) vector)
252 {
253     return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
254 }+/
255 
256 /+pragma(inline, true) const(QVector4D) operator *(ref const(QVector4D) vector, float factor)
257 {
258     return QVector4D(vector.v[0] * factor, vector.v[1] * factor, vector.v[2] * factor, vector.v[3] * factor);
259 }+/
260 
261 /+pragma(inline, true) const(QVector4D) operator *(ref const(QVector4D) v1, ref const(QVector4D) v2)
262 {
263     return QVector4D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1], v1.v[2] * v2.v[2], v1.v[3] * v2.v[3]);
264 }+/
265 
266 /+pragma(inline, true) const(QVector4D) operator -(ref const(QVector4D) vector)
267 {
268     return QVector4D(-vector.v[0], -vector.v[1], -vector.v[2], -vector.v[3]);
269 }+/
270 
271 /+pragma(inline, true) const(QVector4D) operator /(ref const(QVector4D) vector, float divisor)
272 {
273     return QVector4D(vector.v[0] / divisor, vector.v[1] / divisor, vector.v[2] / divisor, vector.v[3] / divisor);
274 }+/
275 
276 /+pragma(inline, true) const(QVector4D) operator /(ref const(QVector4D) vector, ref const(QVector4D) divisor)
277 {
278     return QVector4D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1], vector.v[2] / divisor.v[2], vector.v[3] / divisor.v[3]);
279 }+/
280 
281 pragma(inline, true) bool qFuzzyCompare(ref const(QVector4D) v1, ref const(QVector4D) v2)
282 {
283     import qt.core.global;
284 
285     return qt.core.global.qFuzzyCompare(v1.v[0], v2.v[0]) &&
286            qt.core.global.qFuzzyCompare(v1.v[1], v2.v[1]) &&
287            qt.core.global.qFuzzyCompare(v1.v[2], v2.v[2]) &&
288            qt.core.global.qFuzzyCompare(v1.v[3], v2.v[3]);
289 }
290 
291 /+ #ifndef QT_NO_DEBUG_STREAM
292 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector4D &vector);
293 #endif
294 
295 #ifndef QT_NO_DATASTREAM
296 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector4D &);
297 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector4D &);
298 #endif +/
299 
300 }
301