1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.core.line;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.global;
17 import qt.core.point;
18 import qt.core.typeinfo;
19 import qt.helpers;
20 
21 /*******************************************************************************
22  * class QLine
23  *******************************************************************************/
24 
25 /// Binding for C++ class [QLine](https://doc.qt.io/qt-6/qline.html).
26 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QLine
27 {
28 public:
29     /+pragma(inline, true) this() { }+/
30     pragma(inline, true) this(const(QPoint) pt1_, const(QPoint) pt2_)
31     {
32         this.pt1 = pt1_;
33         this.pt2 = pt2_;
34     }
35     pragma(inline, true) this(int x1pos, int y1pos, int x2pos, int y2pos)
36     {
37         this.pt1 = QPoint(x1pos, y1pos);
38         this.pt2 = QPoint(x2pos, y2pos);
39     }
40 
41     pragma(inline, true) bool isNull() const
42     {
43         return pt1 == pt2;
44     }
45 
46     pragma(inline, true) QPoint p1() const
47     {
48         return pt1;
49     }
50     pragma(inline, true) QPoint p2() const
51     {
52         return pt2;
53     }
54 
55     pragma(inline, true) int x1() const
56     {
57         return pt1.x();
58     }
59     pragma(inline, true) int y1() const
60     {
61         return pt1.y();
62     }
63 
64     pragma(inline, true) int x2() const
65     {
66         return pt2.x();
67     }
68     pragma(inline, true) int y2() const
69     {
70         return pt2.y();
71     }
72 
73     pragma(inline, true) int dx() const
74     {
75         return pt2.x() - pt1.x();
76     }
77     pragma(inline, true) int dy() const
78     {
79         return pt2.y() - pt1.y();
80     }
81 
82     pragma(inline, true) void translate(ref const(QPoint) point)
83     {
84         pt1 += point;
85         pt2 += point;
86     }
87     pragma(inline, true) void translate(int adx, int ady)
88     {
89         auto tmp=QPoint(adx, ady); this.translate(tmp);
90     }
91 
92     /+ [[nodiscard]] +/ pragma(inline, true) QLine translated(ref const(QPoint) p) const
93     {
94         return QLine(pt1 + p, pt2 + p);
95     }
96     /+ [[nodiscard]] +/ pragma(inline, true) QLine translated(int adx, int ady) const
97     {
98         auto tmp = QPoint(adx, ady); return translated(tmp);
99     }
100 
101     /+ [[nodiscard]] +/ pragma(inline, true) QPoint center() const
102     {
103         return QPoint(cast(int)((qint64(pt1.x()) + pt2.x()) / 2), cast(int)((qint64(pt1.y()) + pt2.y()) / 2));
104     }
105 
106     pragma(inline, true) void setP1(ref const(QPoint) aP1)
107     {
108         pt1 = aP1;
109     }
110     pragma(inline, true) void setP2(ref const(QPoint) aP2)
111     {
112         pt2 = aP2;
113     }
114     pragma(inline, true) void setPoints(ref const(QPoint) aP1, ref const(QPoint) aP2)
115     {
116         pt1 = aP1;
117         pt2 = aP2;
118     }
119     pragma(inline, true) void setLine(int aX1, int aY1, int aX2, int aY2)
120     {
121         pt1 = QPoint(aX1, aY1);
122         pt2 = QPoint(aX2, aY2);
123     }
124 
125     /+pragma(inline, true) bool operator ==(ref const(QLine) d) const/+ noexcept+/
126     {
127         return pt1 == d.pt1 && pt2 == d.pt2;
128     }+/
129     /+pragma(inline, true) bool operator !=(ref const(QLine) d) const/+ noexcept+/ { return !(this == d); }+/
130 
131 private:
132     QPoint pt1; QPoint pt2;
133     mixin(CREATE_CONVENIENCE_WRAPPERS);
134 }
135 /+ Q_DECLARE_TYPEINFO(QLine, Q_RELOCATABLE_TYPE);
136 
137 /*******************************************************************************
138  * class QLine inline members
139  *******************************************************************************/
140 
141 #ifndef QT_NO_DEBUG_STREAM
142 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p);
143 #endif
144 
145 #ifndef QT_NO_DATASTREAM
146 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLine &);
147 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLine &);
148 #endif +/
149 
150 /*******************************************************************************
151  * class QLineF
152  *******************************************************************************/
153 /// Binding for C++ class [QLineF](https://doc.qt.io/qt-6/qlinef.html).
154 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QLineF
155 {
156 public:
157 
158     enum IntersectionType { NoIntersection, BoundedIntersection, UnboundedIntersection }
159     alias IntersectType = IntersectionType; // deprecated name
160 
161     /+pragma(inline, true) this()
162     {
163     }+/
164     pragma(inline, true) this(const(QPointF) apt1, const(QPointF) apt2)
165     {
166         this.pt1 = apt1;
167         this.pt2 = apt2;
168     }
169     pragma(inline, true) this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos)
170     {
171         this.pt1 = typeof(this.pt1)(x1pos, y1pos);
172         this.pt2 = typeof(this.pt2)(x2pos, y2pos);
173     }
174     /+pragma(inline, true) this(ref const(QLine) line)
175     {
176         this.pt1 = line.p1();
177         this.pt2 = line.p2();
178     }+/
179 
180     /+ [[nodiscard]] +/ static QLineF fromPolar(qreal length, qreal angle);
181 
182     pragma(inline, true) bool isNull() const
183     {
184         return qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y());
185     }
186 
187     pragma(inline, true) QPointF p1() const
188     {
189         return pt1;
190     }
191     pragma(inline, true) QPointF p2() const
192     {
193         return pt2;
194     }
195 
196     pragma(inline, true) qreal x1() const
197     {
198         return pt1.x();
199     }
200     pragma(inline, true) qreal y1() const
201     {
202         return pt1.y();
203     }
204 
205     pragma(inline, true) qreal x2() const
206     {
207         return pt2.x();
208     }
209     pragma(inline, true) qreal y2() const
210     {
211         return pt2.y();
212     }
213 
214     pragma(inline, true) qreal dx() const
215     {
216         return pt2.x() - pt1.x();
217     }
218     pragma(inline, true) qreal dy() const
219     {
220         return pt2.y() - pt1.y();
221     }
222 
223     qreal length() const;
224 /+    void setLength(qreal len)
225     {
226         (mixin(Q_ASSERT(q{qIsFinite(len)})));
227         const(qreal) oldLength = length();
228         (mixin(Q_ASSERT(q{qIsFinite(oldLength)})));
229         // Scale len by dx() / length() and dy() / length(), two O(1) quantities,
230         // rather than scaling dx() and dy() by len / length(), which might overflow.
231         if (oldLength > 0)
232             pt2 = QPointF(pt1.x() + len * (dx() / oldLength), pt1.y() + len * (dy() / oldLength));
233     }+/
234 
235     qreal angle() const;
236     void setAngle(qreal angle);
237 
238     qreal angleTo(ref const(QLineF) l) const;
239 
240     /+ [[nodiscard]] +/ QLineF unitVector() const;
241     /+ [[nodiscard]] +/ pragma(inline, true) QLineF normalVector() const
242     {
243         auto tmp = p1(); return QLineF(tmp, p1() + QPointF(dy(), -dx()));
244     }
245 
246     IntersectionType intersects(ref const(QLineF) l, QPointF* intersectionPoint = null) const;
247 
248     pragma(inline, true) QPointF pointAt(qreal t) const
249     {
250         return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t);
251     }
252     pragma(inline, true) void translate(ref const(QPointF) point)
253     {
254         pt1 += point;
255         pt2 += point;
256     }
257     pragma(inline, true) void translate(qreal adx, qreal ady)
258     {
259         auto tmp = QPointF(adx, ady); this.translate(tmp);
260     }
261 
262     /+ [[nodiscard]] +/ pragma(inline, true) QLineF translated(ref const(QPointF) p) const
263     {
264         return QLineF(pt1 + p, pt2 + p);
265     }
266     /+ [[nodiscard]] +/ pragma(inline, true) QLineF translated(qreal adx, qreal ady) const
267     {
268         auto tmp = QPointF(adx, ady); return translated(tmp);
269     }
270 
271     /+ [[nodiscard]] +/ pragma(inline, true) QPointF center() const
272     {
273         return QPointF(0.5 * pt1.x() + 0.5 * pt2.x(), 0.5 * pt1.y() + 0.5 * pt2.y());
274     }
275 
276     pragma(inline, true) void setP1(ref const(QPointF) aP1)
277     {
278         pt1 = aP1;
279     }
280     pragma(inline, true) void setP2(ref const(QPointF) aP2)
281     {
282         pt2 = aP2;
283     }
284     pragma(inline, true) void setPoints(ref const(QPointF) aP1, ref const(QPointF) aP2)
285     {
286         pt1 = aP1;
287         pt2 = aP2;
288     }
289     pragma(inline, true) void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2)
290     {
291         pt1 = QPointF(aX1, aY1);
292         pt2 = QPointF(aX2, aY2);
293     }
294 
295     /+pragma(inline, true) bool operator ==(ref const(QLineF) d) const
296     {
297         return pt1 == d.pt1 && pt2 == d.pt2;
298     }+/
299     /+pragma(inline, true) bool operator !=(ref const(QLineF) d) const { return !(this == d); }+/
300 
301     pragma(inline, true) QLine toLine() const
302     {
303         auto tmp = pt1.toPoint(); auto tmp__1 = pt2.toPoint(); return QLine(tmp, tmp__1);
304     }
305 
306 private:
307     QPointF pt1; QPointF pt2;
308     mixin(CREATE_CONVENIENCE_WRAPPERS);
309 }
310 /+ Q_DECLARE_TYPEINFO(QLineF, Q_RELOCATABLE_TYPE);
311 
312 /*******************************************************************************
313  * class QLineF inline members
314  *******************************************************************************/
315 
316 
317 
318 
319 
320 #ifndef QT_NO_DEBUG_STREAM
321 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLineF &p);
322 #endif
323 
324 #ifndef QT_NO_DATASTREAM
325 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLineF &);
326 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLineF &);
327 #endif +/
328