1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2019, assimp team
7
8
9
10All rights reserved.
11
12Redistribution and use of this software in source and binary forms,
13with or without modification, are permitted provided that the following
14conditions 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
30THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41---------------------------------------------------------------------------
42*/
43
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
50
51#ifdef __cplusplus
52#include "vector2.h"
53
54#include <cmath>
55
56// ------------------------------------------------------------------------------------------------
57template <typename TReal>
58template <typename TOther>
59aiVector2t<TReal>::operator aiVector2t<TOther> () const {
60 return aiVector2t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y));
61}
62// ------------------------------------------------------------------------------------------------
63template <typename TReal>
64inline
65void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
66 x = pX; y = pY;
67}
68
69// ------------------------------------------------------------------------------------------------
70template <typename TReal>
71inline
72TReal aiVector2t<TReal>::SquareLength() const {
73 return x*x + y*y;
74}
75
76// ------------------------------------------------------------------------------------------------
77template <typename TReal>
78inline
79TReal aiVector2t<TReal>::Length() const {
80 return std::sqrt( SquareLength());
81}
82
83// ------------------------------------------------------------------------------------------------
84template <typename TReal>
85inline
86aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
87 *this /= Length();
88 return *this;
89}
90
91// ------------------------------------------------------------------------------------------------
92template <typename TReal>
93inline
94const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
95 x += o.x; y += o.y;
96 return *this;
97}
98
99// ------------------------------------------------------------------------------------------------
100template <typename TReal>
101inline
102const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
103 x -= o.x; y -= o.y;
104 return *this;
105}
106
107// ------------------------------------------------------------------------------------------------
108template <typename TReal>
109inline
110const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
111 x *= f; y *= f;
112 return *this;
113}
114
115// ------------------------------------------------------------------------------------------------
116template <typename TReal>
117inline
118const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
119 x /= f; y /= f;
120 return *this;
121}
122
123// ------------------------------------------------------------------------------------------------
124template <typename TReal>
125inline
126TReal 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;
134
135 }
136 return x;
137}
138
139// ------------------------------------------------------------------------------------------------
140template <typename TReal>
141inline
142bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
143 return x == other.x && y == other.y;
144}
145
146// ------------------------------------------------------------------------------------------------
147template <typename TReal>
148inline
149bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
150 return x != other.x || y != other.y;
151}
152
153// ---------------------------------------------------------------------------
154template<typename TReal>
155inline
156bool 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}
161
162// ------------------------------------------------------------------------------------------------
163template <typename TReal>
164inline
165aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
166 x = y = f;
167 return *this;
168}
169
170// ------------------------------------------------------------------------------------------------
171template <typename TReal>
172inline
173const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
174 return aiVector2t(x*o.x,y*o.y);
175}
176
177
178// ------------------------------------------------------------------------------------------------
179// symmetric addition
180template <typename TReal>
181inline
182aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
183 return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
184}
185
186// ------------------------------------------------------------------------------------------------
187// symmetric subtraction
188template <typename TReal>
189inline
190aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
191 return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
192}
193
194// ------------------------------------------------------------------------------------------------
195// scalar product
196template <typename TReal>
197inline
198TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
199 return v1.x*v2.x + v1.y*v2.y;
200}
201
202// ------------------------------------------------------------------------------------------------
203// scalar multiplication
204template <typename TReal>
205inline
206aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v) {
207 return aiVector2t<TReal>( f*v.x, f*v.y);
208}
209
210// ------------------------------------------------------------------------------------------------
211// and the other way around
212template <typename TReal>
213inline
214aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f) {
215 return aiVector2t<TReal>( f*v.x, f*v.y);
216}
217
218// ------------------------------------------------------------------------------------------------
219// scalar division
220template <typename TReal>
221inline
222aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f) {
223 return v * (1/f);
224}
225
226// ------------------------------------------------------------------------------------------------
227// vector division
228template <typename TReal>
229inline
230aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2) {
231 return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
232}
233
234// ------------------------------------------------------------------------------------------------
235// vector negation
236template <typename TReal>
237inline
238aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v) {
239 return aiVector2t<TReal>( -v.x, -v.y);
240}
241
242#endif
243
244#endif // AI_VECTOR2D_INL_INC
245

source code of qt3d/src/3rdparty/assimp/src/include/assimp/vector2.inl