vector: changed conversion constructor to conversion operator
authorsub.mohanty@samsung.com <smohantty@gmail.com>
Sun, 21 Jul 2019 06:24:28 +0000 (15:24 +0900)
committerHermet Park <hermetpark@gmail.com>
Tue, 23 Jul 2019 04:45:39 +0000 (13:45 +0900)
src/vector/vrect.h

index 3d13a4cc14ea14c2a6caf848e2a4fd9a83eb8541..1b1f59bb85422e2182e250d91c16f2b77efff383 100644 (file)
@@ -29,7 +29,7 @@ public:
     VRect() = default;
     VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
     explicit VRect(VPoint pt, VSize sz):VRect(pt.x(), pt.y(), sz.width(), sz.height()){}
-    explicit VRect(const VRectF &r);
+    operator VRectF() const;
     V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
     V_CONSTEXPR int left() const {return x1;}
     V_CONSTEXPR int top() const {return y1;}
@@ -120,8 +120,9 @@ public:
     VRectF(double x, double y, double w, double h):
         x1(float(x)),y1(float(y)),
         x2(float(x+w)),y2(float(y+h)){}
-
-    explicit VRectF(const VRect &r):VRectF(r.x(), r.y(), r.width(), r.height()){}
+    operator VRect() const {
+        return {int(left()), int(right()), int(width()), int(height())};
+    }
 
     V_CONSTEXPR bool  empty() const {return x1 >= x2 || y1 >= y2;}
     V_CONSTEXPR float left() const {return x1;}
@@ -157,8 +158,11 @@ private:
     float y2{0};
 };
 
-inline VRect::VRect(const VRectF &r):x1(int(r.left())),y1(int(r.top())),
-                                     x2(int(r.right())),y2(int(r.bottom())){}
+inline VRect::operator VRectF() const
+{
+       return {double(left()), double(right()), double(width()), double(height())};
+}
+
 V_END_NAMESPACE
 
 #endif  // VRECT_H