| 1 | /* |
| 2 | --------------------------------------------------------------------------- |
| 3 | Open Asset Import Library (assimp) |
| 4 | --------------------------------------------------------------------------- |
| 5 | |
| 6 | Copyright (c) 2006-2019, assimp team |
| 7 | |
| 8 | |
| 9 | |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use of this software in source and binary forms, |
| 13 | with or without modification, are permitted provided that the following |
| 14 | conditions 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 | |
| 30 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 31 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 32 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 33 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 34 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 35 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 36 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 37 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 38 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 40 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 41 | --------------------------------------------------------------------------- |
| 42 | */ |
| 43 | |
| 44 | /** @file color4.inl |
| 45 | * @brief Inline implementation of aiColor4t<TReal> operators |
| 46 | */ |
| 47 | #pragma once |
| 48 | #ifndef AI_COLOR4D_INL_INC |
| 49 | #define AI_COLOR4D_INL_INC |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | #include "color4.h" |
| 53 | |
| 54 | // ------------------------------------------------------------------------------------------------ |
| 55 | template <typename TReal> |
| 56 | AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator += (const aiColor4t<TReal>& o) { |
| 57 | r += o.r; g += o.g; b += o.b; a += o.a; |
| 58 | return *this; |
| 59 | } |
| 60 | // ------------------------------------------------------------------------------------------------ |
| 61 | template <typename TReal> |
| 62 | AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator -= (const aiColor4t<TReal>& o) { |
| 63 | r -= o.r; g -= o.g; b -= o.b; a -= o.a; |
| 64 | return *this; |
| 65 | } |
| 66 | // ------------------------------------------------------------------------------------------------ |
| 67 | template <typename TReal> |
| 68 | AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) { |
| 69 | r *= f; g *= f; b *= f; a *= f; |
| 70 | return *this; |
| 71 | } |
| 72 | // ------------------------------------------------------------------------------------------------ |
| 73 | template <typename TReal> |
| 74 | AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) { |
| 75 | r /= f; g /= f; b /= f; a /= f; |
| 76 | return *this; |
| 77 | } |
| 78 | // ------------------------------------------------------------------------------------------------ |
| 79 | template <typename TReal> |
| 80 | AI_FORCE_INLINE TReal aiColor4t<TReal>::operator[](unsigned int i) const { |
| 81 | switch ( i ) { |
| 82 | case 0: |
| 83 | return r; |
| 84 | case 1: |
| 85 | return g; |
| 86 | case 2: |
| 87 | return b; |
| 88 | case 3: |
| 89 | return a; |
| 90 | default: |
| 91 | break; |
| 92 | } |
| 93 | return r; |
| 94 | } |
| 95 | // ------------------------------------------------------------------------------------------------ |
| 96 | template <typename TReal> |
| 97 | AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) { |
| 98 | switch ( i ) { |
| 99 | case 0: |
| 100 | return r; |
| 101 | case 1: |
| 102 | return g; |
| 103 | case 2: |
| 104 | return b; |
| 105 | case 3: |
| 106 | return a; |
| 107 | default: |
| 108 | break; |
| 109 | } |
| 110 | return r; |
| 111 | } |
| 112 | // ------------------------------------------------------------------------------------------------ |
| 113 | template <typename TReal> |
| 114 | AI_FORCE_INLINE bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const { |
| 115 | return r == other.r && g == other.g && b == other.b && a == other.a; |
| 116 | } |
| 117 | // ------------------------------------------------------------------------------------------------ |
| 118 | template <typename TReal> |
| 119 | AI_FORCE_INLINE bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other) const { |
| 120 | return r != other.r || g != other.g || b != other.b || a != other.a; |
| 121 | } |
| 122 | // ------------------------------------------------------------------------------------------------ |
| 123 | template <typename TReal> |
| 124 | AI_FORCE_INLINE bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const { |
| 125 | return r < other.r || ( |
| 126 | r == other.r && ( |
| 127 | g < other.g || ( |
| 128 | g == other.g && ( |
| 129 | b < other.b || ( |
| 130 | b == other.b && ( |
| 131 | a < other.a |
| 132 | ) |
| 133 | ) |
| 134 | ) |
| 135 | ) |
| 136 | ) |
| 137 | ); |
| 138 | } |
| 139 | // ------------------------------------------------------------------------------------------------ |
| 140 | template <typename TReal> |
| 141 | AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) { |
| 142 | return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a); |
| 143 | } |
| 144 | // ------------------------------------------------------------------------------------------------ |
| 145 | template <typename TReal> |
| 146 | AI_FORCE_INLINE aiColor4t<TReal> operator - (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) { |
| 147 | return aiColor4t<TReal>( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a); |
| 148 | } |
| 149 | // ------------------------------------------------------------------------------------------------ |
| 150 | template <typename TReal> |
| 151 | AI_FORCE_INLINE aiColor4t<TReal> operator * (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) { |
| 152 | return aiColor4t<TReal>( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a); |
| 153 | } |
| 154 | // ------------------------------------------------------------------------------------------------ |
| 155 | template <typename TReal> |
| 156 | AI_FORCE_INLINE aiColor4t<TReal> operator / (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) { |
| 157 | return aiColor4t<TReal>( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a); |
| 158 | } |
| 159 | // ------------------------------------------------------------------------------------------------ |
| 160 | template <typename TReal> |
| 161 | AI_FORCE_INLINE aiColor4t<TReal> operator * ( TReal f, const aiColor4t<TReal>& v) { |
| 162 | return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a); |
| 163 | } |
| 164 | // ------------------------------------------------------------------------------------------------ |
| 165 | template <typename TReal> |
| 166 | AI_FORCE_INLINE aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f) { |
| 167 | return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a); |
| 168 | } |
| 169 | // ------------------------------------------------------------------------------------------------ |
| 170 | template <typename TReal> |
| 171 | AI_FORCE_INLINE aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f) { |
| 172 | return v * (1/f); |
| 173 | } |
| 174 | // ------------------------------------------------------------------------------------------------ |
| 175 | template <typename TReal> |
| 176 | AI_FORCE_INLINE aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) { |
| 177 | return aiColor4t<TReal>(f,f,f,f)/v; |
| 178 | } |
| 179 | // ------------------------------------------------------------------------------------------------ |
| 180 | template <typename TReal> |
| 181 | AI_FORCE_INLINE aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f) { |
| 182 | return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a); |
| 183 | } |
| 184 | // ------------------------------------------------------------------------------------------------ |
| 185 | template <typename TReal> |
| 186 | AI_FORCE_INLINE aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f) { |
| 187 | return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f); |
| 188 | } |
| 189 | // ------------------------------------------------------------------------------------------------ |
| 190 | template <typename TReal> |
| 191 | AI_FORCE_INLINE aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v) { |
| 192 | return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a); |
| 193 | } |
| 194 | // ------------------------------------------------------------------------------------------------ |
| 195 | template <typename TReal> |
| 196 | AI_FORCE_INLINE aiColor4t<TReal> operator - ( TReal f, const aiColor4t<TReal>& v) { |
| 197 | return aiColor4t<TReal>( f-v.r, f-v.g, f-v.b, f-v.a); |
| 198 | } |
| 199 | |
| 200 | // ------------------------------------------------------------------------------------------------ |
| 201 | template <typename TReal> |
| 202 | inline bool aiColor4t<TReal> :: IsBlack() const { |
| 203 | // The alpha component doesn't care here. black is black. |
| 204 | static const TReal epsilon = 10e-3f; |
| 205 | return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon; |
| 206 | } |
| 207 | |
| 208 | #endif // __cplusplus |
| 209 | #endif // AI_VECTOR3D_INL_INC |
| 210 | |