miniassimp

view include/miniassimp/color4.inl @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2018, assimp team
10 All rights reserved.
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:
16 * Redistributions of source code must retain the above
17 copyright notice, this list of conditions and the
18 following disclaimer.
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.
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.
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 */
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
51 #ifdef __cplusplus
52 #include "color4.h"
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 default:
89 break;
90 }
91 return r;
92 }
93 // ------------------------------------------------------------------------------------------------
94 template <typename TReal>
95 AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) {
96 switch ( i ) {
97 case 0:
98 return r;
99 case 1:
100 return g;
101 case 2:
102 return b;
103 default:
104 break;
105 }
106 return r;
107 }
108 // ------------------------------------------------------------------------------------------------
109 template <typename TReal>
110 AI_FORCE_INLINE bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const {
111 return r == other.r && g == other.g && b == other.b && a == other.a;
112 }
113 // ------------------------------------------------------------------------------------------------
114 template <typename TReal>
115 AI_FORCE_INLINE bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other) const {
116 return r != other.r || g != other.g || b != other.b || a != other.a;
117 }
118 // ------------------------------------------------------------------------------------------------
119 template <typename TReal>
120 AI_FORCE_INLINE bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const {
121 return r < other.r || (
122 r == other.r && (
123 g < other.g || (
124 g == other.g && (
125 b < other.b || (
126 b == other.b && (
127 a < other.a
128 )
129 )
130 )
131 )
132 )
133 );
134 }
135 // ------------------------------------------------------------------------------------------------
136 template <typename TReal>
137 AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
138 return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
139 }
140 // ------------------------------------------------------------------------------------------------
141 template <typename TReal>
142 AI_FORCE_INLINE aiColor4t<TReal> operator - (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
143 return aiColor4t<TReal>( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a);
144 }
145 // ------------------------------------------------------------------------------------------------
146 template <typename TReal>
147 AI_FORCE_INLINE aiColor4t<TReal> operator * (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
148 return aiColor4t<TReal>( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a);
149 }
150 // ------------------------------------------------------------------------------------------------
151 template <typename TReal>
152 AI_FORCE_INLINE aiColor4t<TReal> operator / (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
153 return aiColor4t<TReal>( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a);
154 }
155 // ------------------------------------------------------------------------------------------------
156 template <typename TReal>
157 AI_FORCE_INLINE aiColor4t<TReal> operator * ( TReal f, const aiColor4t<TReal>& v) {
158 return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
159 }
160 // ------------------------------------------------------------------------------------------------
161 template <typename TReal>
162 AI_FORCE_INLINE aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f) {
163 return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
164 }
165 // ------------------------------------------------------------------------------------------------
166 template <typename TReal>
167 AI_FORCE_INLINE aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f) {
168 return v * (1/f);
169 }
170 // ------------------------------------------------------------------------------------------------
171 template <typename TReal>
172 AI_FORCE_INLINE aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) {
173 return aiColor4t<TReal>(f,f,f,f)/v;
174 }
175 // ------------------------------------------------------------------------------------------------
176 template <typename TReal>
177 AI_FORCE_INLINE aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f) {
178 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
179 }
180 // ------------------------------------------------------------------------------------------------
181 template <typename TReal>
182 AI_FORCE_INLINE aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f) {
183 return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f);
184 }
185 // ------------------------------------------------------------------------------------------------
186 template <typename TReal>
187 AI_FORCE_INLINE aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v) {
188 return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
189 }
190 // ------------------------------------------------------------------------------------------------
191 template <typename TReal>
192 AI_FORCE_INLINE aiColor4t<TReal> operator - ( TReal f, const aiColor4t<TReal>& v) {
193 return aiColor4t<TReal>( f-v.r, f-v.g, f-v.b, f-v.a);
194 }
196 // ------------------------------------------------------------------------------------------------
197 template <typename TReal>
198 inline bool aiColor4t<TReal> :: IsBlack() const {
199 // The alpha component doesn't care here. black is black.
200 static const TReal epsilon = 10e-3f;
201 return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
202 }
204 #endif // __cplusplus
205 #endif // AI_VECTOR3D_INL_INC