gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/flash/geom/Point_a...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/flash/geom/Point_a...
Date: Mon, 19 May 2008 15:59:26 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/05/19 15:59:25

Modified files:
        .              : ChangeLog 
        server/asobj/flash/geom: Point_as.cpp 
        testsuite/actionscript.all: Point.as 

Log message:
        And..
                * server/asobj/flash/geom/Point_as.cpp:
                  Implement Point.normalize(), Point.offset(), Point.subtract()
                  and Point.polar().
                * testsuite/actionscript.all/Point.as:
                  Test Point.normalize(), Point.offset(), Point.subtract()
                  and Point.polar().
        
        ... flash.geom.Point is complete now.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6649&r2=1.6650
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/flash/geom/Point_as.cpp?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Point.as?cvsroot=gnash&r1=1.4&r2=1.5

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6649
retrieving revision 1.6650
diff -u -b -r1.6649 -r1.6650
--- ChangeLog   19 May 2008 14:37:03 -0000      1.6649
+++ ChangeLog   19 May 2008 15:59:25 -0000      1.6650
@@ -1,3 +1,12 @@
+2008-05-19 Sandro Santilli <address@hidden>
+
+       * server/asobj/flash/geom/Point_as.cpp: 
+         Implement Point.normalize(), Point.offset(), Point.subtract()
+         and Point.polar().
+       * testsuite/actionscript.all/Point.as:
+         Test Point.normalize(), Point.offset(), Point.subtract()
+         and Point.polar().
+
 2008-05-19 Benjamin Wolsey <address@hidden>
 
        * po/Makefile.am, po/ja.po: add Japanese translation by 

Index: server/asobj/flash/geom/Point_as.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/flash/geom/Point_as.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- server/asobj/flash/geom/Point_as.cpp        19 May 2008 14:12:16 -0000      
1.11
+++ server/asobj/flash/geom/Point_as.cpp        19 May 2008 15:59:25 -0000      
1.12
@@ -127,13 +127,13 @@
        }
        else
        {
+               IF_VERBOSE_ASCODING_ERRORS(
                if ( fn.nargs > 1 )
                {
-                       IF_VERBOSE_ASCODING_ERRORS(
                        std::stringstream ss; fn.dump_args(ss);
                        log_aserror("Point.add(%s): %s", ss.str(), _("arguments 
after first discarded"));
-                       );
                }
+               );
                as_value& arg1 = fn.arg(0);
                as_object* o = arg1.to_object().get();
                if ( ! o )
@@ -238,8 +238,53 @@
 Point_normalize(const fn_call& fn)
 {
        boost::intrusive_ptr<Point_as> ptr = ensureType<Point_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+       as_value argval;
+
+       if ( ! fn.nargs )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               log_aserror(_("%s: missing arguments"), "Point.normalize()");
+               );
+               return as_value();
+       }
+       else
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               if ( fn.nargs > 1 )
+               {
+                       std::stringstream ss; fn.dump_args(ss);
+                       log_aserror("Point.normalize(%s): %s", ss.str(), 
_("arguments after first discarded"));
+               }
+               );
+
+               argval = fn.arg(0);
+       }
+
+       // newlen may be NaN, and we'd still be updating x/y
+       // see actionscript.all/Point.as
+       double newlen = argval.to_number();
+
+       as_value xval, yval;
+       ptr->get_member(NSV::PROP_X, &xval);
+       ptr->get_member(NSV::PROP_Y, &yval);
+
+       double x = xval.to_number();
+       if ( ! utility::isFinite(x) ) return as_value();
+       double y = yval.to_number();
+       if ( ! utility::isFinite(y) ) return as_value();
+
+       if ( x == 0 && y == 0 ) return as_value();
+
+       double curlen = sqrt(x*x+y*y);
+       double fact = newlen/curlen;
+
+
+       xval.set_double( xval.to_number() * fact );
+       yval.set_double( yval.to_number() * fact );
+       ptr->set_member(NSV::PROP_X, xval);
+       ptr->set_member(NSV::PROP_Y, yval);
+
        return as_value();
 }
 
@@ -247,8 +292,24 @@
 Point_offset(const fn_call& fn)
 {
        boost::intrusive_ptr<Point_as> ptr = ensureType<Point_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+
+       as_value x, y;
+       ptr->get_member(NSV::PROP_X, &x);
+       ptr->get_member(NSV::PROP_Y, &y);
+
+       as_value xoff, yoff;
+
+       if ( fn.nargs ) {
+               xoff = fn.arg(0);
+               if ( fn.nargs > 1 ) yoff = fn.arg(1);
+       }
+
+       x.newAdd(xoff);
+       y.newAdd(yoff);
+
+       ptr->set_member(NSV::PROP_X, x);
+       ptr->set_member(NSV::PROP_Y, y);
+
        return as_value();
 }
 
@@ -256,9 +317,66 @@
 Point_subtract(const fn_call& fn)
 {
        boost::intrusive_ptr<Point_as> ptr = ensureType<Point_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
-       return as_value();
+
+       as_value x, y;
+       ptr->get_member(NSV::PROP_X, &x);
+       ptr->get_member(NSV::PROP_Y, &y);
+
+       as_value x1, y1;
+
+       if ( ! fn.nargs )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               log_aserror(_("%s: missing arguments"), "Point.add()");
+               );
+       }
+       else
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               if ( fn.nargs > 1 )
+               {
+                       std::stringstream ss; fn.dump_args(ss);
+                       log_aserror("Point.add(%s): %s", ss.str(), _("arguments 
after first discarded"));
+               }
+               );
+               as_value& arg1 = fn.arg(0);
+               as_object* o = arg1.to_object().get();
+               if ( ! o )
+               {
+                       IF_VERBOSE_ASCODING_ERRORS(
+                       std::stringstream ss; fn.dump_args(ss);
+                       log_aserror("Point.add(%s): %s", ss.str(), _("first 
argument doesn't cast to object"));
+                       );
+               }
+               else
+               {
+                       if ( ! o->get_member(NSV::PROP_X, &x1) )
+                       {
+                               IF_VERBOSE_ASCODING_ERRORS(
+                               std::stringstream ss; fn.dump_args(ss);
+                               log_aserror("Point.add(%s): %s", ss.str(),
+                                       _("first argument casted to object 
doesn't contain an 'x' member"));
+                               );
+                       }
+                       if ( ! o->get_member(NSV::PROP_Y, &y1) )
+                       {
+                               IF_VERBOSE_ASCODING_ERRORS(
+                               std::stringstream ss; fn.dump_args(ss);
+                               log_aserror("Point.add(%s): %s", ss.str(),
+                                       _("first argument casted to object 
doesn't contain an 'y' member"));
+                               );
+                       }
+               }
+       }
+
+       x.set_double(x.to_number() - x1.to_number());
+       y.set_double(y.to_number() - y1.to_number());
+
+       boost::intrusive_ptr<as_object> ret = new Point_as;
+       ret->set_member(NSV::PROP_X, x);
+       ret->set_member(NSV::PROP_Y, y);
+
+       return as_value(ret.get());
 }
 
 static as_value
@@ -468,10 +586,43 @@
 static as_value
 Point_polar(const fn_call& fn)
 {
-       boost::intrusive_ptr<Point_as> ptr = ensureType<Point_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
-       return as_value();
+       as_value lval; // length
+       as_value aval; // angle (radians)
+
+       if ( fn.nargs )
+       {
+               lval=fn.arg(0);
+               if ( fn.nargs > 1 ) aval=fn.arg(1);
+               else
+               {
+                       IF_VERBOSE_ASCODING_ERRORS(
+                       std::stringstream ss; fn.dump_args(ss);
+                       log_aserror("Point.polar(%s): %s", ss.str(), _("missing 
arguments"));
+                       );
+               }
+       }
+       else
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("Point.polar(%s): %s", ss.str(), _("missing 
arguments"));
+               );
+       }
+       
+       double len = lval.to_number();
+       double angle = aval.to_number();
+
+       double x = len * std::cos(angle);
+       double y = len * std::sin(angle);
+
+       as_value xval(x);
+       as_value yval(y);
+       boost::intrusive_ptr<as_object> obj = new Point_as;
+
+       obj->set_member(NSV::PROP_X, x);
+       obj->set_member(NSV::PROP_Y, y);
+       
+       return as_value(obj.get());
 }
 
 

Index: testsuite/actionscript.all/Point.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Point.as,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/actionscript.all/Point.as 19 May 2008 14:12:16 -0000      1.4
+++ testsuite/actionscript.all/Point.as 19 May 2008 15:59:25 -0000      1.5
@@ -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: Point.as,v 1.4 2008/05/19 14:12:16 strk Exp $";
+rcsid="$Id: Point.as,v 1.5 2008/05/19 15:59:25 strk Exp $";
 
 #include "check.as"
 
@@ -318,36 +318,164 @@
 check_equals(ret.toString(), '(x=5, y=5)');
 
 
-// TODO
-
 //-------------------------------------------------------------
 // Test Point.normalize
 //-------------------------------------------------------------
 
-// TODO
+p0 = new Point(0, 0);
+p1 = p0.clone();
+ret = p1.normalize();
+check_equals(typeof(ret), 'undefined');
+check(p1.equals(p0));
+
+p0 = new Point(0, 0);
+p1 = p0.clone();
+ret = p1.normalize(10);
+check_equals(typeof(ret), 'undefined');
+check(p1.equals(p0));
+
+p0 = new Point(10, 0);
+p1 = p0.clone();
+ret = p1.normalize(5);
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=5, y=0)');
+
+p0 = new Point(0, 10);
+p1 = p0.clone();
+ret = p1.normalize(-5);
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=0, y=-5)');
+
+p0 = new Point(3, -4);
+p1 = p0.clone();
+ret = p1.normalize(-10);
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=-6, y=8)');
+
+p0 = new Point(-10, 0);
+p1 = p0.clone();
+ret = p1.normalize(5);
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=-5, y=0)');
+
+p0 = new Point(-10, 0);
+p1 = p0.clone();
+ret = p1.normalize('r');
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=NaN, y=NaN)');
+
+p0 = new Point('x', 'y');
+p1 = p0.clone();
+ret = p1.normalize(5);
+check_equals(typeof(ret), 'undefined');
+check_equals(p1.toString(), '(x=x, y=y)');
 
 //-------------------------------------------------------------
 // Test Point.offset
 //-------------------------------------------------------------
 
-// TODO
+p0 = new Point('x', 'y');
+ret = p0.offset();
+check_equals(typeof(ret), 'undefined');
+check_equals(p0.toString(), '(x=xundefined, y=yundefined)');
+
+p0 = new Point('x', 'y');
+ret = p0.offset('a');
+check_equals(typeof(ret), 'undefined');
+check_equals(p0.toString(), '(x=xa, y=yundefined)');
+
+p0 = new Point('x', 'y');
+ret = p0.offset('a', 'b', 3);
+check_equals(typeof(ret), 'undefined');
+check_equals(p0.toString(), '(x=xa, y=yb)');
+
+p0 = new Point(4, 5);
+ret = p0.offset('-6', -8);
+check_equals(typeof(ret), 'undefined');
+check_equals(p0.toString(), '(x=4-6, y=-3)');
 
 //-------------------------------------------------------------
 // Test Point.polar (static)
 //-------------------------------------------------------------
 
-// TODO
+p0 = Point.polar();
+check(p0 instanceof Point);
+check_equals(p0.toString(), '(x=NaN, y=NaN)');
+
+p0 = Point.polar(1);
+check(p0 instanceof Point);
+check_equals(p0.toString(), '(x=NaN, y=NaN)');
+
+p0 = Point.polar(1, 0);
+check(p0 instanceof Point);
+check_equals(p0.toString(), '(x=1, y=0)');
+
+p0 = Point.polar(1, Math.PI);
+check(p0 instanceof Point);
+check_equals(p0.x, -1);
+check_equals(Math.round(p0.y*100), 0);
+
+p0 = Point.polar(1, Math.PI/2);
+check(p0 instanceof Point);
+check_equals(Math.round(p0.x*100), 0);
+check_equals(p0.y, 1);
+
+p0 = Point.polar(1, Math.PI*2);
+check(p0 instanceof Point);
+check_equals(p0.x, 1);
+check_equals(Math.round(p0.y*100), 0);
+
+p0 = Point.polar(1, Math.PI*1.5);
+check(p0 instanceof Point);
+check_equals(Math.round(p0.x*100), 0);
+check_equals(p0.y, -1);
+
+p0 = Point.polar('5', '0');
+check(p0 instanceof Point);
+check_equals(p0.x, 5);
+check_equals(p0.y, 0);
+
 
 //-------------------------------------------------------------
 // Test Point.subtract
 //-------------------------------------------------------------
 
-// TODO
+p0 = new Point('x', 'y');
+ret = p0.subtract();
+check(ret instanceof Point);
+check_equals(p0.toString(), '(x=x, y=y)');
+check_equals(ret.toString(), '(x=NaN, y=NaN)');
+String.prototype.x = 3; // to test it's used
+ret = p0.subtract('1');
+delete String.prototype.x;
+check(ret instanceof Point);
+check_equals(ret.toString(), '(x=NaN, y=NaN)');
+check_equals(p0.toString(), '(x=x, y=y)');
+ret = p0.subtract(1, '2');
+check(ret instanceof Point);
+check_equals(ret.toString(), '(x=NaN, y=NaN)');
+check_equals(p0.toString(), '(x=x, y=y)');
+
+p0 = new Point('x', 'y');
+p1 = new Point('x1', 'y1');
+ret = p0.subtract(p1);
+check(ret instanceof Point);
+check_equals(ret.toString(), '(x=NaN, y=NaN)');
+check_equals(p0.toString(), '(x=x, y=y)');
+check_equals(p1.toString(), '(x=x1, y=y1)');
+
+p0 = new Point(2, 3);
+p1 = { x:1, y:1 };
+ret = p0.subtract(p1);
+check_equals(ret.toString(), '(x=1, y=2)');
+
+ret = p0.subtract(p1, 4, 5, 6);
+check_equals(ret.toString(), '(x=1, y=2)');
 
 //-------------------------------------------------------------
 // END OF TEST
 //-------------------------------------------------------------
 
-check_totals(116);
+check_totals(176);
 
 #endif // OUTPUT_VERSION >= 8




reply via email to

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