miniassimp

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/miniassimp/color4.inl	Mon Jan 28 18:19:26 2019 +0200
     1.3 @@ -0,0 +1,205 @@
     1.4 +/*
     1.5 +---------------------------------------------------------------------------
     1.6 +Open Asset Import Library (assimp)
     1.7 +---------------------------------------------------------------------------
     1.8 +
     1.9 +Copyright (c) 2006-2018, assimp team
    1.10 +
    1.11 +
    1.12 +
    1.13 +All rights reserved.
    1.14 +
    1.15 +Redistribution and use of this software in source and binary forms,
    1.16 +with or without modification, are permitted provided that the following
    1.17 +conditions are met:
    1.18 +
    1.19 +* Redistributions of source code must retain the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer.
    1.22 +
    1.23 +* Redistributions in binary form must reproduce the above
    1.24 +  copyright notice, this list of conditions and the
    1.25 +  following disclaimer in the documentation and/or other
    1.26 +  materials provided with the distribution.
    1.27 +
    1.28 +* Neither the name of the assimp team, nor the names of its
    1.29 +  contributors may be used to endorse or promote products
    1.30 +  derived from this software without specific prior
    1.31 +  written permission of the assimp team.
    1.32 +
    1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.44 +---------------------------------------------------------------------------
    1.45 +*/
    1.46 +
    1.47 +/** @file  color4.inl
    1.48 + *  @brief Inline implementation of aiColor4t<TReal> operators
    1.49 + */
    1.50 +#pragma once
    1.51 +#ifndef AI_COLOR4D_INL_INC
    1.52 +#define AI_COLOR4D_INL_INC
    1.53 +
    1.54 +#ifdef __cplusplus
    1.55 +#include "color4.h"
    1.56 +
    1.57 +// ------------------------------------------------------------------------------------------------
    1.58 +template <typename TReal>
    1.59 +AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator += (const aiColor4t<TReal>& o) {
    1.60 +    r += o.r; g += o.g; b += o.b; a += o.a;
    1.61 +    return *this;
    1.62 +}
    1.63 +// ------------------------------------------------------------------------------------------------
    1.64 +template <typename TReal>
    1.65 +AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator -= (const aiColor4t<TReal>& o) {
    1.66 +    r -= o.r; g -= o.g; b -= o.b; a -= o.a;
    1.67 +    return *this;
    1.68 +}
    1.69 +// ------------------------------------------------------------------------------------------------
    1.70 +template <typename TReal>
    1.71 +AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator *= (TReal f) {
    1.72 +    r *= f; g *= f; b *= f; a *= f;
    1.73 +    return *this;
    1.74 +}
    1.75 +// ------------------------------------------------------------------------------------------------
    1.76 +template <typename TReal>
    1.77 +AI_FORCE_INLINE const aiColor4t<TReal>& aiColor4t<TReal>::operator /= (TReal f) {
    1.78 +    r /= f; g /= f; b /= f; a /= f;
    1.79 +    return *this;
    1.80 +}
    1.81 +// ------------------------------------------------------------------------------------------------
    1.82 +template <typename TReal>
    1.83 +AI_FORCE_INLINE TReal aiColor4t<TReal>::operator[](unsigned int i) const {
    1.84 +    switch ( i ) {
    1.85 +        case 0:
    1.86 +            return r;
    1.87 +        case 1:
    1.88 +            return g;
    1.89 +        case 2:
    1.90 +            return b;
    1.91 +        default:
    1.92 +            break;
    1.93 +    }
    1.94 +    return r;
    1.95 +}
    1.96 +// ------------------------------------------------------------------------------------------------
    1.97 +template <typename TReal>
    1.98 +AI_FORCE_INLINE TReal& aiColor4t<TReal>::operator[](unsigned int i) {
    1.99 +    switch ( i ) {
   1.100 +        case 0:
   1.101 +            return r;
   1.102 +        case 1:
   1.103 +            return g;
   1.104 +        case 2:
   1.105 +            return b;
   1.106 +        default:
   1.107 +            break;
   1.108 +    }
   1.109 +    return r;
   1.110 +}
   1.111 +// ------------------------------------------------------------------------------------------------
   1.112 +template <typename TReal>
   1.113 +AI_FORCE_INLINE bool aiColor4t<TReal>::operator== (const aiColor4t<TReal>& other) const {
   1.114 +    return r == other.r && g == other.g && b == other.b && a == other.a;
   1.115 +}
   1.116 +// ------------------------------------------------------------------------------------------------
   1.117 +template <typename TReal>
   1.118 +AI_FORCE_INLINE bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other) const {
   1.119 +    return r != other.r || g != other.g || b != other.b || a != other.a;
   1.120 +}
   1.121 +// ------------------------------------------------------------------------------------------------
   1.122 +template <typename TReal>
   1.123 +AI_FORCE_INLINE bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const {
   1.124 +    return r < other.r || (
   1.125 +        r == other.r && (
   1.126 +            g < other.g || (
   1.127 +                g == other.g && (
   1.128 +                    b < other.b || (
   1.129 +                        b == other.b && (
   1.130 +                            a < other.a
   1.131 +                        )
   1.132 +                    )
   1.133 +                )
   1.134 +            )
   1.135 +        )
   1.136 +    );
   1.137 +}
   1.138 +// ------------------------------------------------------------------------------------------------
   1.139 +template <typename TReal>
   1.140 +AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2)    {
   1.141 +    return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
   1.142 +}
   1.143 +// ------------------------------------------------------------------------------------------------
   1.144 +template <typename TReal>
   1.145 +AI_FORCE_INLINE aiColor4t<TReal> operator - (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2)    {
   1.146 +    return aiColor4t<TReal>( v1.r - v2.r, v1.g - v2.g, v1.b - v2.b, v1.a - v2.a);
   1.147 +}
   1.148 +// ------------------------------------------------------------------------------------------------
   1.149 +template <typename TReal>
   1.150 +AI_FORCE_INLINE aiColor4t<TReal> operator * (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2)    {
   1.151 +    return aiColor4t<TReal>( v1.r * v2.r, v1.g * v2.g, v1.b * v2.b, v1.a * v2.a);
   1.152 +}
   1.153 +// ------------------------------------------------------------------------------------------------
   1.154 +template <typename TReal>
   1.155 +AI_FORCE_INLINE aiColor4t<TReal> operator / (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2)    {
   1.156 +    return aiColor4t<TReal>( v1.r / v2.r, v1.g / v2.g, v1.b / v2.b, v1.a / v2.a);
   1.157 +}
   1.158 +// ------------------------------------------------------------------------------------------------
   1.159 +template <typename TReal>
   1.160 +AI_FORCE_INLINE aiColor4t<TReal> operator * ( TReal f, const aiColor4t<TReal>& v)   {
   1.161 +    return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
   1.162 +}
   1.163 +// ------------------------------------------------------------------------------------------------
   1.164 +template <typename TReal>
   1.165 +AI_FORCE_INLINE  aiColor4t<TReal> operator * ( const aiColor4t<TReal>& v, TReal f)  {
   1.166 +    return aiColor4t<TReal>( f*v.r, f*v.g, f*v.b, f*v.a);
   1.167 +}
   1.168 +// ------------------------------------------------------------------------------------------------
   1.169 +template <typename TReal>
   1.170 +AI_FORCE_INLINE  aiColor4t<TReal> operator / ( const aiColor4t<TReal>& v, TReal f)  {
   1.171 +    return v * (1/f);
   1.172 +}
   1.173 +// ------------------------------------------------------------------------------------------------
   1.174 +template <typename TReal>
   1.175 +AI_FORCE_INLINE  aiColor4t<TReal> operator / ( TReal f,const aiColor4t<TReal>& v)   {
   1.176 +    return aiColor4t<TReal>(f,f,f,f)/v;
   1.177 +}
   1.178 +// ------------------------------------------------------------------------------------------------
   1.179 +template <typename TReal>
   1.180 +AI_FORCE_INLINE  aiColor4t<TReal> operator + ( const aiColor4t<TReal>& v, TReal f)  {
   1.181 +    return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
   1.182 +}
   1.183 +// ------------------------------------------------------------------------------------------------
   1.184 +template <typename TReal>
   1.185 +AI_FORCE_INLINE  aiColor4t<TReal> operator - ( const aiColor4t<TReal>& v, TReal f)  {
   1.186 +    return aiColor4t<TReal>( v.r-f, v.g-f, v.b-f, v.a-f);
   1.187 +}
   1.188 +// ------------------------------------------------------------------------------------------------
   1.189 +template <typename TReal>
   1.190 +AI_FORCE_INLINE  aiColor4t<TReal> operator + ( TReal f, const aiColor4t<TReal>& v)  {
   1.191 +    return aiColor4t<TReal>( f+v.r, f+v.g, f+v.b, f+v.a);
   1.192 +}
   1.193 +// ------------------------------------------------------------------------------------------------
   1.194 +template <typename TReal>
   1.195 +AI_FORCE_INLINE  aiColor4t<TReal> operator - ( TReal f, const aiColor4t<TReal>& v)  {
   1.196 +    return aiColor4t<TReal>( f-v.r, f-v.g, f-v.b, f-v.a);
   1.197 +}
   1.198 +
   1.199 +// ------------------------------------------------------------------------------------------------
   1.200 +template <typename TReal>
   1.201 +inline bool aiColor4t<TReal> :: IsBlack() const {
   1.202 +    // The alpha component doesn't care here. black is black.
   1.203 +    static const TReal epsilon = 10e-3f;
   1.204 +    return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
   1.205 +}
   1.206 +
   1.207 +#endif // __cplusplus
   1.208 +#endif // AI_VECTOR3D_INL_INC