From b43c236894f0740591d38916411b4bbd83bf351a Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Wed, 5 Jul 2023 15:23:20 +0800 Subject: [PATCH] added aclSize in Size2<> --- inc/hgl/type/Size2.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/inc/hgl/type/Size2.h b/inc/hgl/type/Size2.h index c0eb6ef..42f602f 100644 --- a/inc/hgl/type/Size2.h +++ b/inc/hgl/type/Size2.h @@ -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 &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); + } + + return(scale); + } };//template struct Size2 using Size2i =Size2;