Warning, /include/assimp/vector2.inl is written in an unsupported language. File is not indexed.
0001 /*
0002 ---------------------------------------------------------------------------
0003 Open Asset Import Library (assimp)
0004 ---------------------------------------------------------------------------
0005
0006 Copyright (c) 2006-2025, assimp team
0007
0008 All rights reserved.
0009
0010 Redistribution and use of this software in source and binary forms,
0011 with or without modification, are permitted provided that the following
0012 conditions are met:
0013
0014 * Redistributions of source code must retain the above
0015 copyright notice, this list of conditions and the
0016 following disclaimer.
0017
0018 * Redistributions in binary form must reproduce the above
0019 copyright notice, this list of conditions and the
0020 following disclaimer in the documentation and/or other
0021 materials provided with the distribution.
0022
0023 * Neither the name of the assimp team, nor the names of its
0024 contributors may be used to endorse or promote products
0025 derived from this software without specific prior
0026 written permission of the assimp team.
0027
0028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0032 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0039 ---------------------------------------------------------------------------
0040 */
0041
0042 /** @file vector2.inl
0043 * @brief Inline implementation of aiVector2t<TReal> operators
0044 */
0045 #pragma once
0046 #ifndef AI_VECTOR2D_INL_INC
0047 #define AI_VECTOR2D_INL_INC
0048
0049 #ifdef __GNUC__
0050 # pragma GCC system_header
0051 #endif
0052
0053 #ifdef __cplusplus
0054 #include <assimp/vector2.h>
0055
0056 #include <cmath>
0057
0058 // ------------------------------------------------------------------------------------------------
0059 template <typename TReal>
0060 template <typename TOther>
0061 aiVector2t<TReal>::operator aiVector2t<TOther> () const {
0062 return aiVector2t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y));
0063 }
0064 // ------------------------------------------------------------------------------------------------
0065 template <typename TReal>
0066 inline
0067 void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
0068 x = pX; y = pY;
0069 }
0070
0071 // ------------------------------------------------------------------------------------------------
0072 template <typename TReal>
0073 inline
0074 TReal aiVector2t<TReal>::SquareLength() const {
0075 return x*x + y*y;
0076 }
0077
0078 // ------------------------------------------------------------------------------------------------
0079 template <typename TReal>
0080 inline
0081 TReal aiVector2t<TReal>::Length() const {
0082 return std::sqrt( SquareLength());
0083 }
0084
0085 // ------------------------------------------------------------------------------------------------
0086 template <typename TReal>
0087 inline
0088 aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
0089 *this /= Length();
0090 return *this;
0091 }
0092
0093 // ------------------------------------------------------------------------------------------------
0094 template <typename TReal>
0095 inline
0096 const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
0097 x += o.x; y += o.y;
0098 return *this;
0099 }
0100
0101 // ------------------------------------------------------------------------------------------------
0102 template <typename TReal>
0103 inline
0104 const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
0105 x -= o.x; y -= o.y;
0106 return *this;
0107 }
0108
0109 // ------------------------------------------------------------------------------------------------
0110 template <typename TReal>
0111 inline
0112 const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
0113 x *= f; y *= f;
0114 return *this;
0115 }
0116
0117 // ------------------------------------------------------------------------------------------------
0118 template <typename TReal>
0119 inline
0120 const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
0121 x /= f; y /= f;
0122 return *this;
0123 }
0124
0125 // ------------------------------------------------------------------------------------------------
0126 template <typename TReal>
0127 inline
0128 TReal aiVector2t<TReal>::operator[](unsigned int i) const {
0129 switch (i) {
0130 case 0:
0131 return x;
0132 case 1:
0133 return y;
0134 default:
0135 break;
0136
0137 }
0138 return x;
0139 }
0140
0141 // ------------------------------------------------------------------------------------------------
0142 template <typename TReal>
0143 inline
0144 bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
0145 return x == other.x && y == other.y;
0146 }
0147
0148 // ------------------------------------------------------------------------------------------------
0149 template <typename TReal>
0150 inline
0151 bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
0152 return x != other.x || y != other.y;
0153 }
0154
0155 // ---------------------------------------------------------------------------
0156 template<typename TReal>
0157 inline
0158 bool aiVector2t<TReal>::Equal(const aiVector2t& other, TReal epsilon) const {
0159 return
0160 std::abs(x - other.x) <= epsilon &&
0161 std::abs(y - other.y) <= epsilon;
0162 }
0163
0164 // ------------------------------------------------------------------------------------------------
0165 template <typename TReal>
0166 inline
0167 aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
0168 x = y = f;
0169 return *this;
0170 }
0171
0172 // ------------------------------------------------------------------------------------------------
0173 template <typename TReal>
0174 inline
0175 const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
0176 return aiVector2t(x*o.x,y*o.y);
0177 }
0178
0179
0180 // ------------------------------------------------------------------------------------------------
0181 // symmetric addition
0182 template <typename TReal>
0183 inline
0184 aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
0185 return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
0186 }
0187
0188 // ------------------------------------------------------------------------------------------------
0189 // symmetric subtraction
0190 template <typename TReal>
0191 inline
0192 aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
0193 return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
0194 }
0195
0196 // ------------------------------------------------------------------------------------------------
0197 // scalar product
0198 template <typename TReal>
0199 inline
0200 TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
0201 return v1.x*v2.x + v1.y*v2.y;
0202 }
0203
0204 // ------------------------------------------------------------------------------------------------
0205 // scalar multiplication
0206 template <typename TReal>
0207 inline
0208 aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v) {
0209 return aiVector2t<TReal>( f*v.x, f*v.y);
0210 }
0211
0212 // ------------------------------------------------------------------------------------------------
0213 // and the other way around
0214 template <typename TReal>
0215 inline
0216 aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f) {
0217 return aiVector2t<TReal>( f*v.x, f*v.y);
0218 }
0219
0220 // ------------------------------------------------------------------------------------------------
0221 // scalar division
0222 template <typename TReal>
0223 inline
0224 aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f) {
0225 return v * (1/f);
0226 }
0227
0228 // ------------------------------------------------------------------------------------------------
0229 // vector division
0230 template <typename TReal>
0231 inline
0232 aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2) {
0233 return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
0234 }
0235
0236 // ------------------------------------------------------------------------------------------------
0237 // vector negation
0238 template <typename TReal>
0239 inline
0240 aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v) {
0241 return aiVector2t<TReal>( -v.x, -v.y);
0242 }
0243
0244 #endif
0245
0246 #endif // AI_VECTOR2D_INL_INC