1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #include "../MathBuildConfig.h"21 22 #ifdef MATH_ENABLE_STL_SUPPORT23 #include <string>24 #include <vector>25 #endif26 27 #include "../MathGeoLibFwd.h"28 29 #ifdef MATH_QT_INTEROP30 #include <QVector2D>31 #endif32 #ifdef MATH_OGRE_INTEROP33 #include <OgreVector2.h>34 #endif35 #ifdef MATH_URHO3D_INTEROP36 #include <Urho3D/Math/Vector2.h>37 #endif38 39 [MATH_BEGIN_NAMESPACE]40 41 42 class [float2]43 {44 public:45 enum46 {47 48 [Size] = 249 };50 51 52 float [x];53 54 55 float [y];56 57 58 59 60 61 [float2]() {}62 63 #ifdef MATH_EXPLICIT_COPYCTORS64 65 66 67 [float2](const [float2] &rhs) { [x] = rhs.[x]; [y] = rhs.[y]; }68 #endif69 70 71 72 [float2](float [x], float [y]);73 74 75 76 explicit [float2](float scalar);77 78 79 80 explicit [float2](const float *data);81 82 83 84 85 86 87 88 89 90 91 92 93 [FORCE_INLINE] float *[ptr]() { return &[x]; }94 [FORCE_INLINE] const float *[ptr]() const { return &[x]; }95 96 97 98 99 100 101 float &[operator []](int index) { return [At](index); }102 [CONST_WIN32] float [operator []](int index) const { return [At](index); }103 104 105 106 107 108 109 float &[At](int index);110 [CONST_WIN32] float [At](int index) const;111 112 113 114 115 [float2] [operator +](const [float2] &v) const;116 117 118 119 [float2] [operator -]() const;120 121 122 123 [float2] [operator -](const [float2] &v) const;124 125 126 127 [float2] [operator *](float scalar) const;128 129 130 131 [float2] [operator /](float scalar) const;132 133 [float2] [operator +]() const { return *this; }134 135 136 137 [float2] &[operator +=](const [float2] &v);138 139 140 [float2] &[operator -=](const [float2] &v);141 142 143 [float2] &[operator *=](float scalar);144 145 146 [float2] &[operator /=](float scalar);147 148 #ifdef MATH_ENABLE_UNCOMMON_OPERATIONS149 150 151 152 153 154 155 [float2] [operator *](const [float2] &vector) const { return this->[Mul](vector); }156 [float2] [operator /](const [float2] &vector) const { return this->[Div](vector); }157 [float2] &[operator *=](const [float2] &vector) { *this = this->[Mul](vector); return *this; }158 [float2] &[operator /=](const [float2] &vector) { *this = this->[Div](vector); return *this; }159 #endif160 161 162 163 [float2] [Add](const [float2] &v) const { return *this + v; }164 165 166 167 168 169 [float2] [Add](float s) const;170 171 172 173 [float2] [Sub](const [float2] &v) const { return *this - v; }174 175 176 177 178 179 [float2] [Sub](float s) const;180 181 182 183 184 185 [float2] [SubLeft](float s) const;186 187 188 189 190 191 [float2] [Mul](const [float2] &v) const;192 193 194 195 [float2] [Mul](float s) const { return *this * s; }196 197 198 199 200 201 [float2] [Div](const [float2] &v) const;202 203 204 205 [float2] [Div](float s) const { return *this / s; }206 207 208 209 210 211 [float2] [DivLeft](float s) const;212 213 214 [float2] [xx]() const { return [float2]([x],[x]); }215 [float2] [xy]() const { return [float2]([x],[y]); } 216 [float2] [yx]() const { return [float2]([y],[x]); } 217 [float2] [yy]() const { return [float2]([y],[y]); } 218 219 220 221 222 223 224 225 [float4] [Swizzled](int i, int j, int k, int l) const;226 [float3] [Swizzled](int i, int j, int k) const;227 [float2] [Swizzled](int i, int j) const;228 229 230 231 static [float2] [FromScalar](float scalar);232 233 234 235 void [SetFromScalar](float scalar);236 237 238 239 void [Set](float [x], float [y]);240 241 242 243 244 245 246 247 248 void [SetFromPolarCoordinates](float theta, float length);249 void [SetFromPolarCoordinates](const [float2] &polar) { [SetFromPolarCoordinates](polar.[x], polar.[y]); }250 static [float2] [FromPolarCoordinates](float theta, float length);251 static [float2] [FromPolarCoordinates](const [float2] &polar) { return [FromPolarCoordinates](polar.[x], polar.[y]); }252 253 254 255 256 257 258 259 [float2] [ToPolarCoordinates]() const;260 261 262 263 264 265 266 267 268 float [AimedAngle]() const;269 270 271 272 273 float [Length]() const;274 275 276 277 278 279 280 281 282 float [LengthSq]() const;283 284 285 286 287 288 289 290 291 292 293 float [Normalize]();294 295 296 297 298 299 300 [float2] [Normalized]() const;301 302 303 304 305 306 307 308 309 310 311 float [ScaleToLength](float newLength);312 313 314 315 316 317 [float2] [ScaledToLength](float newLength) const;318 319 320 321 bool [IsNormalized](float epsilonSq = 1[e]-5f) const;322 323 324 325 bool [IsZero](float epsilonSq = 1[e]-6f) const;326 327 328 329 bool [IsFinite]() const;330 331 332 333 bool [IsPerpendicular](const [float2] &other, float epsilonSq = 1[e]-8f) const;334 335 336 337 bool [Equals](const [float2] &other, float [epsilon] = 1[e]-3f) const;338 bool [Equals](float [x], float [y], float [epsilon] = 1[e]-3f) const;339 340 341 342 bool [BitEquals](const [float2] &other) const;343 344 #ifdef MATH_ENABLE_STL_SUPPORT345 346 std::string [ToString]() const;347 348 349 std::string [SerializeToString]() const;350 351 352 std::string [SerializeToCodeString]() const;353 #endif354 355 356 static [float2] [FromString](const char *str, const char **outEndStr = 0);357 #ifdef MATH_ENABLE_STL_SUPPORT358 static [float2] [FromString](const std::string &str) { return [FromString](str.c_str()); }359 #endif360 361 362 float [SumOfElements]() const;363 364 float [ProductOfElements]() const;365 366 float [AverageOfElements]() const;367 368 369 float [MinElement]() const;370 371 372 int [MinElementIndex]() const;373 374 375 float [MaxElement]() const;376 377 378 int [MaxElementIndex]() const;379 380 381 382 [float2] [Abs]() const;383 384 385 386 387 [float2] [Neg]() const;388 389 390 391 [float2] [Recip]() const;392 393 394 [float2] [Min](float ceil) const;395 396 397 398 [float2] [Min](const [float2] &ceil) const;399 400 401 [float2] [Max](float floor) const;402 403 404 405 [float2] [Max](const [float2] &floor) const;406 407 [float2] [Clamp](float floor, float ceil) const;408 409 410 [float2] [Clamp](const [float2] &floor, const [float2] &ceil) const;411 412 413 [float2] [Clamp01]() const;414 415 416 417 float [Distance](const [float2] &point) const;418 419 420 421 422 423 424 425 float [DistanceSq](const [float2] &point) const;426 427 428 429 430 431 432 float [Dot](const [float2] &v) const;433 434 435 436 437 438 439 440 [float2] [Perp]() const;441 442 443 444 float [PerpDot](const [float2] &rhs) const;445 446 447 448 449 void [Rotate90CW]();450 451 452 453 454 [float2] [Rotated90CW]() const;455 456 457 458 459 void [Rotate90CCW]();460 461 462 463 [float2] [Rotated90CCW]() const;464 465 466 467 468 [float2] [Reflect](const [float2] &normal) const;469 470 471 472 473 474 475 476 477 478 [float2] [Refract](const [float2] &normal, float negativeSideRefractionIndex, float positiveSideRefractionIndex) const;479 480 481 482 483 484 [float2] [ProjectTo](const [float2] &direction) const;485 486 487 488 489 [float2] [ProjectToNorm](const [float2] &direction) const;490 491 492 493 494 495 float [AngleBetween](const [float2] &other) const;496 497 498 499 500 501 float [AngleBetweenNorm](const [float2] &normalizedVector) const;502 503 504 505 506 507 void [Decompose](const [float2] &direction, [float2] &outParallel, [float2] &outPerpendicular) const;508 509 510 511 512 513 514 515 [float2] [Lerp](const [float2] &b, float t) const;516 517 static [float2] [Lerp](const [float2] &a, const [float2] &b, float t);518 519 520 521 522 523 524 static void [Orthogonalize](const [float2] &a, [float2] &b);525 526 527 528 static bool [AreOrthogonal](const [float2] &a, const [float2] &b, float [epsilon] = 1[e]-3f);529 530 531 532 533 534 535 static void [Orthonormalize]([float2] &a, [float2] &b);536 537 538 539 540 541 542 static bool [OrientedCCW](const [float2] &a, const [float2] &b, const [float2] &c);543 544 #ifdef MATH_ENABLE_STL_SUPPORT545 546 547 static void [ConvexHull](const [float2] *pointArray, int numPoints, std::vector<float2> &outConvexHull);548 549 550 551 552 553 554 555 556 557 558 559 560 static int [ConvexHullInPlace]([float2] *pointArray, int numPoints);561 562 563 564 565 566 static bool [ConvexHullContains](const [float2] *convexHull, int numPointsInConvexHull, const [float2] &point);567 #endif568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 static float [MinAreaRectInPlace]([float2] *pointArray, int numPoints, [float2] ¢er, [float2] &uDir, [float2] &vDir, float &minU, float &maxU, float &minV, float &maxV);585 586 587 static [float2] [RandomDir]([LCG] &lcg, float length = 1.f);588 589 590 static [MUST_USE_RESULT] [float2] [RandomBox]([LCG] &lcg, float minElem, float maxElem);591 592 593 594 595 static const [float2] [zero];596 597 598 599 static const [float2] [one];600 601 602 603 static const [float2] [unitX];604 605 606 607 static const [float2] [unitY];608 609 610 611 612 613 614 static const [float2] [nan];615 616 617 618 static const [float2] [inf];619 620 #ifdef MATH_OGRE_INTEROP621 [float2](const Ogre::Vector2 &other):[x](other.[x]), [y](other.[y]) {}622 operator Ogre::Vector2() const { return Ogre::Vector2([x], [y]); }623 #endif624 #ifdef MATH_QT_INTEROP625 [float2](const QVector2D &other):[x](other.[x]()), [y](other.[y]()) {}626 operator QVector2D() const { return QVector2D([x], [y]); }627 operator QString() const { return "float2(" + QString::number([x]) + "," + QString::number([y]) + ")"; }628 QString toString() const { return (QString)*this; }629 QVector2D ToQVector2D() const { return QVector2D([x], [y]); }630 static [float2] FromQVector2D(const QVector2D &v) { return ([float2])v; }631 static [float2] [FromString](const QString &str) { return [FromString](str.toStdString()); }632 #endif633 #ifdef MATH_URHO3D_INTEROP634 [float2](const Urho3D::Vector2 &other) : [x](other.x_), [y](other.y_) {}635 operator Urho3D::Vector2() const { return Urho3D::Vector2([x], [y]); }636 #endif637 };638 639 #ifdef MATH_ENABLE_STL_SUPPORT640 641 std::ostream &[operator <<](std::ostream &out, const [float2] &rhs);642 #endif643 644 [float2] [operator *](float scalar, const [float2] &rhs);645 646 #ifdef MATH_ENABLE_UNCOMMON_OPERATIONS647 inline [float2] operator /(float scalar, const [float2] &rhs) { return [float2::FromScalar](scalar) / rhs; }648 #endif649 650 inline float [Dot](const [float2] &a, const [float2] &b) { return a.[Dot](b); }651 inline [float2] [Abs](const [float2] &a) { return a.[Abs](); }652 inline float [Length](const [float2] &a) { return a.[Length](); }653 inline float [Distance](const [float2] &a, const [float2] &b) { return a.[Distance](b); }654 inline [float2] [Min](const [float2] &a, const [float2] &b) { return a.[Min](b); }655 inline [float2] [Max](const [float2] &a, const [float2] &b) { return a.[Max](b); }656 inline [float2] [Clamp](const [float2] &a, float floor, float ceil) { return a.[Clamp](floor, ceil); }657 inline [float2] [Clamp](const [float2] &a, const [float2] &floor, const [float2] &ceil) { return a.[Clamp](floor, ceil); }658 inline [float2] [Clamp01](const [float2] &a) { return a.[Clamp01](); }659 inline [float2] [Lerp](const [float2] &a, const [float2] &b, float t) { return a.[Lerp](b, t); }660 661 #ifdef MATH_QT_INTEROP662 Q_DECLARE_METATYPE([float2])663 Q_DECLARE_METATYPE([float2]*)664 #endif665 666 [MATH_END_NAMESPACE] Go back to previous page