diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index ae0287ac8d..555ee6985a 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -469,6 +469,11 @@ public: wxRealPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } wxRealPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } + + wxRealPoint& operator/=(int i) { x *= i; y *= i; return *this; } + wxRealPoint& operator*=(int i) { x /= i; y /= i; return *this; } + wxRealPoint& operator/=(double f) { x /= f; y /= f; return *this; } + wxRealPoint& operator*=(double f) { x *= f; y *= f; return *this; } }; @@ -487,81 +492,94 @@ inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2) return wxRealPoint(p1.x + p2.x, p1.y + p2.y); } - inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2) { return wxRealPoint(p1.x - p2.x, p1.y - p2.y); } - -inline wxRealPoint operator/(const wxRealPoint& s, int i) +inline wxRealPoint operator+(const wxRealPoint& pt, const wxSize& sz) { - return wxRealPoint(s.x / i, s.y / i); + return wxRealPoint(pt.x + sz.GetWidth(), pt.y + sz.GetHeight()); } -inline wxRealPoint operator*(const wxRealPoint& s, int i) +inline wxRealPoint operator-(const wxRealPoint& pt, const wxSize& sz) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(pt.x - sz.GetWidth(), pt.y - sz.GetHeight()); } -inline wxRealPoint operator*(int i, const wxRealPoint& s) +inline wxRealPoint operator+(const wxSize& sz, const wxRealPoint& pt) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(sz.GetWidth() + pt.x, sz.GetHeight() + pt.y); } -inline wxRealPoint operator/(const wxRealPoint& s, unsigned int i) +inline wxRealPoint operator-(const wxSize& sz, const wxRealPoint& pt) { - return wxRealPoint(s.x / i, s.y / i); + return wxRealPoint(sz.GetWidth() - pt.x, sz.GetHeight() - pt.y); } -inline wxRealPoint operator*(const wxRealPoint& s, unsigned int i) +inline wxRealPoint operator-(const wxRealPoint& pt) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(-pt.x, -pt.y); } -inline wxRealPoint operator*(unsigned int i, const wxRealPoint& s) +inline wxRealPoint operator/(const wxRealPoint& p, int i) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x / i, p.y / i); } -inline wxRealPoint operator/(const wxRealPoint& s, long i) +inline wxRealPoint operator*(const wxRealPoint& p, int i) { - return wxRealPoint(s.x / i, s.y / i); + return wxRealPoint(p.x * i, p.y * i); } -inline wxRealPoint operator*(const wxRealPoint& s, long i) +inline wxRealPoint operator*(int i, const wxRealPoint& p) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x * i, p.y * i); } -inline wxRealPoint operator*(long i, const wxRealPoint& s) +inline wxRealPoint operator/(const wxRealPoint& p, unsigned int i) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x / i, p.y / i); } -inline wxRealPoint operator/(const wxRealPoint& s, unsigned long i) +inline wxRealPoint operator*(const wxRealPoint& p, unsigned int i) { - return wxRealPoint(s.x / i, s.y / i); + return wxRealPoint(p.x * i, p.y * i); } -inline wxRealPoint operator*(const wxRealPoint& s, unsigned long i) +inline wxRealPoint operator*(unsigned int i, const wxRealPoint& p) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x * i, p.y * i); } -inline wxRealPoint operator*(unsigned long i, const wxRealPoint& s) +inline wxRealPoint operator/(const wxRealPoint& p, long i) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x / i, p.y / i); } -inline wxRealPoint operator*(const wxRealPoint& s, double i) +inline wxRealPoint operator*(const wxRealPoint& p, long i) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x * i, p.y * i); } -inline wxRealPoint operator*(double i, const wxRealPoint& s) +inline wxRealPoint operator*(long i, const wxRealPoint& p) { - return wxRealPoint(s.x * i, s.y * i); + return wxRealPoint(p.x * i, p.y * i); +} + +inline wxRealPoint operator/(const wxRealPoint& p, unsigned long i) +{ + return wxRealPoint(p.x / i, p.y / i); +} + +inline wxRealPoint operator*(const wxRealPoint& p, unsigned long i) +{ + return wxRealPoint(p.x * i, p.y * i); +} + +inline wxRealPoint operator*(unsigned long i, const wxRealPoint& p) +{ + return wxRealPoint(p.x * i, p.y * i); } inline wxRealPoint operator/(const wxRealPoint& p, double f) @@ -569,6 +587,16 @@ inline wxRealPoint operator/(const wxRealPoint& p, double f) return wxRealPoint(p.x / f, p.y / f); } +inline wxRealPoint operator*(const wxRealPoint& p, double f) +{ + return wxRealPoint(p.x * f, p.y * f); +} + +inline wxRealPoint operator*(double f, const wxRealPoint& p) +{ + return wxRealPoint(p.x * f, p.y * f); +} + // ---------------------------------------------------------------------------- // wxPoint: 2D point with integer coordinates @@ -592,6 +620,11 @@ public: wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } + wxPoint& operator/=(int i) { x /= i, y /= i; return *this; } + wxPoint& operator*=(int i) { x *= i, y *= i; return *this; } + wxPoint& operator/=(double f) { x = wxRound(x/f); y = wxRound(y/f); return *this; } + wxPoint& operator*=(double f) { x = wxRound(x*f); y = wxRound(y*f); return *this; } + // check if both components are set/initialized bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; } @@ -654,74 +687,64 @@ inline wxPoint operator-(const wxPoint& p) return wxPoint(-p.x, -p.y); } -inline wxPoint operator/(const wxPoint& s, int i) +inline wxPoint operator/(const wxPoint& p, int i) { - return wxPoint(s.x / i, s.y / i); + return wxPoint(p.x / i, p.y / i); } -inline wxPoint operator*(const wxPoint& s, int i) +inline wxPoint operator*(const wxPoint& p, int i) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(p.x * i, p.y * i); } -inline wxPoint operator*(int i, const wxPoint& s) +inline wxPoint operator*(int i, const wxPoint& p) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(p.x * i, p.y * i); } -inline wxPoint operator/(const wxPoint& s, unsigned int i) +inline wxPoint operator/(const wxPoint& p, unsigned int i) { - return wxPoint(s.x / i, s.y / i); + return wxPoint(p.x / i, p.y / i); } -inline wxPoint operator*(const wxPoint& s, unsigned int i) +inline wxPoint operator*(const wxPoint& p, unsigned int i) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(p.x * i, p.y * i); } -inline wxPoint operator*(unsigned int i, const wxPoint& s) +inline wxPoint operator*(unsigned int i, const wxPoint& p) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(p.x * i, p.y * i); } -inline wxPoint operator/(const wxPoint& s, long i) +inline wxPoint operator/(const wxPoint& p, long i) { - return wxPoint(s.x / i, s.y / i); + return wxPoint(p.x / i, p.y / i); } -inline wxPoint operator*(const wxPoint& s, long i) +inline wxPoint operator*(const wxPoint& p, long i) { - return wxPoint(int(s.x * i), int(s.y * i)); + return wxPoint(int(p.x * i), int(p.y * i)); } -inline wxPoint operator*(long i, const wxPoint& s) +inline wxPoint operator*(long i, const wxPoint& p) { - return wxPoint(int(s.x * i), int(s.y * i)); + return wxPoint(int(p.x * i), int(p.y * i)); } -inline wxPoint operator/(const wxPoint& s, unsigned long i) +inline wxPoint operator/(const wxPoint& p, unsigned long i) { - return wxPoint(s.x / i, s.y / i); + return wxPoint(p.x / i, p.y / i); } -inline wxPoint operator*(const wxPoint& s, unsigned long i) +inline wxPoint operator*(const wxPoint& p, unsigned long i) { - return wxPoint(int(s.x * i), int(s.y * i)); + return wxPoint(int(p.x * i), int(p.y * i)); } -inline wxPoint operator*(unsigned long i, const wxPoint& s) +inline wxPoint operator*(unsigned long i, const wxPoint& p) { - return wxPoint(int(s.x * i), int(s.y * i)); -} - -inline wxPoint operator*(const wxPoint& s, double i) -{ - return wxPoint(int(s.x * i), int(s.y * i)); -} - -inline wxPoint operator*(double i, const wxPoint& s) -{ - return wxPoint(int(s.x * i), int(s.y * i)); + return wxPoint(int(p.x * i), int(p.y * i)); } inline wxPoint operator/(const wxPoint& p, double f) @@ -729,6 +752,16 @@ inline wxPoint operator/(const wxPoint& p, double f) return wxPoint(wxRound(p.x / f), wxRound(p.y / f)); } +inline wxPoint operator*(const wxPoint& p, double f) +{ + return wxPoint(int(p.x * f), int(p.y * f)); +} + +inline wxPoint operator*(double f, const wxPoint& p) +{ + return wxPoint(int(p.x * f), int(p.y * f)); +} + WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE); // --------------------------------------------------------------------------- diff --git a/interface/wx/gdicmn.h b/interface/wx/gdicmn.h index 53fcc348dc..12105288c2 100644 --- a/interface/wx/gdicmn.h +++ b/interface/wx/gdicmn.h @@ -227,13 +227,19 @@ public: wxRealPoint& operator +=(const wxSize& sz); wxRealPoint& operator -=(const wxSize& sz); - wxRealPoint operator /(const wxRealPoint& sz, int factor); + wxRealPoint operator -(const wxRealPoint& pt); + + wxRealPoint operator /(const wxRealPoint& sz, int divisor); wxRealPoint operator *(const wxRealPoint& sz, int factor); - wxRealPoint operator *(int factor, const wxRealPoint& sz); - wxRealPoint& operator /=(int factor); + wxRealPoint operator *(int factor, const wxRealPoint& pt); + wxRealPoint& operator /=(int divisor); wxRealPoint& operator *=(int factor); - wxRealPoint operator /(const wxRealPoint& pt, double factor); + wxRealPoint operator /(const wxRealPoint& pt, double divisor); + wxRealPoint operator *(const wxRealPoint& pt, double factor); + wxRealPoint operator *(double factor, const wxRealPoint& pt); + wxRealPoint& operator /=(double divisor); + wxRealPoint& operator *=(double factor); ///@} /** @@ -733,13 +739,19 @@ public: wxPoint& operator +=(const wxSize& sz); wxPoint& operator -=(const wxSize& sz); - wxPoint operator /(const wxPoint& sz, int factor); + wxPoint operator -(const wxPoint& pt); + + wxPoint operator /(const wxPoint& sz, int divisor); wxPoint operator *(const wxPoint& sz, int factor); wxPoint operator *(int factor, const wxPoint& sz); - wxPoint& operator /=(int factor); + wxPoint& operator /=(int divisor); wxPoint& operator *=(int factor); - wxPoint operator /(const wxPoint& pt, double factor); + wxPoint operator /(const wxPoint& pt, double divisor); + wxPoint operator *(const wxPoint& pt, double factor); + wxPoint operator *(double factor, const wxPoint& pt); + wxPoint& operator /=(double divisor); + wxPoint& operator *=(double factor); ///@} diff --git a/tests/geometry/point.cpp b/tests/geometry/point.cpp index aaf2867bd2..2f0dea08ff 100644 --- a/tests/geometry/point.cpp +++ b/tests/geometry/point.cpp @@ -51,6 +51,31 @@ TEST_CASE("wxPoint::Operators", "[point]") p6 = p2; p6 -= s; CHECK( p3 == p5 ); CHECK( p4 == p6 ); + + // Test arithmetic compound assignment operators with scalars + wxPoint p7(3, 5); + p7 /= 2; // chosen to check results truncate + CHECK( p7.x == 1 ); + CHECK( p7.y == 2 ); + p7 *= 2; + CHECK( p7.x == 2 ); + CHECK( p7.y == 4 ); + p7 *= 3.2; // chosen so that x and y rounds down and up respectively + CHECK( p7.x == 6 ); + CHECK( p7.y == 13 ); + p7 /= 1.1; // chosen so that x and y rounds up and down respectively + CHECK( p7.x == 5 ); + CHECK( p7.y == 12 ); + + // Test arithmetic compound assignment operators with wxSizes + wxSize s1(2, 3); + p7 += s1; + CHECK( p7.x == 7 ); + CHECK( p7.y == 15 ); + wxSize s2(3, 4); + p7 -= s2; + CHECK( p7.x == 4 ); + CHECK( p7.y == 11 ); } TEST_CASE("wxRealPoint::Operators", "[point]") @@ -66,4 +91,23 @@ TEST_CASE("wxRealPoint::Operators", "[point]") CHECK( p4.x == Approx(p6.x) ); CHECK( p4.y == Approx(p6.y) ); CHECK( p3.x != Approx(p4.x) ); + + // Test arithmetic compound assignment operators with scalars + wxRealPoint p7(3.0, 5.0); + p7 /= 2.0; + CHECK( p7.x == Approx(1.5) ); + CHECK( p7.y == Approx(2.5) ); + p7 *= 3.0; + CHECK( p7.x == Approx(4.5) ); + CHECK( p7.y == Approx(7.5) ); + + // Test arithmetic compound assignment operators with wxSizes + wxSize s1(2, 3); + p7 += s1; + CHECK( p7.x == Approx(6.5) ); + CHECK( p7.y == Approx(10.5) ); + wxSize s2(3, 4); + p7 -= s2; + CHECK( p7.x == Approx(3.5) ); + CHECK( p7.y == Approx(6.5) ); }