comparison d2/qt/core/QLine.d @ 311:8674fd5f34f4 lifetime

Added d1/d2 top directories
author maxter <spambox@d-coding.com>
date Wed, 23 Dec 2009 16:17:22 +0200
parents
children
comparison
equal deleted inserted replaced
310:5bcfe9e7db7f 311:8674fd5f34f4
1 module qt.core.QLine;
2
3 public import qt.QGlobal;
4 public import qt.core.Qt;
5 public import qt.core.QPoint;
6 public import qt.core.QDataStream;
7
8
9 public struct QLine
10 {
11 public static QLine opCall() {
12 QLine ln;
13 ln.pt1 = QPoint();
14 ln.pt2 = QPoint();
15 return ln;
16 }
17
18 public this(QPoint pt1_, QPoint pt2_) {
19 pt1 = pt1_;
20 pt2 = pt2_;
21 }
22
23 public this(int x1pos, int y1pos, int x2pos, int y2pos) {
24 pt1 = QPoint(x1pos, y1pos);
25 pt2 = QPoint(x2pos, y2pos);
26 }
27
28 bool isNull() // const
29 {
30 return pt1 == pt2;
31 }
32
33 int x1() // const
34 {
35 return pt1.x();
36 }
37
38 int y1() // const
39 {
40 return pt1.y();
41 }
42
43 int x2() // const
44 {
45 return pt2.x();
46 }
47
48 int y2() // const
49 {
50 return pt2.y();
51 }
52
53 QPoint p1() // const
54 {
55 return pt1;
56 }
57
58 QPoint p2() // const
59 {
60 return pt2;
61 }
62
63 int dx() // const
64 {
65 return pt2.x() - pt1.x();
66 }
67
68 int dy() // const
69 {
70 return pt2.y() - pt1.y();
71 }
72
73 void translate(ref QPoint point)
74 {
75 pt1 += point;
76 pt2 += point;
77 }
78
79 void translate(int adx, int ady)
80 {
81 translate(QPoint(adx, ady));
82 }
83
84 QLine translated(ref QPoint p) // const
85 {
86 return QLine(pt1 + p, pt2 + p);
87 }
88
89 QLine translated(int adx, int ady) // const
90 {
91 return translated(QPoint(adx, ady));
92 }
93
94 void p1(ref QPoint aP1)
95 {
96 pt1 = aP1;
97 }
98
99 void p2(ref QPoint aP2)
100 {
101 pt2 = aP2;
102 }
103
104 void setP1(ref QPoint aP1) // for convenience
105 {
106 pt1 = aP1;
107 }
108
109 void setP2(ref QPoint aP2) // for convenience
110 {
111 pt2 = aP2;
112 }
113
114 void setPoints(ref QPoint aP1, ref QPoint aP2)
115 {
116 pt1 = aP1;
117 pt2 = aP2;
118 }
119
120 void setLine(int aX1, int aY1, int aX2, int aY2)
121 {
122 pt1 = QPoint(aX1, aY1);
123 pt2 = QPoint(aX2, aY2);
124 }
125
126 bool opEquals(ref QLine d) // const
127 {
128 return pt1 == d.pt1 && pt2 == d.pt2;
129 }
130
131 public final void writeTo(QDataStream arg__1) {
132 qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
133 }
134
135 public final void readFrom(QDataStream arg__1) {
136 qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
137 }
138
139 private:
140 QPoint pt1, pt2;
141 }
142
143
144 public enum QLineF_IntersectType {
145 NoIntersection = 0,
146 BoundedIntersection = 1,
147 UnboundedIntersection = 2
148 }
149
150 public struct QLineF
151 {
152
153 alias QLineF_IntersectType IntersectType;
154
155 alias QLineF_IntersectType.NoIntersection NoIntersection;
156 alias QLineF_IntersectType.BoundedIntersection BoundedIntersection;
157 alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection;
158
159 public static QLineF opCall() {
160 QLineF ln;
161 ln.pt1 = QPointF();
162 ln.pt2 = QPointF();
163 return ln;
164 }
165
166 public this(QPointF apt1, QPointF apt2) {
167 pt1 = apt1;
168 pt2 = apt2;
169 }
170
171 public this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) {
172 pt1 = QPointF(x1pos, y1pos);
173 pt2 = QPointF(x2pos, y2pos);
174 }
175
176 public this(QLine line){
177 pt1 = QPointF(line.p1());
178 pt2 = QPointF(line.p2());
179 }
180
181 public final bool isNull() // const
182 {
183 return qtd_QLineF_isNull(&this);
184 }
185
186 qreal x1() // const
187 {
188 return pt1.x();
189 }
190
191 qreal y1() // const
192 {
193 return pt1.y();
194 }
195
196 qreal x2() // const
197 {
198 return pt2.x();
199 }
200
201 qreal y2() // const
202 {
203 return pt2.y();
204 }
205
206 QPointF p1() // const
207 {
208 return pt1;
209 }
210
211 QPointF p2() // const
212 {
213 return pt2;
214 }
215
216 qreal dx() // const
217 {
218 return pt2.x() - pt1.x();
219 }
220
221 qreal dy() // const
222 {
223 return pt2.y() - pt1.y();
224 }
225
226 QLineF normalVector() // const
227 {
228 return QLineF(p1(), p1() + QPointF(dy(), -dx()));
229 }
230
231 void translate(ref QPointF point)
232 {
233 pt1 += point;
234 pt2 += point;
235 }
236
237 void translate(qreal adx, qreal ady)
238 {
239 this.translate(QPointF(adx, ady));
240 }
241
242 QLineF translated(ref QPointF p) // const
243 {
244 return QLineF(pt1 + p, pt2 + p);
245 }
246
247 QLineF translated(qreal adx, qreal ady) // const
248 {
249 return translated(QPointF(adx, ady));
250 }
251
252 void setLength(qreal len)
253 {
254 if (isNull())
255 return;
256 QLineF v = unitVector();
257 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
258 }
259
260 void length(qreal len)
261 {
262 if (isNull())
263 return;
264 QLineF v = unitVector();
265 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len);
266 }
267
268 QPointF pointAt(qreal t) // const
269 {
270 qreal vx = pt2.x() - pt1.x();
271 qreal vy = pt2.y() - pt1.y();
272 return QPointF(pt1.x() + vx * t, pt1.y() + vy * t);
273 }
274
275 QLine toLine() // const
276 {
277 return QLine(pt1.toPoint(), pt2.toPoint());
278 }
279
280 void setP1(ref QPointF aP1)
281 {
282 pt1 = aP1;
283 }
284
285 void setP2(ref QPointF aP2)
286 {
287 pt2 = aP2;
288 }
289
290 void p1(ref QPointF aP1)
291 {
292 pt1 = aP1;
293 }
294
295 void p2(ref QPointF aP2)
296 {
297 pt2 = aP2;
298 }
299
300 void setPoints(ref QPointF aP1, ref QPointF aP2)
301 {
302 pt1 = aP1;
303 pt2 = aP2;
304 }
305
306 void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2)
307 {
308 pt1 = QPointF(aX1, aY1);
309 pt2 = QPointF(aX2, aY2);
310 }
311
312 bool opEquals(ref QLineF d) // const
313 {
314 return pt1 == d.pt1 && pt2 == d.pt2;
315 }
316
317 public final double angle() {
318 return qtd_QLineF_angle(&this);
319 }
320
321 public final double angle(ref QLineF l) {
322 return qtd_QLineF_angle_QLineF(&this, &l);
323 }
324
325 public final double angleTo(ref QLineF l) {
326 return qtd_QLineF_angleTo_QLineF(&this, &l);
327 }
328
329 // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType
330 private final QLineF_IntersectType intersect(ref QLineF l, QPointF* intersectionPoint) {
331 return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(&this, &l, intersectionPoint);
332 }
333
334 public final double length() {
335 return qtd_QLineF_length(&this);
336 }
337
338 public final void writeTo(QDataStream arg__1) {
339 qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
340 }
341
342 public final void readFrom(QDataStream arg__1) {
343 qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId);
344 }
345
346 public final void setAngle(double angle) {
347 qtd_QLineF_setAngle_double(&this, angle);
348 }
349
350 public final QLineF unitVector() {
351 return qtd_QLineF_unitVector(&this);
352 }
353
354 public static QLineF fromPolar(double length, double angle) {
355 return qtd_QLineF_fromPolar_double_double(length, angle);
356 }
357
358 private:
359 QPointF pt1, pt2;
360 }
361
362
363 // C wrappers
364 // QLine
365 private extern(C) void qtd_QLine_writeTo_QDataStream(void* __this_nativeId,
366 void* arg__1);
367 private extern(C) void qtd_QLine_readFrom_QDataStream(void* __this_nativeId,
368 void* arg__1);
369
370 // QLineF
371 private extern(C) bool qtd_QLineF_isNull(void* __this_nativeId);
372 private extern(C) double qtd_QLineF_angle(void* __this_nativeId);
373 private extern(C) double qtd_QLineF_angle_QLineF(void* __this_nativeId,
374 void* l0);
375 private extern(C) double qtd_QLineF_angleTo_QLineF(void* __this_nativeId,
376 void* l0);
377 private extern(C) int qtd_QLineF_intersect_QLineF_nativepointerQPointF(void* __this_nativeId,
378 void* l0,
379 void* intersectionPoint1);
380 private extern(C) double qtd_QLineF_length(void* __this_nativeId);
381 private extern(C) void qtd_QLineF_writeTo_QDataStream(void* __this_nativeId,
382 void* arg__1);
383 private extern(C) void qtd_QLineF_readFrom_QDataStream(void* __this_nativeId,
384 void* arg__1);
385 private extern(C) void qtd_QLineF_setAngle_double(void* __this_nativeId,
386 double angle0);
387
388 private extern(C) QLineF qtd_QLineF_unitVector(void* __this_nativeId);
389 private extern(C) QLineF qtd_QLineF_fromPolar_double_double(double length0,
390 double angle1);