mPoint2.h
Classes:
class
2D high-precision point.
class
2D floating-point point.
class
2D integer point
Namespaces:
namespace
Public Functions
Detailed Description
Public Functions
mCross(const Point2F & p0, const Point2F & p1, const Point2F & pt2)
Return 0 if points are colinear Return positive if p0p1p2 are counter-clockwise Return negative if p0p1p2 are clockwise
mDot(const Point2F & p1, const Point2F & p2)
mDotPerp(const Point2F & p1, const Point2F & p2)
mIsNaN(const Point2F & p)
operator*(F32 mul, const Point2F & multiplicand)
operator*(F64 mul, const Point2D & multiplicand)
operator*(S32 mul, const Point2I & multiplicand)
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _MPOINT2_H_ 25#define _MPOINT2_H_ 26 27#ifndef _MMATHFN_H_ 28#include "math/mMathFn.h" 29#endif 30 31//------------------------------------------------------------------------------ 32/// 2D integer point 33/// 34/// Uses S32 internally. 35class Point2I 36{ 37 //-------------------------------------- Public data 38 public: 39 S32 x; ///< X position 40 S32 y; ///< Y position 41 42 //-------------------------------------- Public interface 43 public: 44 Point2I(); ///< Create an uninitialized point. 45 Point2I(const Point2I&); ///< Copy constructor 46 Point2I(S32 in_x, S32 in_y); ///< Create point from two co-ordinates. 47 48 //-------------------------------------- Non-math mutators and misc functions 49 void set(S32 in_x, S32 in_y); ///< Set (x,y) position 50 void setMin(const Point2I&); ///< Store lesser co-ordinates from parameter in this point. 51 void setMax(const Point2I&); ///< Store greater co-ordinates from parameter in this point. 52 void zero(); ///< Zero all values 53 54 //-------------------------------------- Math mutators 55 void neg(); ///< Invert sign of point's co-ordinates. 56 void convolve(const Point2I&); ///< Convolve this point by parameter. 57 58 //-------------------------------------- Queries 59 bool isZero() const; ///< Is this point at the origin? (No epsilon used) 60 F32 len() const; ///< Get the length of the point 61 S32 lenSquared() const; ///< Get the length-squared of the point 62 63 //-------------------------------------- Overloaded operators 64 public: 65 operator S32*() { return &x; } 66 operator const S32*() const { return &x; } 67 68 // Comparison operators 69 bool operator==(const Point2I&) const; 70 bool operator!=(const Point2I&) const; 71 72 // Arithmetic w/ other points 73 Point2I operator+(const Point2I&) const; 74 Point2I operator-(const Point2I&) const; 75 Point2I& operator+=(const Point2I&); 76 Point2I& operator-=(const Point2I&); 77 78 // Arithmetic w/ scalars 79 Point2I operator*(S32) const; 80 Point2I& operator*=(S32); 81 Point2I operator/(S32) const; 82 Point2I& operator/=(S32); 83 84 Point2I operator*(const Point2I&) const; 85 Point2I& operator*=(const Point2I&); 86 Point2I operator/(const Point2I&) const; 87 Point2I& operator/=(const Point2I&); 88 89 // Unary operators 90 Point2I operator-() const; 91 92 //-------------------------------------- Public static constants 93 public: 94 const static Point2I One; 95 const static Point2I Zero; 96 const static Point2I Min; 97 const static Point2I Max; 98}; 99 100//------------------------------------------------------------------------------ 101/// 2D floating-point point. 102class Point2F 103{ 104 //-------------------------------------- Public data 105 public: 106 F32 x; 107 F32 y; 108 109 public: 110 Point2F(); ///< Create uninitialized point. 111 Point2F(const Point2F&); ///< Copy constructor 112 Point2F(F32 _x, F32 _y); ///< Create point from co-ordinates. 113 114 //-------------------------------------- Non-math mutators and misc functions 115 public: 116 void set(F32 _x, F32 _y); ///< Set point's co-ordinates. 117 118 void setMin(const Point2F&); ///< Store lesser co-ordinates. 119 void setMax(const Point2F&); ///< Store greater co-ordinates. 120 121 /// Interpolate from a to b, based on c. 122 /// 123 /// @param a Starting point. 124 /// @param b Ending point. 125 /// @param c Interpolation factor (0.0 .. 1.0). 126 void interpolate(const Point2F& a, const Point2F& b, const F32 c); 127 128 void zero(); ///< Zero all values 129 130 operator F32*() { return &x; } 131 operator const F32*() const { return &x; } 132 133 //-------------------------------------- Queries 134 public: 135 bool isZero() const; ///< Check for zero coordinates. (No epsilon.) 136 F32 len() const; ///< Get length. 137 F32 lenSquared() const; ///< Get squared length (one sqrt less than len()). 138 bool equal( const Point2F &compare ) const; ///< Is compare within POINT_EPSILON of all of the component of this point 139 F32 magnitudeSafe() const; 140 141 //-------------------------------------- Mathematical mutators 142 public: 143 void neg(); ///< Invert signs of co-ordinates. 144 void normalize(); ///< Normalize vector. 145 void normalize(F32 val); ///< Normalize, scaling by val. 146 void normalizeSafe(); 147 void convolve(const Point2F&); ///< Convolve by parameter. 148 void convolveInverse(const Point2F&); ///< Inversely convolute by parameter. (ie, divide) 149 void rotate( F32 radians ); ///< Rotate vector around origin. 150 151 /// Return a perpendicular vector to this one. The result is equivalent to rotating the 152 /// vector 90 degrees clockwise around the origin. 153 Point2F getPerpendicular() const { return Point2F( y, - x ); } 154 155 //-------------------------------------- Overloaded operators 156 public: 157 // Comparison operators 158 bool operator==(const Point2F&) const; 159 bool operator!=(const Point2F&) const; 160 161 // Arithmetic w/ other points 162 Point2F operator+(const Point2F&) const; 163 Point2F operator-(const Point2F&) const; 164 Point2F& operator+=(const Point2F&); 165 Point2F& operator-=(const Point2F&); 166 167 // Arithmetic w/ scalars 168 Point2F operator*(F32) const; 169 Point2F operator/(F32) const; 170 Point2F& operator*=(F32); 171 Point2F& operator/=(F32); 172 173 Point2F operator*(const Point2F&) const; 174 Point2F& operator*=(const Point2F&); 175 Point2F operator/(const Point2F&) const; 176 Point2F& operator/=(const Point2F&); 177 178 // Unary operators 179 Point2F operator-() const; 180 181 //-------------------------------------- Public static constants 182 public: 183 const static Point2F One; 184 const static Point2F Zero; 185 const static Point2F Min; 186 const static Point2F Max; 187}; 188 189 190//------------------------------------------------------------------------------ 191/// 2D high-precision point. 192/// 193/// Uses F64 internally. 194class Point2D 195{ 196 //-------------------------------------- Public data 197 public: 198 F64 x; ///< X co-ordinate. 199 F64 y; ///< Y co-ordinate. 200 201 public: 202 Point2D(); ///< Create uninitialized point. 203 Point2D(const Point2D&); ///< Copy constructor 204 Point2D(F64 _x, F64 _y); ///< Create point from coordinates. 205 206 //-------------------------------------- Non-math mutators and misc functions 207 public: 208 void set(F64 _x, F64 _y); ///< Set point's coordinates. 209 210 void setMin(const Point2D&); ///< Store lesser co-ordinates. 211 void setMax(const Point2D&); ///< Store greater co-ordinates. 212 213 /// Interpolate from a to b, based on c. 214 /// 215 /// @param a Starting point. 216 /// @param b Ending point. 217 /// @param c Interpolation factor (0.0 .. 1.0). 218 void interpolate(const Point2D &a, const Point2D &b, const F64 c); 219 220 void zero(); ///< Zero all values 221 222 operator F64*() { return &x; } 223 operator const F64*() const { return &x; } 224 225 //-------------------------------------- Queries 226 public: 227 bool isZero() const; 228 F64 len() const; 229 F64 lenSquared() const; 230 231 //-------------------------------------- Mathematical mutators 232 public: 233 void neg(); 234 void normalize(); 235 void normalize(F64 val); 236 void convolve(const Point2D&); 237 void convolveInverse(const Point2D&); 238 239 //-------------------------------------- Overloaded operators 240 public: 241 // Comparison operators 242 bool operator==(const Point2D&) const; 243 bool operator!=(const Point2D&) const; 244 245 // Arithmetic w/ other points 246 Point2D operator+(const Point2D&) const; 247 Point2D operator-(const Point2D&) const; 248 Point2D& operator+=(const Point2D&); 249 Point2D& operator-=(const Point2D&); 250 251 // Arithmetic w/ scalars 252 Point2D operator*(F64) const; 253 Point2D operator/(F64) const; 254 Point2D& operator*=(F64); 255 Point2D& operator/=(F64); 256 257 // Unary operators 258 Point2D operator-() const; 259 260 //-------------------------------------- Public static constants 261 public: 262 const static Point2D One; 263 const static Point2D Zero; 264}; 265 266//------------------------------------------------------------------------------ 267//-------------------------------------- Point2I 268// 269inline Point2I::Point2I() 270 :x(0),y(0) 271{ 272} 273 274 275inline Point2I::Point2I(const Point2I& _copy) 276 : x(_copy.x), y(_copy.y) 277{ 278 // 279} 280 281 282inline Point2I::Point2I(S32 _x, S32 _y) 283 : x(_x), y(_y) 284{ 285 // 286} 287 288 289inline void Point2I::set(S32 _x, S32 _y) 290{ 291 x = _x; 292 y = _y; 293} 294 295 296inline void Point2I::setMin(const Point2I& _test) 297{ 298 x = (_test.x < x) ? _test.x : x; 299 y = (_test.y < y) ? _test.y : y; 300} 301 302 303inline void Point2I::setMax(const Point2I& _test) 304{ 305 x = (_test.x > x) ? _test.x : x; 306 y = (_test.y > y) ? _test.y : y; 307} 308 309 310inline void Point2I::zero() 311{ 312 x = y = 0; 313} 314 315 316inline void Point2I::neg() 317{ 318 x = -x; 319 y = -y; 320} 321 322inline void Point2I::convolve(const Point2I& c) 323{ 324 x *= c.x; 325 y *= c.y; 326} 327 328inline bool Point2I::isZero() const 329{ 330 return ((x == 0) && (y == 0)); 331} 332 333 334inline F32 Point2I::len() const 335{ 336 return mSqrt(F32(x*x + y*y)); 337} 338 339inline S32 Point2I::lenSquared() const 340{ 341 return x*x + y*y; 342} 343 344inline bool Point2I::operator==(const Point2I& _test) const 345{ 346 return ((x == _test.x) && (y == _test.y)); 347} 348 349 350inline bool Point2I::operator!=(const Point2I& _test) const 351{ 352 return (operator==(_test) == false); 353} 354 355 356inline Point2I Point2I::operator+(const Point2I& _add) const 357{ 358 return Point2I(x + _add.x, y + _add.y); 359} 360 361 362inline Point2I Point2I::operator-(const Point2I& _rSub) const 363{ 364 return Point2I(x - _rSub.x, y - _rSub.y); 365} 366 367 368inline Point2I& Point2I::operator+=(const Point2I& _add) 369{ 370 x += _add.x; 371 y += _add.y; 372 373 return *this; 374} 375 376 377inline Point2I& Point2I::operator-=(const Point2I& _rSub) 378{ 379 x -= _rSub.x; 380 y -= _rSub.y; 381 382 return *this; 383} 384 385 386inline Point2I Point2I::operator-() const 387{ 388 return Point2I(-x, -y); 389} 390 391 392inline Point2I Point2I::operator*(S32 mul) const 393{ 394 return Point2I(x * mul, y * mul); 395} 396 397inline Point2I Point2I::operator/(S32 div) const 398{ 399 AssertFatal(div != 0, "Error, div by zero attempted"); 400 return Point2I(x/div, y/div); 401} 402 403 404inline Point2I& Point2I::operator*=(S32 mul) 405{ 406 x *= mul; 407 y *= mul; 408 409 return *this; 410} 411 412 413inline Point2I& Point2I::operator/=(S32 div) 414{ 415 AssertFatal(div != 0, "Error, div by zero attempted"); 416 417 x /= div; 418 y /= div; 419 420 return *this; 421} 422 423inline Point2I Point2I::operator*(const Point2I &_vec) const 424{ 425 return Point2I(x * _vec.x, y * _vec.y); 426} 427 428inline Point2I& Point2I::operator*=(const Point2I &_vec) 429{ 430 x *= _vec.x; 431 y *= _vec.y; 432 return *this; 433} 434 435inline Point2I Point2I::operator/(const Point2I &_vec) const 436{ 437 return Point2I(x / _vec.x, y / _vec.y); 438} 439 440inline Point2I& Point2I::operator/=(const Point2I &_vec) 441{ 442 AssertFatal(_vec.x != 0 && _vec.y != 0, "Error, div by zero attempted"); 443 x /= _vec.x; 444 y /= _vec.y; 445 return *this; 446} 447 448//------------------------------------------------------------------------------ 449//-------------------------------------- Point2F 450// 451inline Point2F::Point2F() 452 :x(0.0f), y(0.0f) 453{ 454} 455 456 457inline Point2F::Point2F(const Point2F& _copy) 458 : x(_copy.x), y(_copy.y) 459{ 460 // 461} 462 463 464inline Point2F::Point2F(F32 _x, F32 _y) 465 : x(_x), y(_y) 466{ 467} 468 469 470inline void Point2F::set(F32 _x, F32 _y) 471{ 472 x = _x; 473 y = _y; 474} 475 476 477inline void Point2F::setMin(const Point2F& _test) 478{ 479 x = (_test.x < x) ? _test.x : x; 480 y = (_test.y < y) ? _test.y : y; 481} 482 483 484inline void Point2F::setMax(const Point2F& _test) 485{ 486 x = (_test.x > x) ? _test.x : x; 487 y = (_test.y > y) ? _test.y : y; 488} 489 490 491inline void Point2F::interpolate(const Point2F& _rFrom, const Point2F& _to, const F32 _factor) 492{ 493 AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor"); 494 x = (_rFrom.x * (1.0f - _factor)) + (_to.x * _factor); 495 y = (_rFrom.y * (1.0f - _factor)) + (_to.y * _factor); 496} 497 498 499inline void Point2F::zero() 500{ 501 x = y = 0.0f; 502} 503 504 505inline bool Point2F::isZero() const 506{ 507 return (x == 0.0f) && (y == 0.0f); 508} 509 510 511inline F32 Point2F::lenSquared() const 512{ 513 return (x * x) + (y * y); 514} 515 516 517inline bool Point2F::equal( const Point2F &compare ) const 518{ 519 return( ( mFabs( x - compare.x ) < POINT_EPSILON ) && 520 ( mFabs( y - compare.y ) < POINT_EPSILON ) ); 521} 522 523 524inline void Point2F::neg() 525{ 526 x = -x; 527 y = -y; 528} 529 530inline void Point2F::convolve(const Point2F& c) 531{ 532 x *= c.x; 533 y *= c.y; 534} 535 536 537inline void Point2F::convolveInverse(const Point2F& c) 538{ 539 x /= c.x; 540 y /= c.y; 541} 542 543inline void Point2F::rotate( F32 radians ) 544{ 545 F32 sinTheta, cosTheta; 546 mSinCos( radians, sinTheta, cosTheta ); 547 548 set( cosTheta * x - sinTheta * y, 549 sinTheta * x + cosTheta * y ); 550} 551 552inline bool Point2F::operator==(const Point2F& _test) const 553{ 554 return (x == _test.x) && (y == _test.y); 555} 556 557 558inline bool Point2F::operator!=(const Point2F& _test) const 559{ 560 return operator==(_test) == false; 561} 562 563 564inline Point2F Point2F::operator+(const Point2F& _add) const 565{ 566 return Point2F(x + _add.x, y + _add.y); 567} 568 569 570inline Point2F Point2F::operator-(const Point2F& _rSub) const 571{ 572 return Point2F(x - _rSub.x, y - _rSub.y); 573} 574 575 576inline Point2F& Point2F::operator+=(const Point2F& _add) 577{ 578 x += _add.x; 579 y += _add.y; 580 581 return *this; 582} 583 584 585inline Point2F& Point2F::operator-=(const Point2F& _rSub) 586{ 587 x -= _rSub.x; 588 y -= _rSub.y; 589 590 return *this; 591} 592 593 594inline Point2F Point2F::operator*(F32 _mul) const 595{ 596 return Point2F(x * _mul, y * _mul); 597} 598 599 600inline Point2F Point2F::operator/(F32 _div) const 601{ 602 AssertFatal(_div != 0.0f, "Error, div by zero attempted"); 603 604 F32 inv = 1.0f / _div; 605 606 return Point2F(x * inv, y * inv); 607} 608 609 610inline Point2F& Point2F::operator*=(F32 _mul) 611{ 612 x *= _mul; 613 y *= _mul; 614 615 return *this; 616} 617 618 619inline Point2F& Point2F::operator/=(F32 _div) 620{ 621 AssertFatal(_div != 0.0f, "Error, div by zero attempted"); 622 623 F32 inv = 1.0f / _div; 624 625 x *= inv; 626 y *= inv; 627 628 return *this; 629} 630 631inline Point2F Point2F::operator*(const Point2F &_vec) const 632{ 633 return Point2F(x * _vec.x, y * _vec.y); 634} 635 636inline Point2F& Point2F::operator*=(const Point2F &_vec) 637{ 638 x *= _vec.x; 639 y *= _vec.y; 640 return *this; 641} 642 643inline Point2F Point2F::operator/(const Point2F &_vec) const 644{ 645 return Point2F(x / _vec.x, y / _vec.y); 646} 647 648inline Point2F& Point2F::operator/=(const Point2F &_vec) 649{ 650 AssertFatal(_vec.x != 0 && _vec.y != 0, "Error, div by zero attempted"); 651 x /= _vec.x; 652 y /= _vec.y; 653 return *this; 654} 655 656inline Point2F Point2F::operator-() const 657{ 658 return Point2F(-x, -y); 659} 660 661inline F32 Point2F::len() const 662{ 663 return mSqrt(x*x + y*y); 664} 665 666inline void Point2F::normalize() 667{ 668 m_point2F_normalize(*this); 669} 670 671inline void Point2F::normalize(F32 val) 672{ 673 m_point2F_normalize_f(*this, val); 674} 675 676inline F32 Point2F::magnitudeSafe() const 677{ 678 if( isZero() ) 679 return 0.0f; 680 else 681 return len(); 682} 683 684inline void Point2F::normalizeSafe() 685{ 686 F32 vmag = magnitudeSafe(); 687 688 if( vmag > POINT_EPSILON ) 689 *this *= F32(1.0 / vmag); 690} 691 692//------------------------------------------------------------------------------ 693//-------------------------------------- Point2D 694// 695inline Point2D::Point2D() 696 :x(0.0), y(0.0) 697{ 698} 699 700 701inline Point2D::Point2D(const Point2D& _copy) 702 : x(_copy.x), y(_copy.y) 703{ 704 // 705} 706 707 708inline Point2D::Point2D(F64 _x, F64 _y) 709 : x(_x), y(_y) 710{ 711} 712 713 714inline void Point2D::set(F64 _x, F64 _y) 715{ 716 x = _x; 717 y = _y; 718} 719 720 721inline void Point2D::setMin(const Point2D& _test) 722{ 723 x = (_test.x < x) ? _test.x : x; 724 y = (_test.y < y) ? _test.y : y; 725} 726 727 728inline void Point2D::setMax(const Point2D& _test) 729{ 730 x = (_test.x > x) ? _test.x : x; 731 y = (_test.y > y) ? _test.y : y; 732} 733 734 735inline void Point2D::interpolate(const Point2D& _rFrom, const Point2D& _to, const F64 _factor) 736{ 737 AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor"); 738 x = (_rFrom.x * (1.0f - _factor)) + (_to.x * _factor); 739 y = (_rFrom.y * (1.0f - _factor)) + (_to.y * _factor); 740} 741 742 743inline void Point2D::zero() 744{ 745 x = y = 0.0; 746} 747 748 749inline bool Point2D::isZero() const 750{ 751 return (x == 0.0f) && (y == 0.0f); 752} 753 754 755inline F64 Point2D::lenSquared() const 756{ 757 return (x * x) + (y * y); 758} 759 760 761inline void Point2D::neg() 762{ 763 x = -x; 764 y = -y; 765} 766 767inline void Point2D::convolve(const Point2D& c) 768{ 769 x *= c.x; 770 y *= c.y; 771} 772 773inline void Point2D::convolveInverse(const Point2D& c) 774{ 775 x /= c.x; 776 y /= c.y; 777} 778 779inline bool Point2D::operator==(const Point2D& _test) const 780{ 781 return (x == _test.x) && (y == _test.y); 782} 783 784 785inline bool Point2D::operator!=(const Point2D& _test) const 786{ 787 return operator==(_test) == false; 788} 789 790 791inline Point2D Point2D::operator+(const Point2D& _add) const 792{ 793 return Point2D(x + _add.x, y + _add.y); 794} 795 796 797inline Point2D Point2D::operator-(const Point2D& _rSub) const 798{ 799 return Point2D(x - _rSub.x, y - _rSub.y); 800} 801 802 803inline Point2D& Point2D::operator+=(const Point2D& _add) 804{ 805 x += _add.x; 806 y += _add.y; 807 808 return *this; 809} 810 811 812inline Point2D& Point2D::operator-=(const Point2D& _rSub) 813{ 814 x -= _rSub.x; 815 y -= _rSub.y; 816 817 return *this; 818} 819 820 821inline Point2D Point2D::operator*(F64 _mul) const 822{ 823 return Point2D(x * _mul, y * _mul); 824} 825 826 827inline Point2D Point2D::operator/(F64 _div) const 828{ 829 AssertFatal(_div != 0.0f, "Error, div by zero attempted"); 830 831 F64 inv = 1.0f / _div; 832 833 return Point2D(x * inv, y * inv); 834} 835 836 837inline Point2D& Point2D::operator*=(F64 _mul) 838{ 839 x *= _mul; 840 y *= _mul; 841 842 return *this; 843} 844 845 846inline Point2D& Point2D::operator/=(F64 _div) 847{ 848 AssertFatal(_div != 0.0f, "Error, div by zero attempted"); 849 850 F64 inv = 1.0f / _div; 851 852 x *= inv; 853 y *= inv; 854 855 return *this; 856} 857 858 859inline Point2D Point2D::operator-() const 860{ 861 return Point2D(-x, -y); 862} 863 864inline F64 Point2D::len() const 865{ 866 return mSqrtD(x*x + y*y); 867} 868 869inline void Point2D::normalize() 870{ 871 m_point2D_normalize(*this); 872} 873 874inline void Point2D::normalize(F64 val) 875{ 876 m_point2D_normalize_f(*this, val); 877} 878 879 880//------------------------------------------------------------------- 881// Non-Member Operators 882//------------------------------------------------------------------- 883 884inline Point2I operator*(S32 mul, const Point2I& multiplicand) 885{ 886 return multiplicand * mul; 887} 888 889inline Point2F operator*(F32 mul, const Point2F& multiplicand) 890{ 891 return multiplicand * mul; 892} 893 894inline Point2D operator*(F64 mul, const Point2D& multiplicand) 895{ 896 return multiplicand * mul; 897} 898 899inline F32 mDot(const Point2F &p1, const Point2F &p2) 900{ 901 return (p1.x*p2.x + p1.y*p2.y); 902} 903 904inline F32 mDotPerp(const Point2F &p1, const Point2F &p2) 905{ 906 return p1.x*p2.y - p2.x*p1.y; 907} 908 909inline bool mIsNaN( const Point2F &p ) 910{ 911 return mIsNaN_F( p.x ) || mIsNaN_F( p.y ); 912} 913 914/// Return 0 if points are colinear 915/// Return positive if p0p1p2 are counter-clockwise 916/// Return negative if p0p1p2 are clockwise 917inline F64 mCross(const Point2F &p0, const Point2F &p1, const Point2F &pt2) 918{ 919 return (p1.x - p0.x) * (pt2.y - p0.y) - (p1.y - p0.y) * (pt2.x - p0.x); 920} 921 922 923namespace DictHash 924{ 925 /// Generates a 32bit hash from a Point2I. 926 /// @see DictHash 927 inline U32 hash( const Point2I &key ) 928 { 929 return (key.x * 2230148873u) ^ key.y; 930 } 931} 932 933#endif // _MPOINT2_H_ 934