added aclSize in Size2<>

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-05 15:23:20 +08:00
parent 50e754aba2
commit b43c236894

View File

@ -19,6 +19,11 @@ namespace hgl
}
Size2(const T &w,const T &h)
{
Set(w,h);
}
void Set(const T &w,const T &h)
{
width=w;
height=h;
@ -72,6 +77,30 @@ namespace hgl
SIZE2_OPERATOR_INTERACTIVE(/)
#undef SIZE2_OPERATOR_INTERACTIVE
/**
*
* @param allow_over
*/
const float alcScale(const Size2<T> &s,const bool allow_over) const
{
if(width<=0||height<=0)return(0);
if(s.width<=0||s.height<=0)return(0);
float scale=float(width)/float(s.width);
if(allow_over)
{
if(scale*float(s.height)<float(height))
scale=float(height)/float(s.height);
}
else
{
if(scale*float(s.height)>float(height))
scale=float(height)/float(s.height);
}
return(scale);
}
};//template<typename T> struct Size2
using Size2i =Size2<int>;