gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libgeometry/Makefile.am testsui...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libgeometry/Makefile.am testsui...
Date: Sat, 10 Nov 2007 09:46:55 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/11/10 09:46:54

Modified files:
        .              : ChangeLog 
        libgeometry    : Makefile.am 
        testsuite/libgeometry: Makefile.am 
Added files:
        libgeometry    : Point2d.h 
        testsuite/libgeometry: Point2dTest.cpp 

Log message:
                * libgeometry/: Makefile.am, Point2d.h: initial implementation 
of
                  a generalized point class.
                * testsuite/libgeometry/: Makefile.am, Point2dTest.cpp: initial
                  test for the generalized point class.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4821&r2=1.4822
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/Makefile.am?cvsroot=gnash&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/Point2d.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libgeometry/Makefile.am?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libgeometry/Point2dTest.cpp?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4821
retrieving revision 1.4822
diff -u -b -r1.4821 -r1.4822
--- ChangeLog   9 Nov 2007 21:51:43 -0000       1.4821
+++ ChangeLog   10 Nov 2007 09:46:53 -0000      1.4822
@@ -1,3 +1,10 @@
+2007-11-10 Sandro Santilli <address@hidden>
+
+       * libgeometry/: Makefile.am, Point2d.h: initial implementation of
+         a generalized point class.
+       * testsuite/libgeometry/: Makefile.am, Point2dTest.cpp: initial
+         test for the generalized point class.
+
 2007-11-09 Sandro Santilli <address@hidden>
 
        * testsuite/samples/Makefile.am: don't giveup on failure

Index: libgeometry/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libgeometry/Makefile.am,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- libgeometry/Makefile.am     10 Aug 2007 04:36:13 -0000      1.31
+++ libgeometry/Makefile.am     10 Nov 2007 09:46:54 -0000      1.32
@@ -18,7 +18,7 @@
 # 
 #
 
-# $Id: Makefile.am,v 1.31 2007/08/10 04:36:13 strk Exp $
+# $Id: Makefile.am,v 1.32 2007/11/10 09:46:54 strk Exp $
 
 AUTOMAKE_OPTIONS = 
 
@@ -57,6 +57,7 @@
 
 noinst_HEADERS = \
        Range2d.h       \
+       Point2d.h       \
        snappingrange.h \
        axial_box.h     \
        bsp.h           \

Index: testsuite/libgeometry/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libgeometry/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/libgeometry/Makefile.am   1 Jul 2007 10:54:44 -0000       1.4
+++ testsuite/libgeometry/Makefile.am   10 Nov 2007 09:46:54 -0000      1.5
@@ -35,6 +35,7 @@
 
 check_PROGRAMS = \
        Range2dTest     \
+       Point2dTest     \
        snappingrangetest       \
        $(NULL)
 
@@ -44,9 +45,11 @@
       gnash-dbg.log \
       site.exp.bak \
       Range2dTest \
+      Point2dTest \
       snappingrangetest \
       $(NULL)
 
+Point2dTest_SOURCES = Point2dTest.cpp
 Range2dTest_SOURCES = Range2dTest.cpp
 snappingrangetest_SOURCES = snappingrangetest.cpp
 

Index: libgeometry/Point2d.h
===================================================================
RCS file: libgeometry/Point2d.h
diff -N libgeometry/Point2d.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libgeometry/Point2d.h       10 Nov 2007 09:46:54 -0000      1.1
@@ -0,0 +1,153 @@
+// Point2d template - for gnash
+// 
+//   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 3 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
+
+//
+// Original author: Sandro Santilli <address@hidden>
+//
+
+
+/* $Id: Point2d.h,v 1.1 2007/11/10 09:46:54 strk Exp $ */
+
+#ifndef GNASH_POINT2DH
+#define GNASH_POINT2DH
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <ostream>
+#include <limits>
+#include <algorithm>
+#include <cassert> // for inlines
+#include <iostream> // temporary include for debugging
+#include <cmath> // for floor / ceil
+
+using namespace std;
+
+namespace gnash {
+
+namespace geometry {
+
+/// 2d Point template class
+//
+/// The class stores 2 values of the type specified
+/// as template argument, representing the the X and Y oordinates.
+///
+template <typename T>
+class Point2d
+{
+private:
+
+public:
+
+       /// The x ordinate
+       T x;
+
+       /// The y ordinate
+       T y;
+
+       /// Construct a Point2d with given X and Y ordinates
+       //
+       Point2d(T nx, T ny)
+               :
+               x(nx),
+               y(ny)
+       {
+       }
+
+       /// Construct a Point2d as an interpolation of the given input points
+       //
+       /// @param p0 first point
+       /// @param p1 second point
+       /// @param t interpolation factor, between 0 and 1
+       ///
+       //template <typename U>
+       Point2d(const Point2d<T>& p0, const Point2d<T>& p1, float t)
+               :
+               x( p0.x + (p1.x - p0.x) * t ),
+               y( p0.y + (p1.y - p0.y) * t )
+       {
+       }
+
+       /// Set coordinates to given values
+       //
+       /// @return a reference to this instance
+       ///
+       Point2d<T>& setTo(const T& nx, const T& ny)
+       {
+               x = nx;
+               y = ny;
+
+               return *this;
+       }
+
+       /// Set coordinates to the ones of the interpolation between the given 
input points
+       //
+       /// @param p0 first point
+       /// @param p1 second point
+       /// @param t interpolation factor, between 0 and 1
+       ///
+       /// @return a reference to this instance
+       ///
+       Point2d<T>& setTo(const Point2d<T>& p0, const Point2d<T>& p1, float t)
+       {
+               x = p0.x + (p1.x - p0.x) * t;
+               y = p0.y + (p1.y - p0.y) * t;
+               return *this;
+       }
+
+       /// Return square distance between two points
+       static
+       float squareDistance(const Point2d<T>& p0, const Point2d<T>& p1)
+       {
+               float hside = p1.x - p0.x;
+               float vside = p1.y - p0.y;
+
+               return hside*hside + vside*vside;
+       }
+
+       /// Return square distance between this and the given point
+       float squareDistance(const Point2d<T>& p)
+       {
+               return squareDistance(*this, p);
+       }
+
+       /// Return distance between this and the given point
+       float distance(const Point2d<T>& p)
+       {
+               return sqrtf(squareDistance(p));
+       }
+};
+
+template <typename T> inline std::ostream&
+operator<< (std::ostream& os, const Point2d<T>& p)
+{
+       return os << "Point2d(" << p.x << "," << p.y << ")";
+}
+
+
+} // namespace gnash::geometry
+} // namespace gnash
+
+#endif // GNASH_POINT2DH
+
+
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:

Index: testsuite/libgeometry/Point2dTest.cpp
===================================================================
RCS file: testsuite/libgeometry/Point2dTest.cpp
diff -N testsuite/libgeometry/Point2dTest.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ testsuite/libgeometry/Point2dTest.cpp       10 Nov 2007 09:46:54 -0000      
1.1
@@ -0,0 +1,63 @@
+// 
+//   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 3 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 "check.h"
+#include "Point2d.h"
+#include <iostream>
+#include <sstream>
+#include <cassert>
+
+using namespace std;
+using namespace gnash;
+using namespace gnash::geometry;
+
+int
+main(int /*argc*/, char** /*argv*/)
+{
+       Point2d<float> p(0, 0);
+       Point2d<float> p1(10, 0);
+
+       check_equals( p.distance(p1), 10 );
+
+       Point2d<float> p2(p, p1, 0.5);
+       check_equals(p2.x, 5);
+       check_equals(p2.y, 0);
+
+       p2.setTo(p, p1, 0.2);
+       check_equals(p2.x, 2);
+       check_equals(p2.y, 0);
+
+       p2.setTo(p, p1, 0.7);
+       check_equals(p2.x, 7);
+       check_equals(p2.y, 0);
+
+       p.setTo(0, 10);
+       p2.setTo(p, p1, 0.5);
+       check_equals(p2.x, 5);
+       check_equals(p2.y, 5);
+
+       p1.setTo(0, 20);
+       p2.setTo(p, p1, 0.7);
+       check_equals(p2.x, 0);
+       check_equals(p2.y, 17); 
+
+}
+




reply via email to

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