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