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.vector2d;
15 extern(C++):
16 
17 import qt.config;
18 import qt.helpers;
19 version(QT_NO_VECTOR2D){}else
20 version(QT_NO_VECTOR3D){}else
21     import qt.gui.vector3d;
22 version(QT_NO_VECTOR2D){}else
23 version(QT_NO_VECTOR4D){}else
24     import qt.gui.vector4d;
25 version(QT_NO_VECTOR2D){}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_VECTOR2D)
34 {
35 extern(C++, class) struct QVector2D;
36 }
37 /+ class QVector3D;
38 class QVector4D;
39 class QVariant; +/
40 
41 version(QT_NO_VECTOR2D){}else
42 {
43 
44 @(QMetaType.Type.QVector2D) extern(C++, class) struct /+ Q_GUI_EXPORT +/ QVector2D
45 {
46 public:
47     @disable this();
48     /+pragma(inline, true) this()
49     {
50         this.v = [0.0f, 0.0f];
51     }+/
52     /+ explicit +/this(/+ Qt:: +/qt.core.namespace.Initialization) {}
53     pragma(inline, true) this(float xpos, float ypos)
54     {
55         this.v = [xpos, ypos];
56     }
57     /+ explicit +/pragma(inline, true) this(ref const(QPoint) point)
58     {
59         this.v = [float(point.x()), float(point.y())];
60     }
61     /+ explicit +/pragma(inline, true) this(ref const(QPointF) point)
62     {
63         this.v = [float(point.x()), float(point.y())];
64     }
65 /+ #ifndef QT_NO_VECTOR3D +/
66     version(QT_NO_VECTOR3D){}else
67     {
68         /+ explicit +/this(ref const(QVector3D) vector);
69     }
70 /+ #endif
71 #ifndef QT_NO_VECTOR4D +/
72     version(QT_NO_VECTOR4D){}else
73     {
74         /+ explicit +/this(ref const(QVector4D) vector);
75     }
76 /+ #endif +/
77 
78     pragma(inline, true) bool isNull() const
79     {
80         import qt.core.global;
81 
82         return qIsNull(v[0]) && qIsNull(v[1]);
83     }
84 
85     pragma(inline, true) float x() const { return v[0]; }
86     pragma(inline, true) float y() const { return v[1]; }
87 
88     pragma(inline, true) void setX(float aX) { v[0] = aX; }
89     pragma(inline, true) void setY(float aY) { v[1] = aY; }
90 
91     /+pragma(inline, true) ref float operator [](int i)
92     {
93         import qt.core.global;
94 
95         (mixin(Q_ASSERT(q{uint(i) < 2u})));
96         return v[i];
97     }+/
98     /+pragma(inline, true) float operator [](int i) const
99     {
100         import qt.core.global;
101 
102         (mixin(Q_ASSERT(q{uint(i) < 2u})));
103         return v[i];
104     }+/
105 
106     float length() const;
107     float lengthSquared() const; //In Qt 6 convert to inline and constexpr
108 
109     /+ Q_REQUIRED_RESULT +/ QVector2D normalized() const;
110     void normalize();
111 
112     float distanceToPoint(ref const(QVector2D) point) const;
113     float distanceToLine(ref const(QVector2D) point, ref const(QVector2D) direction) const;
114 
115     /+pragma(inline, true) ref QVector2D operator +=(ref const(QVector2D) vector)
116     {
117         v[0] += vector.v[0];
118         v[1] += vector.v[1];
119         return this;
120     }+/
121     /+pragma(inline, true) ref QVector2D operator -=(ref const(QVector2D) vector)
122     {
123         v[0] -= vector.v[0];
124         v[1] -= vector.v[1];
125         return this;
126     }+/
127     /+pragma(inline, true) ref QVector2D operator *=(float factor)
128     {
129         v[0] *= factor;
130         v[1] *= factor;
131         return this;
132     }+/
133     /+pragma(inline, true) ref QVector2D operator *=(ref const(QVector2D) vector)
134     {
135         v[0] *= vector.v[0];
136         v[1] *= vector.v[1];
137         return this;
138     }+/
139     /+pragma(inline, true) ref QVector2D operator /=(float divisor)
140     {
141         v[0] /= divisor;
142         v[1] /= divisor;
143         return this;
144     }+/
145     /+pragma(inline, true) ref QVector2D operator /=(ref const(QVector2D) vector)
146     {
147         v[0] /= vector.v[0];
148         v[1] /= vector.v[1];
149         return this;
150     }+/
151 
152     static float dotProduct(ref const(QVector2D) v1, ref const(QVector2D) v2); //In Qt 6 convert to inline and constexpr
153 
154     /+ friend inline bool operator==(const QVector2D &v1, const QVector2D &v2); +/
155     /+ friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2); +/
156     /+ friend inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2); +/
157     /+ friend inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2); +/
158     /+ friend inline const QVector2D operator*(float factor, const QVector2D &vector); +/
159     /+ friend inline const QVector2D operator*(const QVector2D &vector, float factor); +/
160     /+ friend inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2); +/
161     /+ friend inline const QVector2D operator-(const QVector2D &vector); +/
162     /+ friend inline const QVector2D operator/(const QVector2D &vector, float divisor); +/
163     /+ friend inline const QVector2D operator/(const QVector2D &vector, const QVector2D &divisor); +/
164 
165     /+ friend inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2); +/
166 
167 /+ #ifndef QT_NO_VECTOR3D +/
168     version(QT_NO_VECTOR3D){}else
169     {
170         QVector3D toVector3D() const;
171     }
172 /+ #endif
173 #ifndef QT_NO_VECTOR4D +/
174     version(QT_NO_VECTOR4D){}else
175     {
176         QVector4D toVector4D() const;
177     }
178 /+ #endif +/
179 
180     pragma(inline, true) QPoint toPoint() const
181     {
182         import qt.core.global;
183 
184         return QPoint(qRound(v[0]), qRound(v[1]));
185     }
186     pragma(inline, true) QPointF toPointF() const
187     {
188         import qt.core.global;
189 
190         return QPointF(qreal(v[0]), qreal(v[1]));
191     }
192 
193     /+auto opCast(T : QVariant)() const;+/
194 
195 private:
196     float[2] v;
197 
198     /+ friend class QVector3D; +/
199     /+ friend class QVector4D; +/
200 }
201 
202 /+ Q_DECLARE_TYPEINFO(QVector2D, Q_PRIMITIVE_TYPE);
203 
204 QT_WARNING_PUSH
205 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
206 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
207 QT_WARNING_DISABLE_INTEL(1572) +/
208 /+pragma(inline, true) bool operator ==(ref const(QVector2D) v1, ref const(QVector2D) v2)
209 {
210     return v1.v[0] == v2.v[0] && v1.v[1] == v2.v[1];
211 }+/
212 
213 /+pragma(inline, true) bool operator !=(ref const(QVector2D) v1, ref const(QVector2D) v2)
214 {
215     return v1.v[0] != v2.v[0] || v1.v[1] != v2.v[1];
216 }+/
217 /+ QT_WARNING_POP +/
218 
219 /+pragma(inline, true) const(QVector2D) operator +(ref const(QVector2D) v1, ref const(QVector2D) v2)
220 {
221     return QVector2D(v1.v[0] + v2.v[0], v1.v[1] + v2.v[1]);
222 }+/
223 
224 /+pragma(inline, true) const(QVector2D) operator -(ref const(QVector2D) v1, ref const(QVector2D) v2)
225 {
226     return QVector2D(v1.v[0] - v2.v[0], v1.v[1] - v2.v[1]);
227 }+/
228 
229 /+pragma(inline, true) const(QVector2D) operator *(float factor, ref const(QVector2D) vector)
230 {
231     return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
232 }+/
233 
234 /+pragma(inline, true) const(QVector2D) operator *(ref const(QVector2D) vector, float factor)
235 {
236     return QVector2D(vector.v[0] * factor, vector.v[1] * factor);
237 }+/
238 
239 /+pragma(inline, true) const(QVector2D) operator *(ref const(QVector2D) v1, ref const(QVector2D) v2)
240 {
241     return QVector2D(v1.v[0] * v2.v[0], v1.v[1] * v2.v[1]);
242 }+/
243 
244 /+pragma(inline, true) const(QVector2D) operator -(ref const(QVector2D) vector)
245 {
246     return QVector2D(-vector.v[0], -vector.v[1]);
247 }+/
248 
249 /+pragma(inline, true) const(QVector2D) operator /(ref const(QVector2D) vector, float divisor)
250 {
251     return QVector2D(vector.v[0] / divisor, vector.v[1] / divisor);
252 }+/
253 
254 /+pragma(inline, true) const(QVector2D) operator /(ref const(QVector2D) vector, ref const(QVector2D) divisor)
255 {
256     return QVector2D(vector.v[0] / divisor.v[0], vector.v[1] / divisor.v[1]);
257 }+/
258 
259 pragma(inline, true) bool qFuzzyCompare(ref const(QVector2D) v1, ref const(QVector2D) v2)
260 {
261     import qt.core.global;
262 
263     return qt.core.global.qFuzzyCompare(v1.v[0], v2.v[0]) && qt.core.global.qFuzzyCompare(v1.v[1], v2.v[1]);
264 }
265 
266 /+ #ifndef QT_NO_DEBUG_STREAM
267 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector2D &vector);
268 #endif
269 
270 #ifndef QT_NO_DATASTREAM
271 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QVector2D &);
272 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QVector2D &);
273 #endif +/
274 
275 }
276