Simplifying arithmetic and comparison operator implementation.
authorMarc Rollins <mrollins@gravityjack.com>
Mon, 18 Aug 2014 19:25:48 +0000 (12:25 -0700)
committerMarc Rollins <mrollins@gravityjack.com>
Mon, 18 Aug 2014 19:25:48 +0000 (12:25 -0700)
Implementing + and - in terms of += and -=.
Implementing != in terms of ==.

modules/core/include/opencv2/core/types.hpp

index b8f9434..ea7b4dc 100644 (file)
@@ -1342,30 +1342,32 @@ Size_<_Tp> operator / (Size_<_Tp> a, _Tp b)
 }
 
 template<typename _Tp> static inline
-Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b)
+Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b)
 {
-    return Size_<_Tp>(a.width + b.width, a.height + b.height);
+    a.width += b.width;
+    a.height += b.height;
+    return a;
 }
 
 template<typename _Tp> static inline
-Size_<_Tp> operator - (const Size_<_Tp>& a, const Size_<_Tp>& b)
+Size_<_Tp> operator + (Size_<_Tp> a, const Size_<_Tp>& b)
 {
-    return Size_<_Tp>(a.width - b.width, a.height - b.height);
+    a += b;
+    return a;
 }
 
 template<typename _Tp> static inline
-Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b)
+Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b)
 {
-    a.width += b.width;
-    a.height += b.height;
+    a.width -= b.width;
+    a.height -= b.height;
     return a;
 }
 
 template<typename _Tp> static inline
-Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b)
+Size_<_Tp> operator - (Size_<_Tp> a, const Size_<_Tp>& b)
 {
-    a.width -= b.width;
-    a.height -= b.height;
+    a -= b;
     return a;
 }
 
@@ -1378,7 +1380,7 @@ bool operator == (const Size_<_Tp>& a, const Size_<_Tp>& b)
 template<typename _Tp> static inline
 bool operator != (const Size_<_Tp>& a, const Size_<_Tp>& b)
 {
-    return a.width != b.width || a.height != b.height;
+    return !(a == b);
 }