Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/assimp/vector3.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-2024, 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  vector3.inl
0043  *  @brief Inline implementation of aiVector3t<TReal> operators
0044  */
0045 #pragma once
0046 #ifndef AI_VECTOR3D_INL_INC
0047 #define AI_VECTOR3D_INL_INC
0048 
0049 #ifdef __cplusplus
0050 #include <assimp/vector3.h>
0051 
0052 #include <cmath>
0053 
0054 // ------------------------------------------------------------------------------------------------
0055 /** Transformation of a vector by a 3x3 matrix */
0056 template <typename TReal>
0057 AI_FORCE_INLINE aiVector3t<TReal> operator * (const aiMatrix3x3t<TReal>& pMatrix, const aiVector3t<TReal>& pVector) {
0058     aiVector3t<TReal> res;
0059     res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z;
0060     res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z;
0061     res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z;
0062     return res;
0063 }
0064 
0065 // ------------------------------------------------------------------------------------------------
0066 /** Transformation of a vector by a 4x4 matrix */
0067 template <typename TReal>
0068 AI_FORCE_INLINE aiVector3t<TReal> operator * (const aiMatrix4x4t<TReal>& pMatrix, const aiVector3t<TReal>& pVector) {
0069     aiVector3t<TReal> res;
0070     res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z + pMatrix.a4;
0071     res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z + pMatrix.b4;
0072     res.z = pMatrix.c1 * pVector.x + pMatrix.c2 * pVector.y + pMatrix.c3 * pVector.z + pMatrix.c4;
0073     return res;
0074 }
0075 // ------------------------------------------------------------------------------------------------
0076 template <typename TReal>
0077 template <typename TOther>
0078 aiVector3t<TReal>::operator aiVector3t<TOther> () const {
0079     return aiVector3t<TOther>(static_cast<TOther>(x),static_cast<TOther>(y),static_cast<TOther>(z));
0080 }
0081 // ------------------------------------------------------------------------------------------------
0082 template <typename TReal>
0083 AI_FORCE_INLINE void aiVector3t<TReal>::Set( TReal pX, TReal pY, TReal pZ) {
0084     x = pX;
0085     y = pY;
0086     z = pZ;
0087 }
0088 // ------------------------------------------------------------------------------------------------
0089 template <typename TReal>
0090 AI_FORCE_INLINE TReal aiVector3t<TReal>::SquareLength() const {
0091     return x*x + y*y + z*z;
0092 }
0093 // ------------------------------------------------------------------------------------------------
0094 template <typename TReal>
0095 AI_FORCE_INLINE TReal aiVector3t<TReal>::Length() const {
0096     return std::sqrt( SquareLength());
0097 }
0098 // ------------------------------------------------------------------------------------------------
0099 template <typename TReal>
0100  aiVector3t<TReal>& aiVector3t<TReal>::Normalize() {
0101     const TReal l = Length();
0102     if (l == 0) {
0103         return *this;
0104     }
0105     *this /= Length();
0106 
0107     return *this;
0108 }
0109 // ------------------------------------------------------------------------------------------------
0110 template <typename TReal>
0111 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::NormalizeSafe() {
0112     TReal len = Length();
0113     if ( len > static_cast< TReal >( 0 ) ) {
0114         *this /= len;
0115     }
0116     return *this;
0117 }
0118 // ------------------------------------------------------------------------------------------------
0119 template <typename TReal>
0120 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator += (const aiVector3t<TReal>& o) {
0121     x += o.x;
0122     y += o.y;
0123     z += o.z;
0124 
0125     return *this;
0126 }
0127 // ------------------------------------------------------------------------------------------------
0128 template <typename TReal>
0129 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator -= (const aiVector3t<TReal>& o) {
0130     x -= o.x;
0131     y -= o.y;
0132     z -= o.z;
0133 
0134     return *this;
0135 }
0136 // ------------------------------------------------------------------------------------------------
0137 template <typename TReal>
0138 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator *= (TReal f) {
0139     x *= f;
0140     y *= f;
0141     z *= f;
0142 
0143     return *this;
0144 }
0145 // ------------------------------------------------------------------------------------------------
0146 template <typename TReal>
0147 AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator /= (TReal f) {
0148     if ( f == static_cast<TReal>(0.0)) {
0149         return *this;
0150     }
0151     const TReal invF = (TReal) 1.0 / f;
0152     x *= invF;
0153     y *= invF;
0154     z *= invF;
0155 
0156     return *this;
0157 }
0158 // ------------------------------------------------------------------------------------------------
0159 template <typename TReal>
0160 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix3x3t<TReal>& mat){
0161     return (*this =  mat * (*this));
0162 }
0163 // ------------------------------------------------------------------------------------------------
0164 template <typename TReal>
0165 AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::operator *= (const aiMatrix4x4t<TReal>& mat){
0166     return (*this = mat * (*this));
0167 }
0168 // ------------------------------------------------------------------------------------------------
0169 template <typename TReal>
0170 AI_FORCE_INLINE TReal aiVector3t<TReal>::operator[](unsigned int i) const {
0171     switch (i) {
0172         case 0:
0173             return x;
0174         case 1:
0175             return y;
0176         case 2:
0177             return z;
0178         default:
0179             break;
0180     }
0181     return x;
0182 }
0183 // ------------------------------------------------------------------------------------------------
0184 template <typename TReal>
0185 AI_FORCE_INLINE TReal& aiVector3t<TReal>::operator[](unsigned int i) {
0186     switch (i) {
0187         case 0:
0188             return x;
0189         case 1:
0190             return y;
0191         case 2:
0192             return z;
0193         default:
0194             break;
0195     }
0196     return x;
0197 }
0198 // ------------------------------------------------------------------------------------------------
0199 template <typename TReal>
0200 AI_FORCE_INLINE bool aiVector3t<TReal>::operator== (const aiVector3t<TReal>& other) const {
0201     return x == other.x && y == other.y && z == other.z;
0202 }
0203 // ------------------------------------------------------------------------------------------------
0204 template <typename TReal>
0205 AI_FORCE_INLINE bool aiVector3t<TReal>::operator!= (const aiVector3t<TReal>& other) const {
0206     return x != other.x || y != other.y || z != other.z;
0207 }
0208 // ---------------------------------------------------------------------------
0209 template<typename TReal>
0210 AI_FORCE_INLINE bool aiVector3t<TReal>::Equal(const aiVector3t<TReal>& other, TReal epsilon) const {
0211     return
0212         std::abs(x - other.x) <= epsilon &&
0213         std::abs(y - other.y) <= epsilon &&
0214         std::abs(z - other.z) <= epsilon;
0215 }
0216 // ------------------------------------------------------------------------------------------------
0217 template <typename TReal>
0218 AI_FORCE_INLINE bool aiVector3t<TReal>::operator < (const aiVector3t<TReal>& other) const {
0219     return x != other.x ? x < other.x : y != other.y ? y < other.y : z < other.z;
0220 }
0221 // ------------------------------------------------------------------------------------------------
0222 template <typename TReal>
0223 AI_FORCE_INLINE const aiVector3t<TReal> aiVector3t<TReal>::SymMul(const aiVector3t<TReal>& o) {
0224     return aiVector3t<TReal>(x*o.x,y*o.y,z*o.z);
0225 }
0226 // ------------------------------------------------------------------------------------------------
0227 // symmetric addition
0228 template <typename TReal>
0229 AI_FORCE_INLINE aiVector3t<TReal> operator + (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
0230     return aiVector3t<TReal>( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
0231 }
0232 // ------------------------------------------------------------------------------------------------
0233 // symmetric subtraction
0234 template <typename TReal>
0235 AI_FORCE_INLINE aiVector3t<TReal> operator - (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
0236     return aiVector3t<TReal>( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
0237 }
0238 // ------------------------------------------------------------------------------------------------
0239 // scalar product
0240 template <typename TReal>
0241 AI_FORCE_INLINE TReal operator * (const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
0242     return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
0243 }
0244 // ------------------------------------------------------------------------------------------------
0245 // scalar multiplication
0246 template <typename TReal>
0247 AI_FORCE_INLINE aiVector3t<TReal> operator * ( TReal f, const aiVector3t<TReal>& v) {
0248     return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
0249 }
0250 // ------------------------------------------------------------------------------------------------
0251 // and the other way around
0252 template <typename TReal>
0253 AI_FORCE_INLINE aiVector3t<TReal> operator * ( const aiVector3t<TReal>& v, TReal f) {
0254     return aiVector3t<TReal>( f*v.x, f*v.y, f*v.z);
0255 }
0256 // ------------------------------------------------------------------------------------------------
0257 // scalar division
0258 template <typename TReal>
0259 AI_FORCE_INLINE aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, TReal f) {
0260     return v * (1/f);
0261 }
0262 // ------------------------------------------------------------------------------------------------
0263 // vector division
0264 template <typename TReal>
0265 AI_FORCE_INLINE aiVector3t<TReal> operator / ( const aiVector3t<TReal>& v, const aiVector3t<TReal>& v2) {
0266     return aiVector3t<TReal>(v.x / v2.x,v.y / v2.y,v.z / v2.z);
0267 }
0268 // ------------------------------------------------------------------------------------------------
0269 // cross product
0270 template<typename TReal>
0271 AI_FORCE_INLINE aiVector3t<TReal> operator ^ ( const aiVector3t<TReal>& v1, const aiVector3t<TReal>& v2) {
0272     return aiVector3t<TReal>( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
0273 }
0274 // ------------------------------------------------------------------------------------------------
0275 // vector negation
0276 template<typename TReal>
0277 AI_FORCE_INLINE aiVector3t<TReal> operator - ( const aiVector3t<TReal>& v) {
0278     return aiVector3t<TReal>( -v.x, -v.y, -v.z);
0279 }
0280 
0281 // ------------------------------------------------------------------------------------------------
0282 
0283 #endif // __cplusplus
0284 #endif // AI_VECTOR3D_INL_INC