Mercurial > projects > qtd
comparison qt/d2/qt/core/QLine.d @ 248:7664de4a55e5
Fixed #23.
QtD_QObjectEntity is not created dynamically for shell classes any more.
Class initialization is now performed by static constructors.
When wrapping QObjects returned from functions, their run-time types are now taken into account.
QObjects are allocated on GC heap, a doubly-linked list is used to prevent them from been collected (arguably a better solution than allocating on C heap and adding GC ranges)
Minor changes (including unnecessary).
author | maxter |
---|---|
date | Thu, 20 Aug 2009 14:47:17 +0000 |
parents | 7dd099050621 |
children | 37eed70de029 |
comparison
equal
deleted
inserted
replaced
247:27497bbe62a1 | 248:7664de4a55e5 |
---|---|
22 | 22 |
23 public this(int x1pos, int y1pos, int x2pos, int y2pos) { | 23 public this(int x1pos, int y1pos, int x2pos, int y2pos) { |
24 pt1 = QPoint(x1pos, y1pos); | 24 pt1 = QPoint(x1pos, y1pos); |
25 pt2 = QPoint(x2pos, y2pos); | 25 pt2 = QPoint(x2pos, y2pos); |
26 } | 26 } |
27 | 27 |
28 bool isNull() // const | 28 bool isNull() // const |
29 { | 29 { |
30 return pt1 == pt2; | 30 return pt1 == pt2; |
31 } | 31 } |
32 | 32 |
33 int x1() // const | 33 int x1() // const |
34 { | 34 { |
35 return pt1.x(); | 35 return pt1.x(); |
36 } | 36 } |
37 | 37 |
38 int y1() // const | 38 int y1() // const |
39 { | 39 { |
40 return pt1.y(); | 40 return pt1.y(); |
41 } | 41 } |
42 | 42 |
43 int x2() // const | 43 int x2() // const |
44 { | 44 { |
45 return pt2.x(); | 45 return pt2.x(); |
46 } | 46 } |
47 | 47 |
48 int y2() // const | 48 int y2() // const |
49 { | 49 { |
50 return pt2.y(); | 50 return pt2.y(); |
51 } | 51 } |
52 | 52 |
53 QPoint p1() // const | 53 QPoint p1() // const |
54 { | 54 { |
55 return pt1; | 55 return pt1; |
56 } | 56 } |
57 | 57 |
58 QPoint p2() // const | 58 QPoint p2() // const |
59 { | 59 { |
60 return pt2; | 60 return pt2; |
61 } | 61 } |
62 | 62 |
63 int dx() // const | 63 int dx() // const |
64 { | 64 { |
65 return pt2.x() - pt1.x(); | 65 return pt2.x() - pt1.x(); |
66 } | 66 } |
67 | 67 |
68 int dy() // const | 68 int dy() // const |
69 { | 69 { |
70 return pt2.y() - pt1.y(); | 70 return pt2.y() - pt1.y(); |
71 } | 71 } |
72 | 72 |
73 void translate(ref QPoint point) | 73 void translate(ref QPoint point) |
74 { | 74 { |
75 pt1 += point; | 75 pt1 += point; |
76 pt2 += point; | 76 pt2 += point; |
77 } | 77 } |
78 | 78 |
79 void translate(int adx, int ady) | 79 void translate(int adx, int ady) |
80 { | 80 { |
81 translate(QPoint(adx, ady)); | 81 translate(QPoint(adx, ady)); |
82 } | 82 } |
83 | 83 |
84 QLine translated(ref QPoint p) // const | 84 QLine translated(ref QPoint p) // const |
85 { | 85 { |
86 return QLine(pt1 + p, pt2 + p); | 86 return QLine(pt1 + p, pt2 + p); |
87 } | 87 } |
88 | 88 |
89 QLine translated(int adx, int ady) // const | 89 QLine translated(int adx, int ady) // const |
90 { | 90 { |
91 return translated(QPoint(adx, ady)); | 91 return translated(QPoint(adx, ady)); |
92 } | 92 } |
93 | 93 |
103 | 103 |
104 void setP1(ref QPoint aP1) // for convenience | 104 void setP1(ref QPoint aP1) // for convenience |
105 { | 105 { |
106 pt1 = aP1; | 106 pt1 = aP1; |
107 } | 107 } |
108 | 108 |
109 void setP2(ref QPoint aP2) // for convenience | 109 void setP2(ref QPoint aP2) // for convenience |
110 { | 110 { |
111 pt2 = aP2; | 111 pt2 = aP2; |
112 } | 112 } |
113 | 113 |
114 void setPoints(ref QPoint aP1, ref QPoint aP2) | 114 void setPoints(ref QPoint aP1, ref QPoint aP2) |
115 { | 115 { |
116 pt1 = aP1; | 116 pt1 = aP1; |
117 pt2 = aP2; | 117 pt2 = aP2; |
118 } | 118 } |
119 | 119 |
120 void setLine(int aX1, int aY1, int aX2, int aY2) | 120 void setLine(int aX1, int aY1, int aX2, int aY2) |
121 { | 121 { |
122 pt1 = QPoint(aX1, aY1); | 122 pt1 = QPoint(aX1, aY1); |
123 pt2 = QPoint(aX2, aY2); | 123 pt2 = QPoint(aX2, aY2); |
124 } | 124 } |
125 | 125 |
126 bool opEquals(ref QLine d) // const | 126 bool opEquals(ref QLine d) // const |
127 { | 127 { |
128 return pt1 == d.pt1 && pt2 == d.pt2; | 128 return pt1 == d.pt1 && pt2 == d.pt2; |
129 } | 129 } |
130 | 130 |
131 public final void writeTo(QDataStream arg__1) { | 131 public final void writeTo(QDataStream arg__1) { |
132 qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); | 132 qtd_QLine_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); |
133 } | 133 } |
134 | 134 |
135 public final void readFrom(QDataStream arg__1) { | 135 public final void readFrom(QDataStream arg__1) { |
136 qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); | 136 qtd_QLine_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); |
137 } | 137 } |
138 | 138 |
139 private: | 139 private: |
140 QPoint pt1, pt2; | 140 QPoint pt1, pt2; |
141 } | 141 } |
147 UnboundedIntersection = 2 | 147 UnboundedIntersection = 2 |
148 } | 148 } |
149 | 149 |
150 public struct QLineF | 150 public struct QLineF |
151 { | 151 { |
152 | 152 |
153 alias QLineF_IntersectType IntersectType; | 153 alias QLineF_IntersectType IntersectType; |
154 | 154 |
155 alias QLineF_IntersectType.NoIntersection NoIntersection; | 155 alias QLineF_IntersectType.NoIntersection NoIntersection; |
156 alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; | 156 alias QLineF_IntersectType.BoundedIntersection BoundedIntersection; |
157 alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; | 157 alias QLineF_IntersectType.UnboundedIntersection UnboundedIntersection; |
158 | 158 |
159 public static QLineF opCall() { | 159 public static QLineF opCall() { |
160 QLineF ln; | 160 QLineF ln; |
161 ln.pt1 = QPointF(); | 161 ln.pt1 = QPointF(); |
162 ln.pt2 = QPointF(); | 162 ln.pt2 = QPointF(); |
163 return ln; | 163 return ln; |
164 } | 164 } |
165 | 165 |
166 public this(QPointF apt1, QPointF apt2) { | 166 public this(QPointF apt1, QPointF apt2) { |
167 pt1 = apt1; | 167 pt1 = apt1; |
168 pt2 = apt2; | 168 pt2 = apt2; |
169 } | 169 } |
170 | 170 |
171 public this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { | 171 public this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) { |
172 pt1 = QPointF(x1pos, y1pos); | 172 pt1 = QPointF(x1pos, y1pos); |
173 pt2 = QPointF(x2pos, y2pos); | 173 pt2 = QPointF(x2pos, y2pos); |
174 } | 174 } |
175 | 175 |
176 public this(QLine line){ | 176 public this(QLine line){ |
177 pt1 = QPointF(line.p1()); | 177 pt1 = QPointF(line.p1()); |
178 pt2 = QPointF(line.p2()); | 178 pt2 = QPointF(line.p2()); |
179 } | 179 } |
180 | 180 |
181 public final bool isNull() // const | 181 public final bool isNull() // const |
182 { | 182 { |
183 return qtd_QLineF_isNull(&this); | 183 return qtd_QLineF_isNull(&this); |
184 } | 184 } |
185 | 185 |
186 qreal x1() // const | 186 qreal x1() // const |
187 { | 187 { |
188 return pt1.x(); | 188 return pt1.x(); |
189 } | 189 } |
190 | 190 |
191 qreal y1() // const | 191 qreal y1() // const |
192 { | 192 { |
193 return pt1.y(); | 193 return pt1.y(); |
194 } | 194 } |
195 | 195 |
196 qreal x2() // const | 196 qreal x2() // const |
197 { | 197 { |
198 return pt2.x(); | 198 return pt2.x(); |
199 } | 199 } |
200 | 200 |
201 qreal y2() // const | 201 qreal y2() // const |
202 { | 202 { |
203 return pt2.y(); | 203 return pt2.y(); |
204 } | 204 } |
205 | 205 |
206 QPointF p1() // const | 206 QPointF p1() // const |
207 { | 207 { |
208 return pt1; | 208 return pt1; |
209 } | 209 } |
210 | 210 |
211 QPointF p2() // const | 211 QPointF p2() // const |
212 { | 212 { |
213 return pt2; | 213 return pt2; |
214 } | 214 } |
215 | 215 |
216 qreal dx() // const | 216 qreal dx() // const |
217 { | 217 { |
218 return pt2.x() - pt1.x(); | 218 return pt2.x() - pt1.x(); |
219 } | 219 } |
220 | 220 |
221 qreal dy() // const | 221 qreal dy() // const |
222 { | 222 { |
223 return pt2.y() - pt1.y(); | 223 return pt2.y() - pt1.y(); |
224 } | 224 } |
225 | 225 |
226 QLineF normalVector() // const | 226 QLineF normalVector() // const |
227 { | 227 { |
228 return QLineF(p1(), p1() + QPointF(dy(), -dx())); | 228 return QLineF(p1(), p1() + QPointF(dy(), -dx())); |
229 } | 229 } |
230 | 230 |
231 void translate(ref QPointF point) | 231 void translate(ref QPointF point) |
232 { | 232 { |
233 pt1 += point; | 233 pt1 += point; |
234 pt2 += point; | 234 pt2 += point; |
235 } | 235 } |
236 | 236 |
237 void translate(qreal adx, qreal ady) | 237 void translate(qreal adx, qreal ady) |
238 { | 238 { |
239 this.translate(QPointF(adx, ady)); | 239 this.translate(QPointF(adx, ady)); |
240 } | 240 } |
241 | 241 |
242 QLineF translated(ref QPointF p) // const | 242 QLineF translated(ref QPointF p) // const |
243 { | 243 { |
244 return QLineF(pt1 + p, pt2 + p); | 244 return QLineF(pt1 + p, pt2 + p); |
245 } | 245 } |
246 | 246 |
247 QLineF translated(qreal adx, qreal ady) // const | 247 QLineF translated(qreal adx, qreal ady) // const |
248 { | 248 { |
249 return translated(QPointF(adx, ady)); | 249 return translated(QPointF(adx, ady)); |
250 } | 250 } |
251 | 251 |
252 void setLength(qreal len) | 252 void setLength(qreal len) |
253 { | 253 { |
254 if (isNull()) | 254 if (isNull()) |
255 return; | 255 return; |
256 QLineF v = unitVector(); | 256 QLineF v = unitVector(); |
257 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); | 257 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); |
258 } | 258 } |
259 | 259 |
260 void length(qreal len) | 260 void length(qreal len) |
261 { | 261 { |
262 if (isNull()) | 262 if (isNull()) |
263 return; | 263 return; |
264 QLineF v = unitVector(); | 264 QLineF v = unitVector(); |
265 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); | 265 pt2 = QPointF(pt1.x() + v.dx() * len, pt1.y() + v.dy() * len); |
266 } | 266 } |
267 | 267 |
268 QPointF pointAt(qreal t) // const | 268 QPointF pointAt(qreal t) // const |
269 { | 269 { |
270 qreal vx = pt2.x() - pt1.x(); | 270 qreal vx = pt2.x() - pt1.x(); |
271 qreal vy = pt2.y() - pt1.y(); | 271 qreal vy = pt2.y() - pt1.y(); |
272 return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); | 272 return QPointF(pt1.x() + vx * t, pt1.y() + vy * t); |
273 } | 273 } |
274 | 274 |
275 QLine toLine() // const | 275 QLine toLine() // const |
276 { | 276 { |
277 return QLine(pt1.toPoint(), pt2.toPoint()); | 277 return QLine(pt1.toPoint(), pt2.toPoint()); |
278 } | 278 } |
279 | 279 |
280 void setP1(ref QPointF aP1) | 280 void setP1(ref QPointF aP1) |
281 { | 281 { |
282 pt1 = aP1; | 282 pt1 = aP1; |
283 } | 283 } |
284 | 284 |
285 void setP2(ref QPointF aP2) | 285 void setP2(ref QPointF aP2) |
286 { | 286 { |
287 pt2 = aP2; | 287 pt2 = aP2; |
288 } | 288 } |
289 | 289 |
290 void p1(ref QPointF aP1) | 290 void p1(ref QPointF aP1) |
291 { | 291 { |
292 pt1 = aP1; | 292 pt1 = aP1; |
293 } | 293 } |
294 | 294 |
295 void p2(ref QPointF aP2) | 295 void p2(ref QPointF aP2) |
296 { | 296 { |
297 pt2 = aP2; | 297 pt2 = aP2; |
298 } | 298 } |
299 | 299 |
300 void setPoints(ref QPointF aP1, ref QPointF aP2) | 300 void setPoints(ref QPointF aP1, ref QPointF aP2) |
301 { | 301 { |
302 pt1 = aP1; | 302 pt1 = aP1; |
303 pt2 = aP2; | 303 pt2 = aP2; |
304 } | 304 } |
305 | 305 |
306 void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) | 306 void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) |
307 { | 307 { |
308 pt1 = QPointF(aX1, aY1); | 308 pt1 = QPointF(aX1, aY1); |
309 pt2 = QPointF(aX2, aY2); | 309 pt2 = QPointF(aX2, aY2); |
310 } | 310 } |
311 | 311 |
312 bool opEquals(ref QLineF d) // const | 312 bool opEquals(ref QLineF d) // const |
313 { | 313 { |
314 return pt1 == d.pt1 && pt2 == d.pt2; | 314 return pt1 == d.pt1 && pt2 == d.pt2; |
315 } | 315 } |
316 | 316 |
317 public final double angle() { | 317 public final double angle() { |
318 return qtd_QLineF_angle(&this); | 318 return qtd_QLineF_angle(&this); |
319 } | 319 } |
320 | 320 |
321 public final double angle(ref QLineF l) { | 321 public final double angle(ref QLineF l) { |
322 return qtd_QLineF_angle_QLineF(&this, &l); | 322 return qtd_QLineF_angle_QLineF(&this, &l); |
323 } | 323 } |
324 | 324 |
325 public final double angleTo(ref QLineF l) { | 325 public final double angleTo(ref QLineF l) { |
326 return qtd_QLineF_angleTo_QLineF(&this, &l); | 326 return qtd_QLineF_angleTo_QLineF(&this, &l); |
327 } | 327 } |
328 | 328 |
329 // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType | 329 // ### Qt 5: rename intersects() or intersection() and rename IntersectType IntersectionType |
330 private final QLineF_IntersectType intersect(ref QLineF l, QPointF* intersectionPoint) { | 330 private final QLineF_IntersectType intersect(ref QLineF l, QPointF* intersectionPoint) { |
331 return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(&this, &l, intersectionPoint); | 331 return cast(QLineF_IntersectType) qtd_QLineF_intersect_QLineF_nativepointerQPointF(&this, &l, intersectionPoint); |
332 } | 332 } |
333 | 333 |
334 public final double length() { | 334 public final double length() { |
335 return qtd_QLineF_length(&this); | 335 return qtd_QLineF_length(&this); |
336 } | 336 } |
337 | 337 |
338 public final void writeTo(QDataStream arg__1) { | 338 public final void writeTo(QDataStream arg__1) { |
339 qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); | 339 qtd_QLineF_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); |
340 } | 340 } |
341 | 341 |
342 public final void readFrom(QDataStream arg__1) { | 342 public final void readFrom(QDataStream arg__1) { |
343 qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.nativeId); | 343 qtd_QLineF_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.__nativeId); |
344 } | 344 } |
345 | 345 |
346 public final void setAngle(double angle) { | 346 public final void setAngle(double angle) { |
347 qtd_QLineF_setAngle_double(&this, angle); | 347 qtd_QLineF_setAngle_double(&this, angle); |
348 } | 348 } |
349 | 349 |
350 public final QLineF unitVector() { | 350 public final QLineF unitVector() { |
351 return qtd_QLineF_unitVector(&this); | 351 return qtd_QLineF_unitVector(&this); |
352 } | 352 } |
353 | 353 |
354 public static QLineF fromPolar(double length, double angle) { | 354 public static QLineF fromPolar(double length, double angle) { |
355 return qtd_QLineF_fromPolar_double_double(length, angle); | 355 return qtd_QLineF_fromPolar_double_double(length, angle); |
356 } | 356 } |
357 | 357 |
358 private: | 358 private: |
359 QPointF pt1, pt2; | 359 QPointF pt1, pt2; |
360 } | 360 } |
361 | 361 |
362 | 362 |