add Make to SkTSize
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 11 Feb 2010 11:09:39 +0000 (11:09 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 11 Feb 2010 11:09:39 +0000 (11:09 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@497 2bbb7eff-a529-9590-31e7-b0007b416f81

include/core/SkSize.h
tests/PathTest.cpp

index d432102..dae6fe9 100644 (file)
@@ -7,6 +7,13 @@ template <typename T> struct SkTSize {
     T fWidth;
     T fHeight;
 
+    static SkTSize Make(T w, T h) {
+        SkTSize s;
+        s.fWidth = w;
+        s.fHeight = h;
+        return s;
+    }
+
     void set(T w, T h) {
         fWidth = w;
         fHeight = h;
@@ -58,11 +65,13 @@ static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-struct SkISize : public SkTSize<int32_t> {};
+typedef SkTSize<int32_t> SkISize;
 
 #include "SkScalar.h"
 
 struct SkSize : public SkTSize<SkScalar> {
+    SkSize(const SkTSize<SkScalar& src) : fWidth(src.fWidth), fHeight(src.fHeight) {}
+
     SkSize& operator=(const SkISize& src) {
         this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight));
         return *this;
index 89fe93b..9f26d01 100644 (file)
@@ -1,5 +1,6 @@
 #include "Test.h"
 #include "SkPath.h"
+#include "SkSize.h"
 
 static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
                                 const SkRect& bounds) {
@@ -17,6 +18,16 @@ static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
 }
 
 static void TestPath(skiatest::Reporter* reporter) {
+    {
+        SkSize size;
+        size.fWidth = 3.4f;
+        size.width();
+        size = SkSize::Make(3,4);
+        SkISize isize = SkISize::Make(3,4);
+    }
+
+    SkTSize<SkScalar>::Make(3,4);
+
     SkPath  p, p2;
     SkRect  bounds, bounds2;