gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog testsuite/actionscript.all/Matr...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog testsuite/actionscript.all/Matr...
Date: Tue, 10 Jun 2008 16:52:01 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/06/10 16:52:00

Modified files:
        .              : ChangeLog 
        testsuite/actionscript.all: Matrix.as 
        server/asobj/flash/geom: Matrix_as.cpp 

Log message:
                * server/asobj/flash/geom/Matrix_as.cpp: finish implementing
                  flash.geom.Matrix (createBox, createGradientBox, 
transformPoint).
                * server/testsuite/actionscript.all/Matrix_as.cpp: more tests.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6893&r2=1.6894
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Matrix.as?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/flash/geom/Matrix_as.cpp?cvsroot=gnash&r1=1.13&r2=1.14

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6893
retrieving revision 1.6894
diff -u -b -r1.6893 -r1.6894
--- ChangeLog   10 Jun 2008 14:25:32 -0000      1.6893
+++ ChangeLog   10 Jun 2008 16:51:59 -0000      1.6894
@@ -1,5 +1,11 @@
 2008-06-10 Benjamin Wolsey <address@hidden>
 
+       * server/asobj/flash/geom/Matrix_as.cpp: finish implementing
+         flash.geom.Matrix (createBox, createGradientBox, transformPoint).
+       * server/testsuite/actionscript.all/Matrix_as.cpp: more tests.
+
+2008-06-10 Benjamin Wolsey <address@hidden>
+
        * server/asobj/flash/geom/Point_as{.cpp.h},Matrix_as.cpp: drop auto_ptr
          for intrusive_ptr to pass a Point object.
        * server/testsuite/actionscript.all/Matrix_as.cpp: uncommitted tests.

Index: testsuite/actionscript.all/Matrix.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Matrix.as,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- testsuite/actionscript.all/Matrix.as        10 Jun 2008 14:25:33 -0000      
1.6
+++ testsuite/actionscript.all/Matrix.as        10 Jun 2008 16:52:00 -0000      
1.7
@@ -20,7 +20,7 @@
 // compile this test case with Ming makeswf, and then
 // execute it like this gnash -1 -r 0 -v out.swf
 
-rcsid="$Id: Matrix.as,v 1.6 2008/06/10 14:25:33 bwy Exp $";
+rcsid="$Id: Matrix.as,v 1.7 2008/06/10 16:52:00 bwy Exp $";
 
 
 // There are lots of floating point calculations here. Comparing them
@@ -201,6 +201,15 @@
 check_equals(m6.toString(), "(a=3.51033024756149, b=6.78504050247288, 
c=-1.91770215441681, d=1.99078511643085, tx=2, ty=3)");
 
 
+// Matrix.transformPoint (and deltaTransformPoint again)
+p = new Point(23, 95);
+p2 = m6.transformPoint(p);
+check_equals(p2.toString(), "(x=-99.4441089756828, y=348.180517617807)");
+p3 = m6.deltaTransformPoint(p);
+check_equals(p3.toString(), "(x=-101.444108975683, y=345.180517617807)");
+p2 = m6.transformPoint(p2);
+check_equals(p2.toString(), "(x=-1014.78819244077, y=21.420285172384)");
+
 // Rotation applies to translation
 m3 = new Matrix(1, 0, 0, 1, 2, 2);
 m3.rotate (Math.PI / 2);
@@ -233,10 +242,39 @@
 m7.rotate(2);
 check_equals(m7.toString(), "(a=NaN, b=NaN, c=NaN, d=NaN, tx=NaN, ty=NaN)");
 
+m8 = new Matrix(5, 4, 5, 3, 2, 1);
+check_equals(m8.toString(), "(a=5, b=4, c=5, d=3, tx=2, ty=1)");
+m8.createBox(4, 3, 4, 2, 3);
+check_equals(m8.toString(), "(a=-2.61457448345445, b=-2.27040748592378, 
c=3.02720998123171, d=-1.96093086259084, tx=2, ty=3)");
+m8.createBox(45, 444, -1.3874987, -47, -2999398);
+check_equals(m8.toString(), "(a=8.2022824555003, b=-436.562099487155, 
c=44.2461587318062, d=80.9291868942697, tx=-47, ty=-2999398)");
+m8.createBox(4, 3, new Object(), "a string");
+check_equals(m8.toString(), "(a=NaN, b=NaN, c=NaN, d=NaN, tx=a string, ty=0)");
+m8.createBox("a", "b");
+check_equals(m8.toString(), "(a=NaN, b=NaN, c=NaN, d=NaN, tx=0, ty=0)");
+
+m8.createGradientBox(20, 30, 2 * Math.PI, 10, 25);
+
+// The very small numbers aren't very 'accurate', of course.
+check_equals(m8.a.toString(), "0.01220703125");
+check_equals(m8.d.toString(), "0.018310546875");
+check_equals(m8.tx.toString(), "20");
+check_equals(m8.ty.toString(), "40");
+check(Math.abs(m8.b) < 0.0000000000001);
+check(Math.abs(m8.c) < 0.0000000000001);
+
+m8.createGradientBox(40, 49, 0, "string", undefined);
+// Half of the width is added to the translation - they take that quite 
literally...
+check_equals(m8.toString(), "(a=0.0244140625, b=0, c=0, d=0.0299072265625, 
tx=string20, ty=NaN)");
+m8.createGradientBox(5, 6, 0, 1, 1);
+check_equals(m8.toString(), "(a=0.0030517578125, b=0, c=0, d=0.003662109375, 
tx=3.5, ty=4)");
+m8.createGradientBox(5, 6, 2, 1, 1);
+check_equals(m8.toString(), "(a=-0.0012699793595799, b=0.00332994663144171, 
c=-0.00277495552620142, d=-0.00152397523149588, tx=3.5, ty=4)");
+
 //-------------------------------------------------------------
 // END OF TEST
 //-------------------------------------------------------------
 
-totals();
+totals(115);
 
 #endif // OUTPUT_VERSION >= 8

Index: server/asobj/flash/geom/Matrix_as.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/flash/geom/Matrix_as.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- server/asobj/flash/geom/Matrix_as.cpp       10 Jun 2008 12:59:25 -0000      
1.13
+++ server/asobj/flash/geom/Matrix_as.cpp       10 Jun 2008 16:52:00 -0000      
1.14
@@ -54,6 +54,7 @@
 namespace gnash {
 
 typedef boost::numeric::ublas::c_matrix<double, 3, 3> MatrixType;
+typedef boost::numeric::ublas::c_vector<double, 2> PointType;
 
 // Forward declarations
 static as_value Matrix_clone(const fn_call& fn);
@@ -68,8 +69,8 @@
 static as_value Matrix_toString(const fn_call& fn);
 static as_value Matrix_transformPoint(const fn_call& fn);
 static as_value Matrix_translate(const fn_call& fn);
-static void fillMatrix(MatrixType& matrix,
-                         as_object* const matrixObject);
+static void fillMatrix(MatrixType& matrix, as_object* const matrixObject);
+static PointType transformPoint(as_object* const pointObject, as_object* const 
matrixObject);
 
 as_value Matrix_ctor(const fn_call& fn);
 
@@ -178,13 +179,12 @@
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
 
-    if (fn.nargs != 1)
+    if (fn.nargs < 1)
     {
         IF_VERBOSE_ASCODING_ERRORS(
             std::ostringstream ss;
             fn.dump_args(ss);
-            log_aserror("Matrix.concat(%s) needs exactly one argument; "
-                        "%d were passed", ss.str(), fn.nargs);
+            log_aserror("Matrix.concat(%s): needs one argument", ss.str());
         );
         return as_value();
     }
@@ -235,31 +235,144 @@
 #endif 
     
     // Set values of current matrix
-    ptr->set_member(NSV::PROP_A, as_value(currentMatrix(0, 0)));
-    ptr->set_member(NSV::PROP_B, as_value(currentMatrix(1, 0)));
-    ptr->set_member(NSV::PROP_C, as_value(currentMatrix(0, 1)));
-    ptr->set_member(NSV::PROP_D, as_value(currentMatrix(1, 1)));
-    ptr->set_member(NSV::PROP_TX, as_value(currentMatrix(0, 2)));
-    ptr->set_member(NSV::PROP_TY, as_value(currentMatrix(1, 2)));
+    ptr->set_member(NSV::PROP_A, currentMatrix(0, 0));
+    ptr->set_member(NSV::PROP_B, currentMatrix(1, 0));
+    ptr->set_member(NSV::PROP_C, currentMatrix(0, 1));
+    ptr->set_member(NSV::PROP_D, currentMatrix(1, 1));
+    ptr->set_member(NSV::PROP_TX, currentMatrix(0, 2));
+    ptr->set_member(NSV::PROP_TY, currentMatrix(1, 2));
 
     return as_value();
 }
 
+
+/// Creates a matrix from (X scale, Y scale, rotation, X translation, Y 
translation)
+/// The translation values can be any as_value; the others (because 
mathematical
+/// operations are applied to them), result in NaN if anything other than a 
number
+/// is passed, so we treat them as doubles from the beginning.
 static as_value
 Matrix_createBox(const fn_call& fn)
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
-    UNUSED(ptr);
-    LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (fn.nargs < 2)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.createBox(%s): needs at least two arguments", 
ss.str());
+        );
+        return as_value();
+    }
+
+    double scaleX, scaleY;
+
+    // Default values for optional arguments    
+    double rotation = 0;
+    as_value tx, ty;
+    tx.set_double(0);
+    ty.set_double(0);
+    
+    switch (fn.nargs)
+    {
+        default:
+            // Log as coding error
+        case 5:
+            ty = fn.arg(4);
+        case 4:
+            tx = fn.arg(3);
+        case 3:
+            rotation = fn.arg(2).to_number();
+        case 2:
+            // There must be a minimum of 2 arguments.
+            scaleY = fn.arg(1).to_number();
+            scaleX = fn.arg(0).to_number();
+            break;
+    }
+    
+    
+    const double a = std::cos(rotation) * scaleX;
+    const double b = std::sin(rotation) * scaleY;
+    const double c = -std::sin(rotation) * scaleX;
+    const double d = std::cos(rotation) * scaleY;
+    
+    ptr->set_member(NSV::PROP_A, as_value(a));
+    ptr->set_member(NSV::PROP_B, as_value(b));
+    ptr->set_member(NSV::PROP_C, as_value(c));
+    ptr->set_member(NSV::PROP_D, as_value(d));
+    ptr->set_member(NSV::PROP_TX, tx);
+    ptr->set_member(NSV::PROP_TY, ty);
+    
     return as_value();
 }
 
+
+// Like createBox, but with strange offsets applied.
 static as_value
 Matrix_createGradientBox(const fn_call& fn)
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
-    UNUSED(ptr);
-    LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (fn.nargs < 2)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.createGradientBox(%s): needs at least two 
arguments", ss.str());
+        );
+        return as_value();
+    }
+
+    double widthX, widthY;
+
+    // Default values for optional arguments    
+    double rotation = 0;
+    as_value tx, ty;
+    tx.set_double(0);
+    ty.set_double(0);
+    
+    switch (fn.nargs)
+    {
+        default:
+            // Log as coding error
+        case 5:
+            ty = fn.arg(4);
+        case 4:
+            tx = fn.arg(3);
+        case 3:
+            rotation = fn.arg(2).to_number();
+        case 2:
+            // There must be a minimum of 2 arguments.
+            widthY = fn.arg(1).to_number();
+            widthX = fn.arg(0).to_number();
+            break;
+    }
+    
+    // A bit of a magic number: the maximum positive co-ordinate of
+    // a gradient square.
+    const double gradientSquareMax = 16384.0;
+    
+    const double a = std::cos(rotation) * widthX * 10 / gradientSquareMax;
+    const double b = std::sin(rotation) * widthY * 10 / gradientSquareMax;
+    const double c = -std::sin(rotation) * widthX * 10 / gradientSquareMax;
+    const double d = std::cos(rotation) * widthY * 10 / gradientSquareMax;
+    
+    ptr->set_member(NSV::PROP_A, as_value(a));
+    ptr->set_member(NSV::PROP_B, as_value(b));
+    ptr->set_member(NSV::PROP_C, as_value(c));
+    ptr->set_member(NSV::PROP_D, as_value(d));
+    
+    // The translation is offset by half the size of the corresponding
+    // dimension. Or rather, half the dimension is added to the translation,
+    // whether it's a number or not.
+    tx.newAdd(widthX / 2.0);
+    ty.newAdd(widthY / 2.0);
+
+    ptr->set_member(NSV::PROP_TX, tx);
+    ptr->set_member(NSV::PROP_TY, ty);
+    
+    return as_value();
+
     return as_value();
 }
 
@@ -273,9 +386,13 @@
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
 
-    if (fn.nargs != 1)
+    if (fn.nargs < 1)
     {
-        //log error
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.deltaTransformPoint(%s): needs one argument", 
ss.str());
+        );
         return as_value();
     }
 
@@ -305,45 +422,9 @@
         return as_value();
     }
 
-    // Get the point co-ordinates.
-    as_value x, y;
-    
-    obj->get_member(NSV::PROP_X, &x);
-    obj->get_member(NSV::PROP_Y, &y);
-
-    // Get the matrix elements to use as a transformation matrix.
-    as_value a, b, c, d;
-
-    ptr->get_member(NSV::PROP_A, &a);
-    ptr->get_member(NSV::PROP_B, &b);
-    ptr->get_member(NSV::PROP_C, &c);
-    ptr->get_member(NSV::PROP_D, &d);
+    const PointType& point = transformPoint(obj, ptr.get());
 
-    // Construct the matrix
-    boost::numeric::ublas::c_matrix<double, 2, 2> transformMatrix;
-    transformMatrix(0, 0) = a.to_number();
-    transformMatrix(0, 1) = b.to_number();
-    transformMatrix(1, 0) = c.to_number();
-    transformMatrix(1, 1) = d.to_number();
-
-    // Construct the point
-    boost::numeric::ublas::c_vector<double, 2> point;
-    point(0) = x.to_number();
-    point(1) = y.to_number();
-
-#ifdef GNASH_DEBUG_GEOM_MATRIX
-    log_debug("(Matrix.deltaTransformPoint) This matrix: %s", transformMatrix);
-    log_debug("(Matrix.deltaTransformPoint) Point vector (pre-transform): %s", 
point);
-#endif
-
-    // Transform
-    point = boost::numeric::ublas::prod(point, transformMatrix);
-
-#ifdef GNASH_DEBUG_GEOM_MATRIX
-    log_debug("(Matrix.deltaTransformPoint) Point vector (post-transform): 
%s", point);
-#endif
-
-    // Get an auto_ptr to a Point and pretend to keep alive.
+    // Construct a Point and set its properties.
     boost::intrusive_ptr<as_object> ret = init_Point_instance();
     ret->set_member(NSV::PROP_X, point(0));
     ret->set_member(NSV::PROP_Y, point(1));
@@ -363,12 +444,12 @@
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
 
-    ptr->set_member(NSV::PROP_A, as_value(1.0));
-    ptr->set_member(NSV::PROP_B, as_value(0.0));
-    ptr->set_member(NSV::PROP_C, as_value(0.0));
-    ptr->set_member(NSV::PROP_D, as_value(1.0));
-    ptr->set_member(NSV::PROP_TX, as_value(0.0));
-    ptr->set_member(NSV::PROP_TY, as_value(0.0));
+    ptr->set_member(NSV::PROP_A, 1.0);
+    ptr->set_member(NSV::PROP_B, 0.0);
+    ptr->set_member(NSV::PROP_C, 0.0);
+    ptr->set_member(NSV::PROP_D, 1.0);
+    ptr->set_member(NSV::PROP_TX, 0.0);
+    ptr->set_member(NSV::PROP_TY, 0.0);
 
     return as_value();
 }
@@ -398,12 +479,12 @@
     if (determinant == 0)
     {
         // Return the identity matrix
-        ptr->set_member(NSV::PROP_A, as_value(1.0));
-        ptr->set_member(NSV::PROP_B, as_value(0.0));
-        ptr->set_member(NSV::PROP_C, as_value(0.0));
-        ptr->set_member(NSV::PROP_D, as_value(1.0));
-        ptr->set_member(NSV::PROP_TX, as_value(0.0));
-        ptr->set_member(NSV::PROP_TY, as_value(0.0)); 
+        ptr->set_member(NSV::PROP_A, 1.0);
+        ptr->set_member(NSV::PROP_B, 0.0);
+        ptr->set_member(NSV::PROP_C, 0.0);
+        ptr->set_member(NSV::PROP_D, 1.0);
+        ptr->set_member(NSV::PROP_TX, 0.0);
+        ptr->set_member(NSV::PROP_TY, 0.0); 
         return as_value();  
     }
     
@@ -432,8 +513,16 @@
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
 
-    if (fn.nargs == 1)
+    if (fn.nargs < 1)
     {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.rotate(%s): needs one argument", ss.str());
+        );
+        return as_value();
+    }
+
         // Make rotation matrix
         boost::numeric::ublas::c_matrix<double, 2, 2> transformMatrix;
         
@@ -479,15 +568,14 @@
         ptr->set_member(NSV::PROP_D, as_value(currentMatrix(1, 1)));
 
         // Do rotation separately.
-        boost::numeric::ublas::c_vector<double, 2> translation;
+    PointType translation;
         translation(0) = tx.to_number();
         translation(1) = ty.to_number();
         
         translation = boost::numeric::ublas::prod(translation, 
transformMatrix);
 
-        ptr->set_member(NSV::PROP_TX, as_value(translation(0)));
-        ptr->set_member(NSV::PROP_TY, as_value(translation(1)));  
-    }      
+    ptr->set_member(NSV::PROP_TX, translation(0));
+    ptr->set_member(NSV::PROP_TY, translation(1));  
 
     return as_value();
 }
@@ -496,8 +584,17 @@
 Matrix_scale(const fn_call& fn)
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
-    if (fn.nargs == 2)
+
+    if (fn.nargs < 2)
     {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.translate(%s): needs two arguments", ss.str());
+        );
+        return as_value();
+    }
+
         // Make scale matrix
         boost::numeric::ublas::c_matrix<double, 2, 2> transformMatrix;
         
@@ -538,15 +635,14 @@
         log_debug("(Matrix.scale) This matrix (post-transform): %s", 
currentMatrix);
 #endif
 
-        ptr->set_member(NSV::PROP_A, as_value(currentMatrix(0, 0)));
-        ptr->set_member(NSV::PROP_B, as_value(currentMatrix(0, 1)));
-        ptr->set_member(NSV::PROP_C, as_value(currentMatrix(1, 0)));
-        ptr->set_member(NSV::PROP_D, as_value(currentMatrix(1, 1)));
+    ptr->set_member(NSV::PROP_A, currentMatrix(0, 0));
+    ptr->set_member(NSV::PROP_B, currentMatrix(0, 1));
+    ptr->set_member(NSV::PROP_C, currentMatrix(1, 0));
+    ptr->set_member(NSV::PROP_D, currentMatrix(1, 1));
 
         // This is just a simple multiplication, so do it separately.
         ptr->set_member(NSV::PROP_TX, as_value(tx.to_number() * scaleX));
         ptr->set_member(NSV::PROP_TY, as_value(ty.to_number() * scaleY));  
-    }      
 
     return as_value();
 }
@@ -581,15 +677,71 @@
 Matrix_transformPoint(const fn_call& fn)
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
-    UNUSED(ptr);
-    LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+    if (fn.nargs < 1)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.translate(%s): needs one argument", ss.str());
+        );
     return as_value();
+    }
+
+    const as_value& arg = fn.arg(0);
+    
+    if ( ! arg.is_object() )
+    {
+        /// Isn't an object...
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.transformPoint(%s): needs an object", 
ss.str());
+        );
+        return as_value();
+    }
+    
+    as_object* obj = arg.to_object().get();
+    assert(obj);
+    if ( ! obj->instanceOf(getFlashGeomPointConstructor()) )
+    {
+        /// Isn't a point.
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.transformPoint(%s): object must be a Point", 
ss.str());
+        );
+        return as_value();
+    }
+
+    as_value tx, ty;
+    ptr->get_member(NSV::PROP_TX, &tx);
+    ptr->get_member(NSV::PROP_TY, &ty);
+    
+    const PointType& point = transformPoint(obj, ptr.get());
+
+    boost::intrusive_ptr<as_object> ret = init_Point_instance();
+    ret->set_member(NSV::PROP_X, point(0) + tx.to_number());
+    ret->set_member(NSV::PROP_Y, point(1) + ty.to_number());
+
+    return as_value(ret.get());
 }
 
 static as_value
 Matrix_translate(const fn_call& fn)
 {
     boost::intrusive_ptr<Matrix_as> ptr = ensureType<Matrix_as>(fn.this_ptr);
+    
+    if (fn.nargs < 2)
+    {
+        IF_VERBOSE_ASCODING_ERRORS(
+            std::ostringstream ss;
+            fn.dump_args(ss);
+            log_aserror("Matrix.translate(%s): needs two arguments", ss.str());
+        );
+        return as_value();    
+    }
+    
     if (fn.nargs == 2)
     {
 
@@ -607,6 +759,54 @@
     return as_value();
 }
 
+// A helper function to transform a point using a matrix object,
+// after which the translation can be applied if necessary
+// (transformPoint) or not if not (deltaTransformPoint). Just
+// make sure the objects are what they're supposed to be.
+static PointType
+transformPoint(as_object* const pointObject, as_object* const matrixObject)
+{
+    // Get the point co-ordinates.
+    as_value x, y;
+    
+    pointObject->get_member(NSV::PROP_X, &x);
+    pointObject->get_member(NSV::PROP_Y, &y);
+
+    // Get the matrix elements to use as a transformation matrix.
+    as_value a, b, c, d;
+
+    matrixObject->get_member(NSV::PROP_A, &a);
+    matrixObject->get_member(NSV::PROP_B, &b);
+    matrixObject->get_member(NSV::PROP_C, &c);
+    matrixObject->get_member(NSV::PROP_D, &d);
+
+    // Construct the matrix
+    boost::numeric::ublas::c_matrix<double, 2, 2> transformMatrix;
+    transformMatrix(0, 0) = a.to_number();
+    transformMatrix(0, 1) = b.to_number();
+    transformMatrix(1, 0) = c.to_number();
+    transformMatrix(1, 1) = d.to_number();
+
+    // Construct the point
+    PointType point;
+    point(0) = x.to_number();
+    point(1) = y.to_number();
+
+#ifdef GNASH_DEBUG_GEOM_MATRIX
+    log_debug("(Matrix.{delta}TransformPoint) This matrix: %s", 
transformMatrix);
+    log_debug("(Matrix.{delta}TransformPoint) Point vector (pre-transform): 
%s", point);
+#endif
+
+    // Transform
+    point = boost::numeric::ublas::prod(point, transformMatrix);
+
+#ifdef GNASH_DEBUG_GEOM_MATRIX
+    log_debug("(Matrix.{delta}TransformPoint) Point vector (post-transform): 
%s", point);
+#endif
+
+    return point;
+
+}
 
 // A helper function to create a boost matrix from a Matrix object
 static void fillMatrix(MatrixType& matrix,
@@ -645,7 +845,7 @@
     
     as_value a, b, c, d, tx, ty;
 
-    if ( ! fn.nargs )
+    if (fn.nargs  == 0)
     {
         a.set_double(1);
         b.set_double(0);
@@ -659,7 +859,7 @@
         switch (fn.nargs)
         {
             default:
-                // Log as coding error
+                // Log as coding error?
             case 6:
                 ty = fn.arg(5);
             case 5:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]