append return value in Color3f/4f::operator =

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-11-01 18:33:27 +08:00
parent ac8565e338
commit b5c66fe2cd
5 changed files with 18 additions and 12 deletions

View File

@ -58,10 +58,11 @@ namespace hgl
void Grey(); ///<将当前色彩变成灰色
//操作符重载
void operator = (const float *v){r=*v++;g=*v++;b=*v;}
const Color3f &operator = (const float *v){r=*v++;g=*v++;b=*v;return *this;}
const Color3f &operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;return *this;}
bool operator == (const Color3f &);
bool operator != (const Color3f &);
bool operator == (const Color3f &)const;
bool operator != (const Color3f &)const;
void operator += (const Color3f &v){r+=v.r;g+=v.g;b+=v.b;Clamp();}
void operator -= (const Color3f &v){r-=v.r;g-=v.g;b-=v.b;Clamp();}

View File

@ -68,12 +68,12 @@ namespace hgl
void Grey(); ///<将当前色彩变成灰色
//操作符重载
void operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;}
void operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;}
void operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;}
const Color4f &operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;return *this;}
const Color4f &operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;;return *this;}
const Color4f &operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;;return *this;}
bool operator == (const Color4f &);
bool operator != (const Color4f &);
bool operator == (const Color4f &)const;
bool operator != (const Color4f &)const;
void operator += (const Color4f &v){r+=v.r;g+=v.g;b+=v.b;a+=v.a;Clamp();}
void operator -= (const Color4f &v){r-=v.r;g-=v.g;b-=v.b;a-=v.a;Clamp();}

View File

@ -14,5 +14,10 @@ namespace hgl
{
return (r*54+g*183+b*19)>>8;
}
template<typename T> constexpr T RGB2LumBT2020(const T &r,const T &g,const T &b)
{
return 0.2627f*r+0.6780f*g+0.0593f*b;
}
}//namespace hgl
#endif//HGL_COLOR_LUM_INCLUDE

View File

@ -39,7 +39,7 @@ namespace hgl
b=lum;
}
//--------------------------------------------------------------------------------------------------
bool Color3f::operator == (const Color3f &v)
bool Color3f::operator == (const Color3f &v) const
{
if(r!=v.r)return(false);
if(g!=v.g)return(false);
@ -48,7 +48,7 @@ namespace hgl
return(true);
}
//--------------------------------------------------------------------------------------------------
bool Color3f::operator != (const Color3f &v)
bool Color3f::operator != (const Color3f &v) const
{
if(r!=v.r)return(true);
if(g!=v.g)return(true);

View File

@ -40,7 +40,7 @@ namespace hgl
b=lum;
}
//--------------------------------------------------------------------------------------------------
bool Color4f::operator == (const Color4f &v)
bool Color4f::operator == (const Color4f &v) const
{
if(r!=v.r)return(false);
if(g!=v.g)return(false);
@ -50,7 +50,7 @@ namespace hgl
return(true);
}
//--------------------------------------------------------------------------------------------------
bool Color4f::operator != (const Color4f &v)
bool Color4f::operator != (const Color4f &v) const
{
if(r!=v.r)return(true);
if(g!=v.g)return(true);