Warning, /include/assimp/color4.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 color4.inl
0043 * @brief Inline implementation of aiColor4t<TReal> operators
0044 */
0045 #pragma once
0046 #ifndef AI_COLOR4D_INL_INC
0047 #define AI_COLOR4D_INL_INC
0048
0049 #ifdef __GNUC__
0050 # pragma GCC system_header
0051 #endif
0052
0053 #ifdef __cplusplus
0054 #include <assimp/color4.h>
0055
0056 // ------------------------------------------------------------------------------------------------
0057 template <typename TReal>
0058 AI_FORCE_INLINE
0059 const aiColor4t<TReal>& aiColor4t<TReal>::operator += (const aiColor4t<TReal>& o) {
0060 r += o.r;
0061 g += o.g;
0062 b += o.b;
0063 a += o.a;
0064
0065 return *this;
0066 }
0067 // ------------------------------------------------------------------------------------------------
0068 template <typename TReal>
0069 AI_FORCE_INLINE
0070 const aiColor4t<TReal>& aiColor4t<TReal>::operator -= (const aiColor4t<TReal>& o) {
0071 r -= o.r;
0072 g -= o.g;
0073 b -= o.b;
0074 a -= o.a;
0075
0076 return *this;
0077 }
0078 // ------------------------------------------------------------------------------------------------
0079 template <typename TReal>
0080 AI_FORCE_INLINE
0081 const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) {
0082 r *= f;
0083 g *= f;
0084 b *= f;
0085 a *= f;
0086
0087 return *this;
0088 }
0089 // ------------------------------------------------------------------------------------------------
0090 template <typename TReal>
0091 AI_FORCE_INLINE
0092 const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) {
0093 r /= f;
0094 g /= f;
0095 b /= f;
0096 a /= f;
0097
0098 return *this;
0099 }
0100 // ------------------------------------------------------------------------------------------------
0101 template <typename TReal>
0102 AI_FORCE_INLINE
0103 TReal aiColor4t<TReal>::operator[](unsigned int i) const {
0104 switch ( i ) {
0105 case 0:
0106 return r;
0107 case 1:
0108 return g;
0109 case 2:
0110 return b;
0111 case 3:
0112 return a;
0113 default:
0114 break;
0115 }
0116 return r;
0117 }
0118 // ------------------------------------------------------------------------------------------------
0119 template <typename TReal>
0120 AI_FORCE_INLINE
0121 TReal& aiColor4t<TReal>::operator[](unsigned int i) {
0122 switch ( i ) {
0123 case 0:
0124 return r;
0125 case 1:
0126 return g;
0127 case 2:
0128 return b;
0129 case 3:
0130 return a;
0131 default:
0132 break;
0133 }
0134 return r;
0135 }
0136 // ------------------------------------------------------------------------------------------------
0137 template <typename TReal>
0138 AI_FORCE_INLINE
0139 bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const {
0140 return r == other.r && g == other.g && b == other.b && a == other.a;
0141 }
0142 // ------------------------------------------------------------------------------------------------
0143 template <typename TReal>
0144 AI_FORCE_INLINE
0145 bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other) const {
0146 return r != other.r || g != other.g || b != other.b || a != other.a;
0147 }
0148 // ------------------------------------------------------------------------------------------------
0149 template <typename TReal>
0150 AI_FORCE_INLINE
0151 bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const {
0152 return r < other.r || (
0153 r == other.r && (
0154 g < other.g || (
0155 g == other.g && (
0156 b < other.b || (
0157 b == other.b && (
0158 a < other.a
0159 )
0160 )
0161 )
0162 )
0163 )
0164 );
0165 }
0166
0167 // ------------------------------------------------------------------------------------------------
0168 template <typename TReal>
0169 AI_FORCE_INLINE
0170 aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
0171 return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
0172 }
0173 // ------------------------------------------------------------------------------------------------
0174 template <typename TReal>
0175 AI_FORCE_INLINE
0176 aiColor4t<TReal> operator - (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
0177 return aiColor4t<TReal>( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a);
0178 }
0179 // ------------------------------------------------------------------------------------------------
0180 template <typename TReal>
0181 AI_FORCE_INLINE aiColor4t<TReal> operator * (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
0182 return aiColor4t<TReal>( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a);
0183 }
0184 // ------------------------------------------------------------------------------------------------
0185 template <typename TReal>
0186 AI_FORCE_INLINE
0187 aiColor4t<TReal> operator / (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
0188 return aiColor4t<TReal>( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a);
0189 }
0190 // ------------------------------------------------------------------------------------------------
0191 template <typename TReal>
0192 AI_FORCE_INLINE
0193 aiColor4t<TReal> operator * ( TReal f, const aiColor4t<TReal>& v) {
0194 return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
0195 }
0196 // ------------------------------------------------------------------------------------------------
0197 template <typename TReal>
0198 AI_FORCE_INLINE
0199 aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f) {
0200 return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
0201 }
0202 // ------------------------------------------------------------------------------------------------
0203 template <typename TReal>
0204 AI_FORCE_INLINE
0205 aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f) {
0206 return v * (1/f);
0207 }
0208 // ------------------------------------------------------------------------------------------------
0209 template <typename TReal>
0210 AI_FORCE_INLINE
0211 aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) {
0212 return aiColor4t<TReal>(f,f,f,f)/v;
0213 }
0214 // ------------------------------------------------------------------------------------------------
0215 template <typename TReal>
0216 AI_FORCE_INLINE
0217 aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f) {
0218 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
0219 }
0220 // ------------------------------------------------------------------------------------------------
0221 template <typename TReal>
0222 AI_FORCE_INLINE
0223 aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f) {
0224 return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f);
0225 }
0226 // ------------------------------------------------------------------------------------------------
0227 template <typename TReal>
0228 AI_FORCE_INLINE
0229 aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v) {
0230 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
0231 }
0232 // ------------------------------------------------------------------------------------------------
0233 template <typename TReal>
0234 AI_FORCE_INLINE
0235 aiColor4t<TReal> operator - ( TReal f, const aiColor4t<TReal>& v) {
0236 return aiColor4t<TReal>( f-v.r, f-v.g, f-v.b, f-v.a);
0237 }
0238
0239 // ------------------------------------------------------------------------------------------------
0240 template <typename TReal>
0241 AI_FORCE_INLINE
0242 bool aiColor4t<TReal>::IsBlack() const {
0243 // The alpha component doesn't care here. black is black.
0244 static const TReal epsilon = 10e-3f;
0245 return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
0246 }
0247
0248 #endif // __cplusplus
0249 #endif // AI_VECTOR3D_INL_INC