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.core.line; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.global; 19 import qt.core.metatype; 20 import qt.core.point; 21 import qt.core.typeinfo; 22 import qt.helpers; 23 24 /******************************************************************************* 25 * class QLine 26 *******************************************************************************/ 27 28 @(QMetaType.Type.QLine) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QLine 29 { 30 public: 31 /+pragma(inline, true) this() { }+/ 32 pragma(inline, true) this(const(QPoint) pt1_, const(QPoint) pt2_) 33 { 34 this.pt1 = pt1_; 35 this.pt2 = pt2_; 36 } 37 pragma(inline, true) this(int x1pos, int y1pos, int x2pos, int y2pos) 38 { 39 this.pt1 = QPoint(x1pos, y1pos); 40 this.pt2 = QPoint(x2pos, y2pos); 41 } 42 43 pragma(inline, true) bool isNull() const 44 { 45 return pt1 == pt2; 46 } 47 48 pragma(inline, true) QPoint p1() const 49 { 50 return pt1; 51 } 52 pragma(inline, true) QPoint p2() const 53 { 54 return pt2; 55 } 56 57 pragma(inline, true) int x1() const 58 { 59 return pt1.x(); 60 } 61 pragma(inline, true) int y1() const 62 { 63 return pt1.y(); 64 } 65 66 pragma(inline, true) int x2() const 67 { 68 return pt2.x(); 69 } 70 pragma(inline, true) int y2() const 71 { 72 return pt2.y(); 73 } 74 75 pragma(inline, true) int dx() const 76 { 77 return pt2.x() - pt1.x(); 78 } 79 pragma(inline, true) int dy() const 80 { 81 return pt2.y() - pt1.y(); 82 } 83 84 pragma(inline, true) void translate(ref const(QPoint) point) 85 { 86 pt1 += point; 87 pt2 += point; 88 } 89 pragma(inline, true) void translate(int adx, int ady) 90 { 91 auto tmp=QPoint(adx, ady); this.translate(tmp); 92 } 93 94 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QLine translated(ref const(QPoint) p) const 95 { 96 return QLine(pt1 + p, pt2 + p); 97 } 98 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QLine translated(int adx, int ady) const 99 { 100 auto tmp = QPoint(adx, ady); return translated(tmp); 101 } 102 103 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QPoint center() const 104 { 105 return QPoint(cast(int)((qint64(pt1.x()) + pt2.x()) / 2), cast(int)((qint64(pt1.y()) + pt2.y()) / 2)); 106 } 107 108 pragma(inline, true) void setP1(ref const(QPoint) aP1) 109 { 110 pt1 = aP1; 111 } 112 pragma(inline, true) void setP2(ref const(QPoint) aP2) 113 { 114 pt2 = aP2; 115 } 116 pragma(inline, true) void setPoints(ref const(QPoint) aP1, ref const(QPoint) aP2) 117 { 118 pt1 = aP1; 119 pt2 = aP2; 120 } 121 pragma(inline, true) void setLine(int aX1, int aY1, int aX2, int aY2) 122 { 123 pt1 = QPoint(aX1, aY1); 124 pt2 = QPoint(aX2, aY2); 125 } 126 127 /+pragma(inline, true) bool operator ==(ref const(QLine) d) const 128 { 129 return pt1 == d.pt1 && pt2 == d.pt2; 130 }+/ 131 /+pragma(inline, true) bool operator !=(ref const(QLine) d) const { return !(this == d); }+/ 132 133 private: 134 QPoint pt1; QPoint pt2; 135 } 136 /+ Q_DECLARE_TYPEINFO(QLine, Q_MOVABLE_TYPE); 137 138 /******************************************************************************* 139 * class QLine inline members 140 *******************************************************************************/ 141 142 #ifndef QT_NO_DEBUG_STREAM 143 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p); 144 #endif 145 146 #ifndef QT_NO_DATASTREAM 147 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLine &); 148 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLine &); 149 #endif +/ 150 151 /******************************************************************************* 152 * class QLineF 153 *******************************************************************************/ 154 @(QMetaType.Type.QLineF) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QLineF { 155 public: 156 157 enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection } 158 alias IntersectionType = IntersectType; 159 160 /+pragma(inline, true) this() 161 { 162 }+/ 163 pragma(inline, true) this(const(QPointF) apt1, const(QPointF) apt2) 164 { 165 this.pt1 = apt1; 166 this.pt2 = apt2; 167 } 168 pragma(inline, true) this(qreal x1pos, qreal y1pos, qreal x2pos, qreal y2pos) 169 { 170 this.pt1 = typeof(this.pt1)(x1pos, y1pos); 171 this.pt2 = typeof(this.pt2)(x2pos, y2pos); 172 } 173 /+pragma(inline, true) this(ref const(QLine) line) 174 { 175 this.pt1 = line.p1(); 176 this.pt2 = line.p2(); 177 }+/ 178 179 /+ Q_REQUIRED_RESULT +/ static QLineF fromPolar(qreal length, qreal angle); 180 181 pragma(inline, true) bool isNull() const 182 { 183 return qFuzzyCompare(pt1.x(), pt2.x()) && qFuzzyCompare(pt1.y(), pt2.y()); 184 } 185 186 pragma(inline, true) QPointF p1() const 187 { 188 return pt1; 189 } 190 pragma(inline, true) QPointF p2() const 191 { 192 return pt2; 193 } 194 195 pragma(inline, true) qreal x1() const 196 { 197 return pt1.x(); 198 } 199 pragma(inline, true) qreal y1() const 200 { 201 return pt1.y(); 202 } 203 204 pragma(inline, true) qreal x2() const 205 { 206 return pt2.x(); 207 } 208 pragma(inline, true) qreal y2() const 209 { 210 return pt2.y(); 211 } 212 213 pragma(inline, true) qreal dx() const 214 { 215 return pt2.x() - pt1.x(); 216 } 217 pragma(inline, true) qreal dy() const 218 { 219 return pt2.y() - pt1.y(); 220 } 221 222 qreal length() const; 223 void setLength(qreal len) 224 { 225 if (isNull()) 226 return; 227 (mixin(Q_ASSERT(q{QLineF.length() > 0}))); 228 const(QLineF) v = unitVector(); 229 len /= v.length(); // In case it's not quite exactly 1. 230 pt2 = QPointF(pt1.x() + len * v.dx(), pt1.y() + len * v.dy()); 231 } 232 233 qreal angle() const; 234 void setAngle(qreal angle); 235 236 qreal angleTo(ref const(QLineF) l) const; 237 238 /+ Q_REQUIRED_RESULT +/ QLineF unitVector() const; 239 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QLineF normalVector() const 240 { 241 auto tmp = p1(); return QLineF(tmp, p1() + QPointF(dy(), -dx())); 242 } 243 244 IntersectionType intersects(ref const(QLineF) l, QPointF* intersectionPoint) const; 245 246 /+ #if QT_DEPRECATED_SINCE(5, 14) +/ 247 /+ QT_DEPRECATED_VERSION_X(5, 14, "Use intersects() instead") +/ 248 IntersectType intersect(ref const(QLineF) l, QPointF* intersectionPoint) const; 249 /+ QT_DEPRECATED_X("Use qMin(l1.angleTo(l2), l2.angleTo(l1)) instead") +/ 250 qreal angle(ref const(QLineF) l) const; 251 /+ #endif +/ 252 253 pragma(inline, true) QPointF pointAt(qreal t) const 254 { 255 return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t); 256 } 257 pragma(inline, true) void translate(ref const(QPointF) point) 258 { 259 pt1 += point; 260 pt2 += point; 261 } 262 pragma(inline, true) void translate(qreal adx, qreal ady) 263 { 264 auto tmp = QPointF(adx, ady); this.translate(tmp); 265 } 266 267 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QLineF translated(ref const(QPointF) p) const 268 { 269 return QLineF(pt1 + p, pt2 + p); 270 } 271 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QLineF translated(qreal adx, qreal ady) const 272 { 273 auto tmp = QPointF(adx, ady); return translated(tmp); 274 } 275 276 /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QPointF center() const 277 { 278 return QPointF(0.5 * pt1.x() + 0.5 * pt2.x(), 0.5 * pt1.y() + 0.5 * pt2.y()); 279 } 280 281 pragma(inline, true) void setP1(ref const(QPointF) aP1) 282 { 283 pt1 = aP1; 284 } 285 pragma(inline, true) void setP2(ref const(QPointF) aP2) 286 { 287 pt2 = aP2; 288 } 289 pragma(inline, true) void setPoints(ref const(QPointF) aP1, ref const(QPointF) aP2) 290 { 291 pt1 = aP1; 292 pt2 = aP2; 293 } 294 pragma(inline, true) void setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2) 295 { 296 pt1 = QPointF(aX1, aY1); 297 pt2 = QPointF(aX2, aY2); 298 } 299 300 /+pragma(inline, true) bool operator ==(ref const(QLineF) d) const 301 { 302 return pt1 == d.pt1 && pt2 == d.pt2; 303 }+/ 304 /+pragma(inline, true) bool operator !=(ref const(QLineF) d) const { return !(this == d); }+/ 305 306 pragma(inline, true) QLine toLine() const 307 { 308 auto tmp = pt1.toPoint(); auto tmp__1 = pt2.toPoint(); return QLine(tmp, tmp__1); 309 } 310 311 private: 312 QPointF pt1; QPointF pt2; 313 } 314 /+ Q_DECLARE_TYPEINFO(QLineF, Q_MOVABLE_TYPE); 315 316 /******************************************************************************* 317 * class QLineF inline members 318 *******************************************************************************/ 319 320 321 322 323 324 #ifndef QT_NO_DEBUG_STREAM 325 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLineF &p); 326 #endif 327 328 #ifndef QT_NO_DATASTREAM 329 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLineF &); 330 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QLineF &); 331 #endif +/ 332