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 11:51:41 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/05/19 11:51:41

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

Log message:
        Implement and test flash.geom.Point.distance()

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6643&r2=1.6644
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/flash/geom/Point_as.cpp?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Point.as?cvsroot=gnash&r1=1.2&r2=1.3

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6643
retrieving revision 1.6644
diff -u -b -r1.6643 -r1.6644
--- ChangeLog   19 May 2008 11:05:26 -0000      1.6643
+++ ChangeLog   19 May 2008 11:51:40 -0000      1.6644
@@ -1,5 +1,10 @@
 2008-05-19 Sandro Santilli <address@hidden>
 
+       * server/asobj/flash/geom/Point_as.cpp: implement Point.distance().
+       * testsuite/actionscript.all/Point.as: test Point.distance().
+
+2008-05-19 Sandro Santilli <address@hidden>
+
        * server/asobj/flash/geom/Point_as.cpp: implement Point.add(),
          Point.equals() and Point.clone()
        * testsuite/actionscript.all/Point.as: test Point.add(),

Index: server/asobj/flash/geom/Point_as.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/flash/geom/Point_as.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- server/asobj/flash/geom/Point_as.cpp        19 May 2008 11:05:27 -0000      
1.9
+++ server/asobj/flash/geom/Point_as.cpp        19 May 2008 11:51:41 -0000      
1.10
@@ -308,10 +308,67 @@
 static as_value
 Point_distance(const fn_call& fn)
 {
-       boost::intrusive_ptr<Point_as> ptr = ensureType<Point_as>(fn.this_ptr);
-       UNUSED(ptr);
-       LOG_ONCE( log_unimpl (__FUNCTION__) );
+       if ( fn.nargs < 2 )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("Point.distance(%s): %s", ss.str(), _("missing 
arguments"));
+               );
+               return as_value();
+       }
+
+       as_value& arg1 = fn.arg(0);
+       if ( ! arg1.is_object() )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("Point.distance(%s): %s", ss.str(), _("First arg 
must be an object"));
+               );
+               return as_value();
+       }
+       as_object* o1 = arg1.to_object().get();
+       assert(o1);
+       if ( ! o1->instanceOf(getFlashGeomPointConstructor()) )
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+               std::stringstream ss; fn.dump_args(ss);
+               log_aserror("Point.equals(%s): %s %s", ss.str(), _("First arg 
must be an instance of"), "flash.geom.Point");
+               );
        return as_value();
+       }
+
+       as_value& arg2 = fn.arg(1);
+       as_object* o2 = arg2.to_object().get();
+       assert(o2);
+       // it seems there's no need to check arg2 (see 
actionscript.all/Point.as)
+
+       as_value x1val;
+       o1->get_member(NSV::PROP_X, &x1val);
+       double x1 = x1val.to_number();
+       if ( ! utility::isFinite(x1) ) return as_value(NAN);
+
+       as_value y1val;
+       o1->get_member(NSV::PROP_Y, &y1val);
+       double y1 = y1val.to_number();
+       if ( ! utility::isFinite(y1) ) return as_value(NAN);
+
+       as_value x2val;
+       o2->get_member(NSV::PROP_X, &x2val);
+       double x2 = x2val.to_number();
+       if ( ! utility::isFinite(x2) ) return as_value(NAN);
+
+       as_value y2val;
+       o2->get_member(NSV::PROP_Y, &y2val);
+       double y2 = y2val.to_number();
+       if ( ! utility::isFinite(y2) ) return as_value(NAN);
+
+       double hside = x2 - x1; // p1.x - p0.x;
+       double vside = y2 - y1; // p1.y - p0.y;
+
+       double sqdist = hside*hside + vside*vside;
+       double dist = sqrtf(sqdist);
+
+       return as_value(dist);
 }
 
 static as_value

Index: testsuite/actionscript.all/Point.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Point.as,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- testsuite/actionscript.all/Point.as 19 May 2008 11:05:27 -0000      1.2
+++ testsuite/actionscript.all/Point.as 19 May 2008 11:51:41 -0000      1.3
@@ -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.2 2008/05/19 11:05:27 strk Exp $";
+rcsid="$Id: Point.as,v 1.3 2008/05/19 11:51:41 strk Exp $";
 
 #include "check.as"
 
@@ -92,7 +92,6 @@
 // Test Point.add
 //-------------------------------------------------------------
 
-// TODO
 p0 = new Point('x', 'y');
 ret = p0.add();
 check(ret instanceof Point);
@@ -143,7 +142,66 @@
 // Test Point.distance (static)
 //-------------------------------------------------------------
 
-// TODO
+dist = Point.distance();
+check_equals(typeof(dist), 'undefined');
+
+dist = Point.distance(undefined);
+check_equals(typeof(dist), 'undefined');
+
+o0 = {x:10, y:1};
+o1 = {x:21, y:1};
+dist = Point.distance(o0, o1);
+check_equals(typeof(dist), 'undefined');
+
+p0 = new Point('x', 'y');
+p1 = new Point('a', 'b');
+dist = Point.distance(p0, p1);
+check_equals(typeof(dist), 'number');
+check(isNaN(dist));
+dist = p0.distance(p1);
+check_equals(typeof(dist), 'undefined');
+
+p0 = new Point('10', '20');
+p1 = new Point('10', 'y');
+dist = Point.distance(p0, p1);
+check_equals(typeof(dist), 'number');
+check(isNaN(dist));
+dist = p0.distance(p1);
+check_equals(typeof(dist), 'undefined');
+
+p0 = new Point('10', 'y');
+p1 = new Point('10', '20');
+dist = Point.distance(p0, p1);
+check_equals(typeof(dist), 'number');
+check(isNaN(dist));
+dist = p0.distance(p1);
+check_equals(typeof(dist), 'undefined');
+
+p0 = new Point('5', '4');
+p1 = new Point('4', '7');
+dist = Point.distance(p0, p1);
+check_equals(typeof(dist), 'number');
+check_equals(Math.round(dist*100), 316);
+dist = p0.distance(p1);
+check_equals(typeof(dist), 'undefined');
+
+p0 = new Point('1', '1');
+p1 = new Point('10', '1');
+dist = Point.distance(p0, p1);
+check_equals(typeof(dist), 'number');
+check_equals(dist, 9);
+
+// Doesn't matter if second arg is an instanceof Point
+dist = Point.distance(p0, o1);
+check_equals(typeof(dist), 'number');
+check_equals(dist, 20);
+
+// But first arg *must* be instanceof point !
+dist = Point.distance(o1, p0);
+check_equals(typeof(dist), 'undefined');
+o1.__proto__ = Point.prototype;
+dist = Point.distance(o1, p0);
+check_equals(dist, 20);
 
 //-------------------------------------------------------------
 // Test Point.equals
@@ -225,6 +283,6 @@
 // END OF TEST
 //-------------------------------------------------------------
 
-check_totals(71);
+check_totals(92);
 
 #endif // OUTPUT_VERSION >= 8




reply via email to

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