From 2bbe126dcae477ae30432b49397c616143d57751 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Nov 2021 22:06:28 +0100 Subject: [PATCH] Add operator/(wxSize, double) For some reason, while both operator*(wxSize, double) and wxSize::operator/=(double) existed, this one did not, which was unexpected, so add it too. --- include/wx/gdicmn.h | 5 +++++ interface/wx/gdicmn.h | 12 ++++++++++++ tests/geometry/size.cpp | 2 ++ 3 files changed, 19 insertions(+) diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 6a0ad01e88..2f5f8ee99f 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -435,6 +435,11 @@ inline wxSize operator*(unsigned long i, const wxSize& s) return wxSize(int(s.x * i), int(s.y * i)); } +inline wxSize operator/(const wxSize& s, double i) +{ + return wxSize(wxRound(s.x / i), wxRound(s.y / i)); +} + inline wxSize operator*(const wxSize& s, double i) { return wxSize(wxRound(s.x * i), wxRound(s.y * i)); diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index bccaa6888f..d3932fcf20 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -1064,12 +1064,19 @@ public: /** @name Miscellaneous operators + Sizes can be added to or subtracted from each other or divided or + multiplied by a number. + Note that these operators are documented as class members (to make them easier to find) but, as their prototype shows, they are implemented as global operators; note that this is transparent to the user but it helps to understand why the following functions are documented to take the wxSize they operate on as an explicit argument. + + Also note that using @c double factor may result in rounding errors, + as wxSize always stores @c int coordinates and the result is always + rounded. */ //@{ wxSize& operator=(const wxSize& sz); @@ -1083,10 +1090,15 @@ public: wxSize& operator -=(const wxSize& sz); wxSize operator /(const wxSize& sz, int factor); + wxSize operator /(const wxSize& sz, double factor); wxSize operator *(const wxSize& sz, int factor); + wxSize operator *(const wxSize& sz, double factor); wxSize operator *(int factor, const wxSize& sz); + wxSize operator *(double factor, const wxSize& sz); wxSize& operator /=(int factor); + wxSize& operator /=(double factor); wxSize& operator *=(int factor); + wxSize& operator *=(double factor); //@} }; diff --git a/tests/geometry/size.cpp b/tests/geometry/size.cpp index a84514bb2c..15ede6e524 100644 --- a/tests/geometry/size.cpp +++ b/tests/geometry/size.cpp @@ -48,4 +48,6 @@ TEST_CASE("wxSize::Operators", "[size]") CHECK( s3 == wxSize(2, 4) ); s3 /= 2; CHECK( s3 == s1 ); + + CHECK( wxSize(6, 9) / 1.5 == wxSize(4, 6) ); }