aiColor4D.inl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development 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 Development 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 aiColor4D operators
  36. */
  37. #ifndef AI_COLOR4D_INL_INC
  38. #define AI_COLOR4D_INL_INC
  39. #include "aiColor4D.h"
  40. #ifdef __cplusplus
  41. // ------------------------------------------------------------------------------------------------
  42. AI_FORCE_INLINE const aiColor4D& aiColor4D::operator += (const aiColor4D& o) {
  43. r += o.r; g += o.g; b += o.b; a += o.a; return *this;
  44. }
  45. // ------------------------------------------------------------------------------------------------
  46. AI_FORCE_INLINE const aiColor4D& aiColor4D::operator -= (const aiColor4D& o) {
  47. r -= o.r; g -= o.g; b -= o.b; a -= o.a; return *this;
  48. }
  49. // ------------------------------------------------------------------------------------------------
  50. AI_FORCE_INLINE const aiColor4D& aiColor4D::operator *= (float f) {
  51. r *= f; g *= f; b *= f; a *= f; return *this;
  52. }
  53. // ------------------------------------------------------------------------------------------------
  54. AI_FORCE_INLINE const aiColor4D& aiColor4D::operator /= (float f) {
  55. r /= f; g /= f; b /= f; a /= f; return *this;
  56. }
  57. // ------------------------------------------------------------------------------------------------
  58. AI_FORCE_INLINE float aiColor4D::operator[](unsigned int i) const {
  59. return *(&r + i);
  60. }
  61. // ------------------------------------------------------------------------------------------------
  62. AI_FORCE_INLINE float& aiColor4D::operator[](unsigned int i) {
  63. return *(&r + i);
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. AI_FORCE_INLINE bool aiColor4D::operator== (const aiColor4D& other) const {
  67. return r == other.r && g == other.g && b == other.b && a == other.a;
  68. }
  69. // ------------------------------------------------------------------------------------------------
  70. AI_FORCE_INLINE bool aiColor4D::operator!= (const aiColor4D& other) const {
  71. return r != other.r || g != other.g || b != other.b || a != other.a;
  72. }
  73. // ------------------------------------------------------------------------------------------------
  74. AI_FORCE_INLINE aiColor4D operator + (const aiColor4D& v1, const aiColor4D& v2) {
  75. return aiColor4D( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
  76. }
  77. // ------------------------------------------------------------------------------------------------
  78. AI_FORCE_INLINE aiColor4D operator - (const aiColor4D& v1, const aiColor4D& v2) {
  79. return aiColor4D( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a);
  80. }
  81. // ------------------------------------------------------------------------------------------------
  82. AI_FORCE_INLINE aiColor4D operator * (const aiColor4D& v1, const aiColor4D& v2) {
  83. return aiColor4D( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a);
  84. }
  85. // ------------------------------------------------------------------------------------------------
  86. AI_FORCE_INLINE aiColor4D operator / (const aiColor4D& v1, const aiColor4D& v2) {
  87. return aiColor4D( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a);
  88. }
  89. // ------------------------------------------------------------------------------------------------
  90. AI_FORCE_INLINE aiColor4D operator * ( float f, const aiColor4D& v) {
  91. return aiColor4D( f*v.r, f*v.g, f*v.b, f*v.a);
  92. }
  93. // ------------------------------------------------------------------------------------------------
  94. AI_FORCE_INLINE aiColor4D operator * ( const aiColor4D& v, float f) {
  95. return aiColor4D( f*v.r, f*v.g, f*v.b, f*v.a);
  96. }
  97. // ------------------------------------------------------------------------------------------------
  98. AI_FORCE_INLINE aiColor4D operator / ( const aiColor4D& v, float f) {
  99. return v * (1/f);
  100. }
  101. // ------------------------------------------------------------------------------------------------
  102. AI_FORCE_INLINE aiColor4D operator / ( float f,const aiColor4D& v) {
  103. return aiColor4D(f,f,f,f)/v;
  104. }
  105. // ------------------------------------------------------------------------------------------------
  106. AI_FORCE_INLINE aiColor4D operator + ( const aiColor4D& v, float f) {
  107. return aiColor4D( f+v.r, f+v.g, f+v.b, f+v.a);
  108. }
  109. // ------------------------------------------------------------------------------------------------
  110. AI_FORCE_INLINE aiColor4D operator - ( const aiColor4D& v, float f) {
  111. return aiColor4D( v.r-f, v.g-f, v.b-f, v.a-f);
  112. }
  113. // ------------------------------------------------------------------------------------------------
  114. AI_FORCE_INLINE aiColor4D operator + ( float f, const aiColor4D& v) {
  115. return aiColor4D( f+v.r, f+v.g, f+v.b, f+v.a);
  116. }
  117. // ------------------------------------------------------------------------------------------------
  118. AI_FORCE_INLINE aiColor4D operator - ( float f, const aiColor4D& v) {
  119. return aiColor4D( f-v.r, f-v.g, f-v.b, f-v.a);
  120. }
  121. // ------------------------------------------------------------------------------------------------
  122. inline bool aiColor4D :: IsBlack() const {
  123. // The alpha component doesn't care here. black is black.
  124. static const float epsilon = 10e-3f;
  125. return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon;
  126. }
  127. #endif // __cplusplus
  128. #endif // AI_VECTOR3D_INL_INC