gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/gnash.h server/types.cpp...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/gnash.h server/types.cpp...
Date: Mon, 23 Apr 2007 16:40:08 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/23 16:40:08

Modified files:
        .              : ChangeLog 
        server         : gnash.h types.cpp 
        testsuite/server: Makefile.am 
Added files:
        testsuite/server: PointTest.cpp 

Log message:
                * server/: gnash.h, types.cpp: add point::distance() and
                  squaredDistance()
                * testsuite/server/: Makefile.am, PointTest.cpp: point tests.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2971&r2=1.2972
http://cvs.savannah.gnu.org/viewcvs/gnash/server/gnash.h?cvsroot=gnash&r1=1.94&r2=1.95
http://cvs.savannah.gnu.org/viewcvs/gnash/server/types.cpp?cvsroot=gnash&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/Makefile.am?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/PointTest.cpp?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2971
retrieving revision 1.2972
diff -u -b -r1.2971 -r1.2972
--- ChangeLog   23 Apr 2007 14:37:52 -0000      1.2971
+++ ChangeLog   23 Apr 2007 16:40:08 -0000      1.2972
@@ -1,5 +1,11 @@
 2007-04-23 Sandro Santilli <address@hidden>
 
+       * server/: gnash.h, types.cpp: add point::distance() and
+         squaredDistance()
+       * testsuite/server/: Makefile.am, PointTest.cpp: point tests.
+
+2007-04-23 Sandro Santilli <address@hidden>
+
        * server/cxform.{cpp,h}: add output operator and toString method.
        * server/DynamicShape.cpp (moveTo): do not reset current
          fill style on move. Fixes some of the tests in DrawingApiTest.swf

Index: server/gnash.h
===================================================================
RCS file: /sources/gnash/gnash/server/gnash.h,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -b -r1.94 -r1.95
--- server/gnash.h      16 Apr 2007 10:26:59 -0000      1.94
+++ server/gnash.h      23 Apr 2007 16:40:08 -0000      1.95
@@ -17,7 +17,7 @@
 // 
 //
 
-/* $Id: gnash.h,v 1.94 2007/04/16 10:26:59 jgilmore Exp $ */
+/* $Id: gnash.h,v 1.95 2007/04/23 16:40:08 strk Exp $ */
 
 /// \mainpage
 ///
@@ -424,6 +424,12 @@
 
        bool operator==(const point& p) const { return m_x == p.m_x && m_y == 
p.m_y; }
 
+       /// Return the square of the distance between this and other point.
+       float squareDistance(const point& other) const;
+
+       /// Return the distance between this and other point.
+       float distance(const point& other) const;
+
        bool    bitwise_equal(const point& p) const;
 };
 

Index: server/types.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/types.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- server/types.cpp    20 Apr 2007 13:46:20 -0000      1.22
+++ server/types.cpp    23 Apr 2007 16:40:08 -0000      1.23
@@ -36,6 +36,19 @@
                return memcmp(this, &p, sizeof(p)) == 0;
        }
 
+       float point::squareDistance(const point& other) const
+       {
+               float hside = other.m_x - m_x;
+               float vside = other.m_y - m_y;
+
+               return hside*hside + vside*vside;
+       }
+
+       float point::distance(const point& other) const
+       {
+               return sqrt(squareDistance(other));
+       }
+
 
        //
        // rgba

Index: testsuite/server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/server/Makefile.am,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- testsuite/server/Makefile.am        16 Apr 2007 12:31:02 -0000      1.26
+++ testsuite/server/Makefile.am        23 Apr 2007 16:40:08 -0000      1.27
@@ -34,6 +34,7 @@
 
 check_PROGRAMS = \
        MatrixTest \
+       PointTest \
        PropertyListTest \
        GetterSetterTest \
        as_prop_flagsTest \
@@ -62,6 +63,11 @@
        $(GNASH_LIBS) \
        $(NULL)
 
+PointTest_SOURCES = PointTest.cpp
+PointTest_LDADD = \
+       $(GNASH_LIBS) \
+       $(NULL)
+
 PropertyListTest_SOURCES = PropertyListTest.cpp
 PropertyListTest_LDADD = \
        $(GNASH_LIBS) \

Index: testsuite/server/PointTest.cpp
===================================================================
RCS file: testsuite/server/PointTest.cpp
diff -N testsuite/server/PointTest.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ testsuite/server/PointTest.cpp      23 Apr 2007 16:40:08 -0000      1.1
@@ -0,0 +1,82 @@
+// 
+//   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gnash.h" // for point !!
+#include <iostream>
+#include <sstream>
+#include <cassert>
+
+#include "check.h"
+
+using namespace std;
+using namespace gnash;
+
+// for double comparison
+struct D {
+       double _d;
+       double _t; // tolerance
+
+       D(double d) : _d(d), _t(1e-4) {}
+
+       // Set tolerance
+       D(double d, double t) : _d(d), _t(t) {}
+
+       // Return true if the difference between the two
+       // doubles is below the minimum tolerance defined for the two
+       bool operator==(const D& d)
+       {
+               double tol = std::min(_t, d._t);
+               double delta = fabs(_d - d._d);
+               bool ret = delta < tol;
+               //cout << "D " << _d << "operator==(const D " << d._d <<") 
returning " << ret << " (delta is " << delta << ") " << endl;
+               return ret;
+       }
+};
+std::ostream& operator<<(std::ostream& os, const D& d)
+{
+       return os << d._d << " [tol: " << d._t << "]";
+}
+
+int
+main(int /*argc*/, char** /*argv*/)
+{
+
+       point p0(0, 0);
+
+       //
+       // Test distance
+       //
+
+       check_equals(p0.distance(point(1, 0)), 1);
+       check_equals(p0.distance(point(10, 0)), 10);
+       check_equals(p0.distance(point(-1, 0)), 1);
+       check_equals(p0.distance(point(-10, 0)), 10);
+
+       check_equals(p0.distance(point(0, 1)), 1);
+       check_equals(p0.distance(point(0, 10)), 10);
+       check_equals(p0.distance(point(0, -1)), 1);
+       check_equals(p0.distance(point(0, -10)), 10);
+
+       check_equals(D(p0.distance(point(2, 4))), D(4.47214));
+       check_equals(D(p0.distance(point(20, 20))), D(28.2843));
+       check_equals(D(p0.distance(point(2, -4))), D(4.47214));
+       check_equals(D(p0.distance(point(-20, 20))), D(28.2843));
+}
+




reply via email to

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