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