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