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.point; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.global; 19 import qt.core.metatype; 20 import qt.core.typeinfo; 21 import qt.helpers; 22 23 /+ #if defined(Q_OS_DARWIN) || defined(Q_QDOC) 24 struct CGPoint; 25 #endif +/ 26 27 28 29 @Q_MOVABLE_TYPE @(QMetaType.Type.QPoint) extern(C++, class) struct /+ Q_CORE_EXPORT +/ QPoint 30 { 31 public: 32 /+pragma(inline, true) this() 33 { 34 this.xp = 0; 35 this.yp = 0; 36 }+/ 37 pragma(inline, true) this(int xpos, int ypos) 38 { 39 this.xp = xpos; 40 this.yp = ypos; 41 } 42 43 pragma(inline, true) bool isNull() const 44 { return xp == 0 && yp == 0; } 45 46 pragma(inline, true) int x() const 47 { return xp; } 48 pragma(inline, true) int y() const 49 { return yp; } 50 pragma(inline, true) void setX(int xpos) 51 { xp = xpos; } 52 pragma(inline, true) void setY(int ypos) 53 { yp = ypos; } 54 55 pragma(inline, true) int manhattanLength() const 56 { return qAbs(x())+qAbs(y()); } 57 58 QPoint transposed() const/+ noexcept+/ { return QPoint(yp, xp); } 59 60 pragma(inline, true) ref int rx() return 61 { return xp; } 62 pragma(inline, true) ref int ry() return 63 { return yp; } 64 65 pragma(inline, true) ref QPoint opOpAssign(string op)(ref const(QPoint) p) if(op == "+") 66 { xp+=p.xp; yp+=p.yp; return this; } 67 pragma(inline, true) ref QPoint opOpAssign(string op)(ref const(QPoint) p) if(op == "-") 68 { xp-=p.xp; yp-=p.yp; return this; } 69 70 /+pragma(inline, true) ref QPoint operator *=(float factor) 71 { xp = qRound(xp*factor); yp = qRound(yp*factor); return this; }+/ 72 /+pragma(inline, true) ref QPoint operator *=(double factor) 73 { xp = qRound(xp*factor); yp = qRound(yp*factor); return this; }+/ 74 /+pragma(inline, true) ref QPoint operator *=(int factor) 75 { xp = xp*factor; yp = yp*factor; return this; }+/ 76 77 /+pragma(inline, true) ref QPoint operator /=(qreal c) 78 { 79 xp = qRound(xp/c); 80 yp = qRound(yp/c); 81 return this; 82 }+/ 83 84 pragma(inline, true) static int dotProduct(ref const(QPoint) p1, ref const(QPoint) p2) 85 { return p1.xp * p2.xp + p1.yp * p2.yp; } 86 87 /+ friend inline bool operator==(const QPoint &, const QPoint &); +/ 88 /+ friend inline bool operator!=(const QPoint &, const QPoint &); +/ 89 /+ friend inline const QPoint operator+(const QPoint &, const QPoint &); +/ 90 91 /+ Q_DECL_CONSTEXPR +/ pragma(inline, true) const(QPoint) opBinary(string op)(const(QPoint) p2) const if(op == "+") 92 { return QPoint(this.xp+p2.xp, this.yp+p2.yp); } 93 94 /+ friend inline const QPoint operator-(const QPoint &, const QPoint &); +/ 95 /+ friend inline const QPoint operator*(const QPoint &, float); +/ 96 /+ friend inline const QPoint operator*(float, const QPoint &); +/ 97 /+ friend inline const QPoint operator*(const QPoint &, double); +/ 98 /+ friend inline const QPoint operator*(double, const QPoint &); +/ 99 /+ friend inline const QPoint operator*(const QPoint &, int); +/ 100 /+ friend inline const QPoint operator*(int, const QPoint &); +/ 101 /+ friend inline const QPoint operator+(const QPoint &); +/ 102 /+ friend inline const QPoint operator-(const QPoint &); +/ 103 /+ friend inline const QPoint operator/(const QPoint &, qreal); +/ 104 105 static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS"))) 106 { 107 /+ Q_REQUIRED_RESULT CGPoint toCGPoint() const noexcept; +/ 108 } 109 110 111 pragma(inline, true) const(QPoint) opBinary(string op)(const(QPoint) p2) if(op == "+") 112 { return QPoint(xp+p2.xp, yp+p2.yp); } 113 114 pragma(inline, true) const(QPoint) opBinary(string op)(const(QPoint) p2) if(op == "-") 115 { return QPoint(xp-p2.xp, yp-p2.yp); } 116 117 118 private: 119 /+ friend class QTransform; +/ 120 int xp = 0; 121 int yp = 0; 122 } 123 124 /+ Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE); 125 126 /***************************************************************************** 127 QPoint stream functions 128 *****************************************************************************/ 129 #ifndef QT_NO_DATASTREAM 130 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPoint &); 131 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPoint &); 132 #endif +/ 133 134 /***************************************************************************** 135 QPoint inline functions 136 *****************************************************************************/ 137 138 /+pragma(inline, true) bool operator ==(ref const(QPoint) p1, ref const(QPoint) p2) 139 { return p1.xp == p2.xp && p1.yp == p2.yp; }+/ 140 141 /+pragma(inline, true) bool operator !=(ref const(QPoint) p1, ref const(QPoint) p2) 142 { return p1.xp != p2.xp || p1.yp != p2.yp; }+/ 143 144 145 /+pragma(inline, true) const(QPoint) operator *(ref const(QPoint) p, float factor) 146 { return QPoint(qRound(p.xp*factor), qRound(p.yp*factor)); }+/ 147 148 /+pragma(inline, true) const(QPoint) operator *(ref const(QPoint) p, double factor) 149 { return QPoint(qRound(p.xp*factor), qRound(p.yp*factor)); }+/ 150 151 /+pragma(inline, true) const(QPoint) operator *(ref const(QPoint) p, int factor) 152 { return QPoint(p.xp*factor, p.yp*factor); }+/ 153 154 /+pragma(inline, true) const(QPoint) operator *(float factor, ref const(QPoint) p) 155 { return QPoint(qRound(p.xp*factor), qRound(p.yp*factor)); }+/ 156 157 /+pragma(inline, true) const(QPoint) operator *(double factor, ref const(QPoint) p) 158 { return QPoint(qRound(p.xp*factor), qRound(p.yp*factor)); }+/ 159 160 /+pragma(inline, true) const(QPoint) operator *(int factor, ref const(QPoint) p) 161 { return QPoint(p.xp*factor, p.yp*factor); }+/ 162 163 /+pragma(inline, true) const(QPoint) operator +(ref const(QPoint) p) 164 { return p; }+/ 165 166 /+pragma(inline, true) const(QPoint) operator -(ref const(QPoint) p) 167 { return QPoint(-p.xp, -p.yp); }+/ 168 169 /+pragma(inline, true) const(QPoint) operator /(ref const(QPoint) p, qreal c) 170 { 171 return QPoint(qRound(p.xp/c), qRound(p.yp/c)); 172 }+/ 173 174 /+ #ifndef QT_NO_DEBUG_STREAM 175 Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &); 176 #endif +/ 177 178 179 180 181 182 @Q_MOVABLE_TYPE @(QMetaType.Type.QPointF) extern(C++, class) struct /+ Q_CORE_EXPORT +/ QPointF 183 { 184 public: 185 /+pragma(inline, true) this() 186 { 187 this.xp = 0; 188 this.yp = 0; 189 }+/ 190 pragma(inline, true) this(ref const(QPoint) p) 191 { 192 this.xp = p.x(); 193 this.yp = p.y(); 194 } 195 pragma(inline, true) this(qreal xpos, qreal ypos) 196 { 197 this.xp = xpos; 198 this.yp = ypos; 199 } 200 201 pragma(inline, true) qreal manhattanLength() const 202 { 203 return qAbs(x())+qAbs(y()); 204 } 205 206 pragma(inline, true) bool isNull() const 207 { 208 return qIsNull(xp) && qIsNull(yp); 209 } 210 211 pragma(inline, true) qreal x() const 212 { 213 return xp; 214 } 215 pragma(inline, true) qreal y() const 216 { 217 return yp; 218 } 219 pragma(inline, true) void setX(qreal xpos) 220 { 221 xp = xpos; 222 } 223 pragma(inline, true) void setY(qreal ypos) 224 { 225 yp = ypos; 226 } 227 228 QPointF transposed() const/+ noexcept+/ { return QPointF(yp, xp); } 229 230 pragma(inline, true) ref qreal rx() return 231 { 232 return xp; 233 } 234 pragma(inline, true) ref qreal ry() return 235 { 236 return yp; 237 } 238 239 pragma(inline, true) ref QPointF opOpAssign(string op)(ref const(QPointF) p) if(op == "+") 240 { 241 xp+=p.xp; 242 yp+=p.yp; 243 return this; 244 } 245 pragma(inline, true) ref QPointF opOpAssign(string op)(ref const(QPointF) p) if(op == "-") 246 { 247 xp-=p.xp; yp-=p.yp; return this; 248 } 249 /+pragma(inline, true) ref QPointF operator *=(qreal c) 250 { 251 xp*=c; yp*=c; return this; 252 }+/ 253 /+pragma(inline, true) ref QPointF operator /=(qreal divisor) 254 { 255 xp/=divisor; 256 yp/=divisor; 257 return this; 258 }+/ 259 260 pragma(inline, true) static qreal dotProduct(ref const(QPointF) p1, ref const(QPointF) p2) 261 { return p1.xp * p2.xp + p1.yp * p2.yp; } 262 263 /+ friend inline bool operator==(const QPointF &, const QPointF &); +/ 264 /+ friend inline bool operator!=(const QPointF &, const QPointF &); +/ 265 /+ friend inline const QPointF operator+(const QPointF &, const QPointF &); +/ 266 267 pragma(inline, true) const(QPointF) opBinary(string op)(const(QPointF) p2) const if(op == "+") 268 { 269 return QPointF(this.xp+p2.xp, this.yp+p2.yp); 270 } 271 272 /+ friend inline const QPointF operator-(const QPointF &, const QPointF &); +/ 273 /+ friend inline const QPointF operator*(qreal, const QPointF &); +/ 274 /+ friend inline const QPointF operator*(const QPointF &, qreal); +/ 275 /+ friend inline const QPointF operator+(const QPointF &); +/ 276 /+ friend inline const QPointF operator-(const QPointF &); +/ 277 /+ friend inline const QPointF operator/(const QPointF &, qreal); +/ 278 279 pragma(inline, true) QPoint toPoint() const 280 { 281 return QPoint(qRound(xp), qRound(yp)); 282 } 283 284 static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS"))) 285 { 286 /+ Q_REQUIRED_RESULT static QPointF fromCGPoint(CGPoint point) noexcept; +/ 287 /+ Q_REQUIRED_RESULT CGPoint toCGPoint() const noexcept; +/ 288 } 289 290 private: 291 /+ friend class QMatrix; +/ 292 /+ friend class QTransform; +/ 293 294 qreal xp = 0; 295 qreal yp = 0; 296 } 297 298 /+ Q_DECLARE_TYPEINFO(QPointF, Q_MOVABLE_TYPE); 299 300 /***************************************************************************** 301 QPointF stream functions 302 *****************************************************************************/ 303 #ifndef QT_NO_DATASTREAM 304 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPointF &); 305 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPointF &); 306 #endif 307 308 /***************************************************************************** 309 QPointF inline functions 310 *****************************************************************************/ 311 312 QT_WARNING_PUSH 313 QT_WARNING_DISABLE_CLANG("-Wfloat-equal") 314 QT_WARNING_DISABLE_GCC("-Wfloat-equal") 315 QT_WARNING_DISABLE_INTEL(1572) +/ 316 317 /+pragma(inline, true) bool operator ==(ref const(QPointF) p1, ref const(QPointF) p2) 318 { 319 return ((!p1.xp || !p2.xp) ? qFuzzyIsNull(p1.xp - p2.xp) : qFuzzyCompare(p1.xp, p2.xp)) 320 && ((!p1.yp || !p2.yp) ? qFuzzyIsNull(p1.yp - p2.yp) : qFuzzyCompare(p1.yp, p2.yp)); 321 }+/ 322 323 /+pragma(inline, true) bool operator !=(ref const(QPointF) p1, ref const(QPointF) p2) 324 { 325 return !(p1 == p2); 326 }+/ 327 328 /+ QT_WARNING_POP +/ 329 330 /+pragma(inline, true) const(QPointF) operator +(ref const(QPointF) p1, ref const(QPointF) p2) 331 { 332 return QPointF(p1.xp+p2.xp, p1.yp+p2.yp); 333 }+/ 334 335 /+pragma(inline, true) const(QPointF) operator -(ref const(QPointF) p1, ref const(QPointF) p2) 336 { 337 return QPointF(p1.xp-p2.xp, p1.yp-p2.yp); 338 }+/ 339 340 /+pragma(inline, true) const(QPointF) operator *(ref const(QPointF) p, qreal c) 341 { 342 return QPointF(p.xp*c, p.yp*c); 343 }+/ 344 345 /+pragma(inline, true) const(QPointF) operator *(qreal c, ref const(QPointF) p) 346 { 347 return QPointF(p.xp*c, p.yp*c); 348 }+/ 349 350 /+pragma(inline, true) const(QPointF) operator +(ref const(QPointF) p) 351 { 352 return p; 353 }+/ 354 355 /+pragma(inline, true) const(QPointF) operator -(ref const(QPointF) p) 356 { 357 return QPointF(-p.xp, -p.yp); 358 }+/ 359 360 /+pragma(inline, true) const(QPointF) operator /(ref const(QPointF) p, qreal divisor) 361 { 362 return QPointF(p.xp/divisor, p.yp/divisor); 363 }+/ 364 365 /+ #ifndef QT_NO_DEBUG_STREAM 366 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QPointF &p); 367 #endif +/ 368