vrshoot

view libs/assimp/assimp/vector2.inl @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
42 /** @file aiVector2D.inl
43 * @brief Inline implementation of aiVector2t<TReal> operators
44 */
45 #ifndef AI_VECTOR2D_INL_INC
46 #define AI_VECTOR2D_INL_INC
48 #ifdef __cplusplus
49 #include "vector2.h"
51 // ------------------------------------------------------------------------------------------------
52 template <typename TReal>
53 template <typename TOther>
54 aiVector2t<TReal>::operator aiVector2t<TOther> () const {
55 return aiVector2t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y));
56 }
57 // ------------------------------------------------------------------------------------------------
58 template <typename TReal>
59 void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
60 x = pX; y = pY;
61 }
63 // ------------------------------------------------------------------------------------------------
64 template <typename TReal>
65 TReal aiVector2t<TReal>::SquareLength() const {
66 return x*x + y*y;
67 }
69 // ------------------------------------------------------------------------------------------------
70 template <typename TReal>
71 TReal aiVector2t<TReal>::Length() const {
72 return ::sqrt( SquareLength());
73 }
75 // ------------------------------------------------------------------------------------------------
76 template <typename TReal>
77 aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
78 *this /= Length();
79 return *this;
80 }
82 // ------------------------------------------------------------------------------------------------
83 template <typename TReal>
84 const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
85 x += o.x; y += o.y;
86 return *this;
87 }
89 // ------------------------------------------------------------------------------------------------
90 template <typename TReal>
91 const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
92 x -= o.x; y -= o.y;
93 return *this;
94 }
96 // ------------------------------------------------------------------------------------------------
97 template <typename TReal>
98 const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
99 x *= f; y *= f;
100 return *this;
101 }
103 // ------------------------------------------------------------------------------------------------
104 template <typename TReal>
105 const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
106 x /= f; y /= f;
107 return *this;
108 }
110 // ------------------------------------------------------------------------------------------------
111 template <typename TReal>
112 TReal aiVector2t<TReal>::operator[](unsigned int i) const {
113 return *(&x + i);
114 }
116 // ------------------------------------------------------------------------------------------------
117 template <typename TReal>
118 TReal& aiVector2t<TReal>::operator[](unsigned int i) {
119 return *(&x + i);
120 }
122 // ------------------------------------------------------------------------------------------------
123 template <typename TReal>
124 bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
125 return x == other.x && y == other.y;
126 }
128 // ------------------------------------------------------------------------------------------------
129 template <typename TReal>
130 bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
131 return x != other.x || y != other.y;
132 }
134 // ------------------------------------------------------------------------------------------------
135 template <typename TReal>
136 aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
137 x = y = f;
138 return *this;
139 }
141 // ------------------------------------------------------------------------------------------------
142 template <typename TReal>
143 const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
144 return aiVector2t(x*o.x,y*o.y);
145 }
148 // ------------------------------------------------------------------------------------------------
149 // symmetric addition
150 template <typename TReal>
151 inline aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
152 {
153 return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
154 }
156 // ------------------------------------------------------------------------------------------------
157 // symmetric subtraction
158 template <typename TReal>
159 inline aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
160 {
161 return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
162 }
164 // ------------------------------------------------------------------------------------------------
165 // scalar product
166 template <typename TReal>
167 inline TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
168 {
169 return v1.x*v2.x + v1.y*v2.y;
170 }
172 // ------------------------------------------------------------------------------------------------
173 // scalar multiplication
174 template <typename TReal>
175 inline aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v)
176 {
177 return aiVector2t<TReal>( f*v.x, f*v.y);
178 }
180 // ------------------------------------------------------------------------------------------------
181 // and the other way around
182 template <typename TReal>
183 inline aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f)
184 {
185 return aiVector2t<TReal>( f*v.x, f*v.y);
186 }
188 // ------------------------------------------------------------------------------------------------
189 // scalar division
190 template <typename TReal>
191 inline aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f)
192 {
194 return v * (1/f);
195 }
197 // ------------------------------------------------------------------------------------------------
198 // vector division
199 template <typename TReal>
200 inline aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2)
201 {
202 return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
203 }
205 // ------------------------------------------------------------------------------------------------
206 // vector negation
207 template <typename TReal>
208 inline aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v)
209 {
210 return aiVector2t<TReal>( -v.x, -v.y);
211 }
213 #endif
214 #endif