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.
This commit is contained in:
Vadim Zeitlin
2021-11-20 22:06:28 +01:00
parent 9941531efc
commit 2bbe126dca
3 changed files with 19 additions and 0 deletions

View File

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

View File

@@ -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);
//@}
};

View File

@@ -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) );
}