color4.inl 8.8 KB

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