1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2019, assimp team
7
8
9
10All rights reserved.
11
12Redistribution and use of this software in source and binary forms,
13with or without modification, are permitted provided that the following
14conditions 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
30THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40OF 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// ------------------------------------------------------------------------------------------------
55template <typename TReal>
56AI_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// ------------------------------------------------------------------------------------------------
61template <typename TReal>
62AI_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// ------------------------------------------------------------------------------------------------
67template <typename TReal>
68AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) {
69 r *= f; g *= f; b *= f; a *= f;
70 return *this;
71}
72// ------------------------------------------------------------------------------------------------
73template <typename TReal>
74AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) {
75 r /= f; g /= f; b /= f; a /= f;
76 return *this;
77}
78// ------------------------------------------------------------------------------------------------
79template <typename TReal>
80AI_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// ------------------------------------------------------------------------------------------------
96template <typename TReal>
97AI_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// ------------------------------------------------------------------------------------------------
113template <typename TReal>
114AI_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// ------------------------------------------------------------------------------------------------
118template <typename TReal>
119AI_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// ------------------------------------------------------------------------------------------------
123template <typename TReal>
124AI_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// ------------------------------------------------------------------------------------------------
140template <typename TReal>
141AI_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// ------------------------------------------------------------------------------------------------
145template <typename TReal>
146AI_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// ------------------------------------------------------------------------------------------------
150template <typename TReal>
151AI_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// ------------------------------------------------------------------------------------------------
155template <typename TReal>
156AI_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// ------------------------------------------------------------------------------------------------
160template <typename TReal>
161AI_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// ------------------------------------------------------------------------------------------------
165template <typename TReal>
166AI_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// ------------------------------------------------------------------------------------------------
170template <typename TReal>
171AI_FORCE_INLINE aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f) {
172 return v * (1/f);
173}
174// ------------------------------------------------------------------------------------------------
175template <typename TReal>
176AI_FORCE_INLINE aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) {
177 return aiColor4t<TReal>(f,f,f,f)/v;
178}
179// ------------------------------------------------------------------------------------------------
180template <typename TReal>
181AI_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// ------------------------------------------------------------------------------------------------
185template <typename TReal>
186AI_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// ------------------------------------------------------------------------------------------------
190template <typename TReal>
191AI_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// ------------------------------------------------------------------------------------------------
195template <typename TReal>
196AI_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// ------------------------------------------------------------------------------------------------
201template <typename TReal>
202inline 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

source code of qt3d/src/3rdparty/assimp/src/include/assimp/color4.inl