From 1f7a8a82c35af7273e8bfb639ee115b63ee0d78e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Mar 2018 16:08:01 +0100 Subject: [PATCH] Round, rather than truncate, in wxSize and wxPoint operations It seems to make more sense to round the result to int rather than to truncate it when scaling wxSize or wxPoint coordinates by a floating point number. --- include/wx/gdicmn.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index d366d4e664..f7d39c017b 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -292,8 +292,8 @@ public: wxSize& operator*=(long i) { x *= i; y *= i; return *this; } wxSize& operator/=(unsigned long i) { x /= i; y /= i; return *this; } wxSize& operator*=(unsigned long i) { x *= i; y *= i; return *this; } - wxSize& operator/=(double i) { x = int(x/i); y = int(y/i); return *this; } - wxSize& operator*=(double i) { x = int(x*i); y = int(y*i); return *this; } + wxSize& operator/=(double i) { x = wxRound(x/i); y = wxRound(y/i); return *this; } + wxSize& operator*=(double i) { x = wxRound(x*i); y = wxRound(y*i); return *this; } void IncTo(const wxSize& sz) { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; } @@ -319,7 +319,7 @@ public: wxSize& Scale(double xscale, double yscale) - { x = (int)(x*xscale); y = (int)(y*yscale); return *this; } + { x = wxRound(x*xscale); y = wxRound(y*yscale); return *this; } // accessors void Set(int xx, int yy) { x = xx; y = yy; } @@ -428,12 +428,12 @@ inline wxSize operator*(unsigned long i, const wxSize& s) inline wxSize operator*(const wxSize& s, double i) { - return wxSize(int(s.x * i), int(s.y * i)); + return wxSize(wxRound(s.x * i), wxRound(s.y * i)); } inline wxSize operator*(double i, const wxSize& s) { - return wxSize(int(s.x * i), int(s.y * i)); + return wxSize(wxRound(s.x * i), wxRound(s.y * i)); } @@ -567,7 +567,7 @@ public: wxPoint() : x(0), y(0) { } wxPoint(int xx, int yy) : x(xx), y(yy) { } - wxPoint(const wxRealPoint& pt) : x(int(pt.x)), y(int(pt.y)) { } + wxPoint(const wxRealPoint& pt) : x(wxRound(pt.x)), y(wxRound(pt.y)) { } // no copy ctor or assignment operator - the defaults are ok