gnash-commit
[Top][All Lists]
Advanced

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

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


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/shape.cpp server/shape.h...
Date: Mon, 23 Apr 2007 18:09:55 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/23 18:09:55

Modified files:
        .              : ChangeLog 
        server         : shape.cpp shape.h 
        testsuite/server: Makefile.am 
Added files:
        testsuite/server: EdgeTest.cpp 

Log message:
                * server/shape.{cpp,h}: add primitive distance functions
                  for point-segment
                * testsuite/server/: Makefile.am, EdgeTest.cpp: add tests
                  for point-segment distance.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2972&r2=1.2973
http://cvs.savannah.gnu.org/viewcvs/gnash/server/shape.cpp?cvsroot=gnash&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/gnash/server/shape.h?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/Makefile.am?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/server/EdgeTest.cpp?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2972
retrieving revision 1.2973
diff -u -b -r1.2972 -r1.2973
--- ChangeLog   23 Apr 2007 16:40:08 -0000      1.2972
+++ ChangeLog   23 Apr 2007 18:09:54 -0000      1.2973
@@ -1,5 +1,12 @@
 2007-04-23 Sandro Santilli <address@hidden>
 
+       * server/shape.{cpp,h}: add primitive distance functions
+         for point-segment
+       * testsuite/server/: Makefile.am, EdgeTest.cpp: add tests 
+         for point-segment distance.
+
+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.

Index: server/shape.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/shape.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- server/shape.cpp    13 Apr 2007 07:35:55 -0000      1.31
+++ server/shape.cpp    23 Apr 2007 18:09:54 -0000      1.32
@@ -5,7 +5,7 @@
 
 // Quadratic bezier outline shapes, the basis for most SWF rendering.
 
-/* $Id: shape.cpp,v 1.31 2007/04/13 07:35:55 bjacques Exp $ */
+/* $Id: shape.cpp,v 1.32 2007/04/23 18:09:54 strk Exp $ */
 
 #include "shape.h"
 
@@ -64,6 +64,48 @@
        }
 }
 
+float
+edge::distancePtSeg(const point& pt, const point& A, const point& B)
+{
+       float square = squareDistancePtSeg(pt, A, B);
+       return sqrt(square);
+}
+
+float
+edge::squareDistancePtSeg(const point& p, const point& A, const point& B)
+{
+       float dx = B.m_x - A.m_x;
+       float dy = B.m_y - A.m_y;
+
+        /* if start==end, then use pt distance */
+        if ( dx == 0 && dy == 0 ) return p.squareDistance(A); 
+
+       float pdx = p.m_x - A.m_x;
+       float pdy = p.m_y - A.m_y;
+
+        float u = (pdx * dx + pdy * dy) / (dx*dx + dy*dy);
+
+        if (u<0)
+       {
+               cout << "R was < 0 " << endl;
+               return p.squareDistance(A); 
+       }
+
+        if (u>1)
+       {
+               cout << "R was > 1 " << endl;
+               return p.squareDistance(B);
+       }
+
+       point px;
+       px.m_x = A.m_x + u * (B.m_x - A.m_x);
+       px.m_y = A.m_y + u * (B.m_y - A.m_y);
+
+       cout << "R was between 0 and 1, u is " << u << " px : " << px.m_x << 
"," << px.m_y << endl;
+
+       return p.squareDistance(px);
+}
+
 
 DSOEXPORT bool edge::is_straight() const
 {

Index: server/shape.h
===================================================================
RCS file: /sources/gnash/gnash/server/shape.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/shape.h      19 Feb 2007 10:41:57 -0000      1.19
+++ server/shape.h      23 Apr 2007 18:09:54 -0000      1.20
@@ -5,7 +5,7 @@
 
 // Quadratic bezier outline shapes, the basis for most SWF rendering.
 
-/* $Id: shape.h,v 1.19 2007/02/19 10:41:57 strk Exp $ */
+/* $Id: shape.h,v 1.20 2007/04/23 18:09:54 strk Exp $ */
 
 #ifndef GNASH_SHAPE_H
 #define GNASH_SHAPE_H
@@ -34,6 +34,12 @@
                void    tesselate_curve() const;
                bool    is_straight() const;
                
+               /// Return squared distance between point pt and segment A-B
+               static float squareDistancePtSeg(const point& pt, const point& 
A, const point& B);
+
+               /// Return distance between point pt and segment A-B
+               static float distancePtSeg(const point& pt, const point& A, 
const point& B);
+               
        //private:
                // *quadratic* bezier: point = p0 * t^2 + p1 * 2t(1-t) + p2 * 
(1-t)^2
                float   m_cx, m_cy;             // "control" point

Index: testsuite/server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/server/Makefile.am,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- testsuite/server/Makefile.am        23 Apr 2007 16:40:08 -0000      1.27
+++ testsuite/server/Makefile.am        23 Apr 2007 18:09:55 -0000      1.28
@@ -35,6 +35,7 @@
 check_PROGRAMS = \
        MatrixTest \
        PointTest \
+       EdgeTest \
        PropertyListTest \
        GetterSetterTest \
        as_prop_flagsTest \
@@ -68,6 +69,11 @@
        $(GNASH_LIBS) \
        $(NULL)
 
+EdgeTest_SOURCES = EdgeTest.cpp
+EdgeTest_LDADD = \
+       $(GNASH_LIBS) \
+       $(NULL)
+
 PropertyListTest_SOURCES = PropertyListTest.cpp
 PropertyListTest_LDADD = \
        $(GNASH_LIBS) \

Index: testsuite/server/EdgeTest.cpp
===================================================================
RCS file: testsuite/server/EdgeTest.cpp
diff -N testsuite/server/EdgeTest.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ testsuite/server/EdgeTest.cpp       23 Apr 2007 18:09:55 -0000      1.1
@@ -0,0 +1,81 @@
+// 
+//   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 "shape.h" // for edge
+#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*/)
+{
+
+       //
+       // Test distance
+       //
+
+       check_equals(edge::distancePtSeg(point(0,0), point(9, 0), point(9, 0)), 
9);
+
+       check_equals(edge::distancePtSeg(point(0,0), point(0, 0), point(3, 0)), 
0);
+
+       check_equals(edge::distancePtSeg(point(-5,0), point(0, 0), point(3, 
0)), 5);
+
+       check_equals(edge::distancePtSeg(point(5,0), point(0, 0), point(3, 0)), 
2);
+
+       check_equals(D(edge::distancePtSeg(point(0,0), point(-10, 0), point(3, 
0))), 0);
+
+       check_equals(edge::distancePtSeg(point(0,0), point(-10, 0), point(-10, 
30)), 10);
+
+       check_equals(edge::distancePtSeg(point(5,5), point(-10, 0), point(10, 
0)), 5);
+
+}
+




reply via email to

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