1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2017, assimp team
7
8
9All rights reserved.
10
11Redistribution and use of this software in source and binary forms,
12with or without modification, are permitted provided that the following
13conditions are met:
14
15* Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18
19* Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23
24* Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40---------------------------------------------------------------------------
41*/
42
43/** @file color4.inl
44 * @brief Inline implementation of aiColor4t<TReal> operators
45 */
46#pragma once
47#ifndef AI_COLOR4D_INL_INC
48#define AI_COLOR4D_INL_INC
49
50#ifdef __cplusplus
51#include "color4.h"
52
53// ------------------------------------------------------------------------------------------------
54template <typename TReal>
55AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator += (const aiColor4t<TReal>& o) {
56 r += o.r; g += o.g; b += o.b; a += o.a;
57 return *this;
58}
59// ------------------------------------------------------------------------------------------------
60template <typename TReal>
61AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator -= (const aiColor4t<TReal>& o) {
62 r -= o.r; g -= o.g; b -= o.b; a -= o.a;
63 return *this;
64}
65// ------------------------------------------------------------------------------------------------
66template <typename TReal>
67AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) {
68 r *= f; g *= f; b *= f; a *= f;
69 return *this;
70}
71// ------------------------------------------------------------------------------------------------
72template <typename TReal>
73AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) {
74 r /= f; g /= f; b /= f; a /= f;
75 return *this;
76}
77// ------------------------------------------------------------------------------------------------
78template <typename TReal>
79AI_FORCE_INLINE TReal aiColor4t<TReal>::operator[](unsigned int i) const {
80 switch ( i ) {
81 case 0:
82 return r;
83 case 1:
84 return g;
85 case 2:
86 return b;
87 default:
88 break;
89 }
90 return r;
91}
92// ------------------------------------------------------------------------------------------------
93template <typename TReal>
94AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) {
95 switch ( i ) {
96 case 0:
97 return r;
98 case 1:
99 return g;
100 case 2:
101 return b;
102 default:
103 break;
104 }
105 return r;
106}
107// ------------------------------------------------------------------------------------------------
108template <typename TReal>
109AI_FORCE_INLINE bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const {
110 return r == other.r && g == other.g && b == other.b && a == other.a;
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 || (
121 r == other.r && (
122 g < other.g || (
123 g == other.g && (
124 b < other.b || (
125 b == other.b && (
126 a < other.a
127 )
128 )
129 )
130 )
131 )
132 );
133}
134// ------------------------------------------------------------------------------------------------
135template <typename TReal>
136AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
137 return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
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 * ( TReal f, const aiColor4t<TReal>& v) {
157 return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
158}
159// ------------------------------------------------------------------------------------------------
160template <typename TReal>
161AI_FORCE_INLINE aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f) {
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 v * (1/f);
168}
169// ------------------------------------------------------------------------------------------------
170template <typename TReal>
171AI_FORCE_INLINE aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) {
172 return aiColor4t<TReal>(f,f,f,f)/v;
173}
174// ------------------------------------------------------------------------------------------------
175template <typename TReal>
176AI_FORCE_INLINE aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f) {
177 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
178}
179// ------------------------------------------------------------------------------------------------
180template <typename TReal>
181AI_FORCE_INLINE aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f) {
182 return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f);
183}
184// ------------------------------------------------------------------------------------------------
185template <typename TReal>
186AI_FORCE_INLINE aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v) {
187 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
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
195// ------------------------------------------------------------------------------------------------
196template <typename TReal>
197inline bool aiColor4t<TReal> :: IsBlack() const {
198 // The alpha component doesn't care here. black is black.
199 static const TReal epsilon = 10e-3f;
200 return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
201}
202
203#endif // __cplusplus
204#endif // AI_VECTOR3D_INL_INC
205