You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

183 lines
8.0 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, 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 aiColor4D.inl
  35. * @brief Inline implementation of aiColor4t<TReal> operators
  36. */
  37. #ifndef AI_COLOR4D_INL_INC
  38. #define AI_COLOR4D_INL_INC
  39. #ifdef __cplusplus
  40. #include "color4.h"
  41. // ------------------------------------------------------------------------------------------------
  42. template <typename TReal>
  43. AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator += (const aiColor4t<TReal>& o) {
  44. r += o.r; g += o.g; b += o.b; a += o.a;
  45. return *this;
  46. }
  47. // ------------------------------------------------------------------------------------------------
  48. template <typename TReal>
  49. AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator -= (const aiColor4t<TReal>& o) {
  50. r -= o.r; g -= o.g; b -= o.b; a -= o.a;
  51. return *this;
  52. }
  53. // ------------------------------------------------------------------------------------------------
  54. template <typename TReal>
  55. AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) {
  56. r *= f; g *= f; b *= f; a *= f;
  57. return *this;
  58. }
  59. // ------------------------------------------------------------------------------------------------
  60. template <typename TReal>
  61. AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) {
  62. r /= f; g /= f; b /= f; a /= f;
  63. return *this;
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. template <typename TReal>
  67. AI_FORCE_INLINE TReal aiColor4t<TReal>::operator[](unsigned int i) const {
  68. return *(&r + i);
  69. }
  70. // ------------------------------------------------------------------------------------------------
  71. template <typename TReal>
  72. AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) {
  73. return *(&r + i);
  74. }
  75. // ------------------------------------------------------------------------------------------------
  76. template <typename TReal>
  77. AI_FORCE_INLINE bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const {
  78. return r == other.r && g == other.g && b == other.b && a == other.a;
  79. }
  80. // ------------------------------------------------------------------------------------------------
  81. template <typename TReal>
  82. AI_FORCE_INLINE bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other) const {
  83. return r != other.r || g != other.g || b != other.b || a != other.a;
  84. }
  85. // ------------------------------------------------------------------------------------------------
  86. template <typename TReal>
  87. AI_FORCE_INLINE bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const {
  88. return r < other.r || (
  89. r == other.r && (
  90. g < other.g || (
  91. g == other.g && (
  92. b < other.b || (
  93. b == other.b && (
  94. a < other.a
  95. )
  96. )
  97. )
  98. )
  99. )
  100. );
  101. }
  102. // ------------------------------------------------------------------------------------------------
  103. template <typename TReal>
  104. AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
  105. return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
  106. }
  107. // ------------------------------------------------------------------------------------------------
  108. template <typename TReal>
  109. AI_FORCE_INLINE aiColor4t<TReal> operator - (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
  110. return aiColor4t<TReal>( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a);
  111. }
  112. // ------------------------------------------------------------------------------------------------
  113. template <typename TReal>
  114. AI_FORCE_INLINE aiColor4t<TReal> operator * (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
  115. return aiColor4t<TReal>( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a);
  116. }
  117. // ------------------------------------------------------------------------------------------------
  118. template <typename TReal>
  119. AI_FORCE_INLINE aiColor4t<TReal> operator / (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
  120. return aiColor4t<TReal>( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a);
  121. }
  122. // ------------------------------------------------------------------------------------------------
  123. template <typename TReal>
  124. AI_FORCE_INLINE aiColor4t<TReal> operator * ( TReal f, const aiColor4t<TReal>& v) {
  125. return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
  126. }
  127. // ------------------------------------------------------------------------------------------------
  128. template <typename TReal>
  129. AI_FORCE_INLINE aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f) {
  130. return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
  131. }
  132. // ------------------------------------------------------------------------------------------------
  133. template <typename TReal>
  134. AI_FORCE_INLINE aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f) {
  135. return v * (1/f);
  136. }
  137. // ------------------------------------------------------------------------------------------------
  138. template <typename TReal>
  139. AI_FORCE_INLINE aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v) {
  140. return aiColor4t<TReal>(f,f,f,f)/v;
  141. }
  142. // ------------------------------------------------------------------------------------------------
  143. template <typename TReal>
  144. AI_FORCE_INLINE aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f) {
  145. return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
  146. }
  147. // ------------------------------------------------------------------------------------------------
  148. template <typename TReal>
  149. AI_FORCE_INLINE aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f) {
  150. return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f);
  151. }
  152. // ------------------------------------------------------------------------------------------------
  153. template <typename TReal>
  154. AI_FORCE_INLINE aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v) {
  155. return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
  156. }
  157. // ------------------------------------------------------------------------------------------------
  158. template <typename TReal>
  159. AI_FORCE_INLINE aiColor4t<TReal> operator - ( TReal f, const aiColor4t<TReal>& v) {
  160. return aiColor4t<TReal>( f-v.r, f-v.g, f-v.b, f-v.a);
  161. }
  162. // ------------------------------------------------------------------------------------------------
  163. template <typename TReal>
  164. inline bool aiColor4t<TReal> :: IsBlack() const {
  165. // The alpha component doesn't care here. black is black.
  166. static const TReal epsilon = 10e-3f;
  167. return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon;
  168. }
  169. #endif // __cplusplus
  170. #endif // AI_VECTOR3D_INL_INC