miniassimp

view include/miniassimp/vector2.inl @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
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:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
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.
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.
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 */
44 /** @file vector2.inl
45 * @brief Inline implementation of aiVector2t<TReal> operators
46 */
47 #pragma once
48 #ifndef AI_VECTOR2D_INL_INC
49 #define AI_VECTOR2D_INL_INC
51 #ifdef __cplusplus
52 #include "vector2.h"
54 #include <cmath>
56 // ------------------------------------------------------------------------------------------------
57 template <typename TReal>
58 template <typename TOther>
59 aiVector2t<TReal>::operator aiVector2t<TOther> () const {
60 return aiVector2t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y));
61 }
62 // ------------------------------------------------------------------------------------------------
63 template <typename TReal>
64 inline
65 void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
66 x = pX; y = pY;
67 }
69 // ------------------------------------------------------------------------------------------------
70 template <typename TReal>
71 inline
72 TReal aiVector2t<TReal>::SquareLength() const {
73 return x*x + y*y;
74 }
76 // ------------------------------------------------------------------------------------------------
77 template <typename TReal>
78 inline
79 TReal aiVector2t<TReal>::Length() const {
80 return std::sqrt( SquareLength());
81 }
83 // ------------------------------------------------------------------------------------------------
84 template <typename TReal>
85 inline
86 aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
87 *this /= Length();
88 return *this;
89 }
91 // ------------------------------------------------------------------------------------------------
92 template <typename TReal>
93 inline
94 const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
95 x += o.x; y += o.y;
96 return *this;
97 }
99 // ------------------------------------------------------------------------------------------------
100 template <typename TReal>
101 inline
102 const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
103 x -= o.x; y -= o.y;
104 return *this;
105 }
107 // ------------------------------------------------------------------------------------------------
108 template <typename TReal>
109 inline
110 const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
111 x *= f; y *= f;
112 return *this;
113 }
115 // ------------------------------------------------------------------------------------------------
116 template <typename TReal>
117 inline
118 const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
119 x /= f; y /= f;
120 return *this;
121 }
123 // ------------------------------------------------------------------------------------------------
124 template <typename TReal>
125 inline
126 TReal aiVector2t<TReal>::operator[](unsigned int i) const {
127 switch (i) {
128 case 0:
129 return x;
130 case 1:
131 return y;
132 default:
133 break;
135 }
136 return x;
137 }
139 // ------------------------------------------------------------------------------------------------
140 template <typename TReal>
141 inline
142 bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
143 return x == other.x && y == other.y;
144 }
146 // ------------------------------------------------------------------------------------------------
147 template <typename TReal>
148 inline
149 bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
150 return x != other.x || y != other.y;
151 }
153 // ---------------------------------------------------------------------------
154 template<typename TReal>
155 inline
156 bool aiVector2t<TReal>::Equal(const aiVector2t& other, TReal epsilon) const {
157 return
158 std::abs(x - other.x) <= epsilon &&
159 std::abs(y - other.y) <= epsilon;
160 }
162 // ------------------------------------------------------------------------------------------------
163 template <typename TReal>
164 inline
165 aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
166 x = y = f;
167 return *this;
168 }
170 // ------------------------------------------------------------------------------------------------
171 template <typename TReal>
172 inline
173 const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
174 return aiVector2t(x*o.x,y*o.y);
175 }
178 // ------------------------------------------------------------------------------------------------
179 // symmetric addition
180 template <typename TReal>
181 inline
182 aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
183 return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
184 }
186 // ------------------------------------------------------------------------------------------------
187 // symmetric subtraction
188 template <typename TReal>
189 inline
190 aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
191 return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
192 }
194 // ------------------------------------------------------------------------------------------------
195 // scalar product
196 template <typename TReal>
197 inline
198 TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
199 return v1.x*v2.x + v1.y*v2.y;
200 }
202 // ------------------------------------------------------------------------------------------------
203 // scalar multiplication
204 template <typename TReal>
205 inline
206 aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v) {
207 return aiVector2t<TReal>( f*v.x, f*v.y);
208 }
210 // ------------------------------------------------------------------------------------------------
211 // and the other way around
212 template <typename TReal>
213 inline
214 aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f) {
215 return aiVector2t<TReal>( f*v.x, f*v.y);
216 }
218 // ------------------------------------------------------------------------------------------------
219 // scalar division
220 template <typename TReal>
221 inline
222 aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f) {
223 return v * (1/f);
224 }
226 // ------------------------------------------------------------------------------------------------
227 // vector division
228 template <typename TReal>
229 inline
230 aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2) {
231 return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
232 }
234 // ------------------------------------------------------------------------------------------------
235 // vector negation
236 template <typename TReal>
237 inline
238 aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v) {
239 return aiVector2t<TReal>( -v.x, -v.y);
240 }
242 #endif
244 #endif // AI_VECTOR2D_INL_INC