vector2.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file aiVector2t.h
  35. * @brief 2D vector structure, including operators when compiling in C++
  36. */
  37. #ifndef AI_VECTOR2D_H_INC
  38. #define AI_VECTOR2D_H_INC
  39. #ifdef __cplusplus
  40. # include <cmath>
  41. #else
  42. # include <math.h>
  43. #endif
  44. #include "./Compiler/pushpack1.h"
  45. // ----------------------------------------------------------------------------------
  46. /** Represents a two-dimensional vector.
  47. */
  48. #ifdef __cplusplus
  49. template <typename TReal>
  50. class aiVector2t
  51. {
  52. public:
  53. aiVector2t () : x(), y() {}
  54. aiVector2t (TReal _x, TReal _y) : x(_x), y(_y) {}
  55. explicit aiVector2t (TReal _xyz) : x(_xyz), y(_xyz) {}
  56. aiVector2t (const aiVector2t& o) : x(o.x), y(o.y) {}
  57. public:
  58. void Set( TReal pX, TReal pY);
  59. TReal SquareLength() const ;
  60. TReal Length() const ;
  61. aiVector2t& Normalize();
  62. public:
  63. const aiVector2t& operator += (const aiVector2t& o);
  64. const aiVector2t& operator -= (const aiVector2t& o);
  65. const aiVector2t& operator *= (TReal f);
  66. const aiVector2t& operator /= (TReal f);
  67. TReal operator[](unsigned int i) const;
  68. TReal& operator[](unsigned int i);
  69. bool operator== (const aiVector2t& other) const;
  70. bool operator!= (const aiVector2t& other) const;
  71. bool Equal(const aiVector2t& other, TReal epsilon = 1e-6) const;
  72. aiVector2t& operator= (TReal f);
  73. const aiVector2t SymMul(const aiVector2t& o);
  74. template <typename TOther>
  75. operator aiVector2t<TOther> () const;
  76. TReal x, y;
  77. } PACK_STRUCT;
  78. typedef aiVector2t<float> aiVector2D;
  79. #else
  80. struct aiVector2D {
  81. float x,y;
  82. };
  83. #endif // __cplusplus
  84. #include "./Compiler/poppack1.h"
  85. #endif // AI_VECTOR2D_H_INC