From 1540361e753688632efbaa5a50e4021871b4c75c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Mar 2018 16:00:47 +0100 Subject: [PATCH 1/4] Avoid warnings about conversion to wxUint16 in wxUniChar code This conversion is intentional, so suppress the -Wconversion warning given by g++ 7 (if this warning is enabled) with an explicit cast. --- include/wx/unichar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/unichar.h b/include/wx/unichar.h index bbd75466bf..5d731754b1 100644 --- a/include/wx/unichar.h +++ b/include/wx/unichar.h @@ -93,14 +93,14 @@ public: static wxUint16 HighSurrogate(wxUint32 value) { wxASSERT_MSG(IsSupplementary(value), "wxUniChar::HighSurrogate() must be called on a supplementary character"); - return 0xD800 | ((value - 0x10000) >> 10); + return static_cast(0xD800 | ((value - 0x10000) >> 10)); } // Returns the low surrogate code unit for the supplementary character static wxUint16 LowSurrogate(wxUint32 value) { wxASSERT_MSG(IsSupplementary(value), "wxUniChar::LowSurrogate() must be called on a supplementary character"); - return 0xDC00 | ((value - 0x10000) & 0x03FF); + return static_cast(0xDC00 | ((value - 0x10000) & 0x03FF)); } // Returns true if the character is a BMP character: From 9774d92e914d39095a9e0b1e8d8d7a147df7275a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Mar 2018 16:01:45 +0100 Subject: [PATCH 2/4] Change wxSize::Scale() to take double, not float There doesn't seem to be any reason to use float here when double is used everywhere else. Moreover, the (implicit) conversion of int to float is not always lossless, and resulted in -Wconversion warnings from g++ 7, which disappear when using doubles. --- include/wx/gdicmn.h | 2 +- interface/wx/gdicmn.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 14b648b092..10baa55178 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -318,7 +318,7 @@ public: void DecBy(int d) { DecBy(d, d); } - wxSize& Scale(float xscale, float yscale) + wxSize& Scale(double xscale, double yscale) { x = (int)(x*xscale); y = (int)(y*yscale); return *this; } // accessors diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index 5d18c2aa7a..6e98d29d88 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -1014,7 +1014,7 @@ public: @return A reference to this object (so that you can concatenate other operations in the same line). */ - wxSize& Scale(float xscale, float yscale); + wxSize& Scale(double xscale, double yscale); /** Sets the width and height members. From bec7c9a1615b0178e7b0321cb5c6ff26ea4c67ed Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Mar 2018 16:06:35 +0100 Subject: [PATCH 3/4] Don't truncate to int in wxRealPoint::operator*() wxRealPoint uses double coordinates and it makes no sense to truncate the result of scaling it to int -- this was almost certainly a copy-and-paste error due to copying the code of the corresponding wxPoint method. --- include/wx/gdicmn.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 10baa55178..d366d4e664 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -547,12 +547,12 @@ inline wxRealPoint operator*(unsigned long i, const wxRealPoint& s) inline wxRealPoint operator*(const wxRealPoint& s, double i) { - return wxRealPoint(int(s.x * i), int(s.y * i)); + return wxRealPoint(s.x * i, s.y * i); } inline wxRealPoint operator*(double i, const wxRealPoint& s) { - return wxRealPoint(int(s.x * i), int(s.y * i)); + return wxRealPoint(s.x * i, s.y * i); } From 1f7a8a82c35af7273e8bfb639ee115b63ee0d78e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Mar 2018 16:08:01 +0100 Subject: [PATCH 4/4] 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