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.
This commit is contained in:
Vadim Zeitlin
2018-03-06 16:08:01 +01:00
parent bec7c9a161
commit 1f7a8a82c3

View File

@@ -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