CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/11/12 10:22:41
Modified files: . : ChangeLog server : shape.cpp Log message: pointOnCurve: quicker return for T in (0,1); withinSquareDistance: compute distance from segments, not points, reducing iterations from 100 to 10 with no detectable precision reduction. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4831&r2=1.4832 http://cvs.savannah.gnu.org/viewcvs/gnash/server/shape.cpp?cvsroot=gnash&r1=1.48&r2=1.49 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4831 retrieving revision 1.4832 diff -u -b -r1.4831 -r1.4832 --- ChangeLog 12 Nov 2007 09:38:28 -0000 1.4831 +++ ChangeLog 12 Nov 2007 10:22:40 -0000 1.4832 @@ -1,5 +1,9 @@ 2007-11-12 Sandro Santilli <[EMAIL PROTECTED]> + * server/shape.cpp: (pointOnCurve): quicker return for T in (0,1); + (withinSquareDistance): compute distance from segments, not points, + reducing iterations from 100 to 10 with no detectable precision + reduction. * testsuite/swfdec/swfdec_gnash_tester: it seems diff -u3 doesn't work anymore (as of GNU diffutils 2.8.1) * server/: shape.cpp, tesselate.h: minor cleanup Index: server/shape.cpp =================================================================== RCS file: /sources/gnash/gnash/server/shape.cpp,v retrieving revision 1.48 retrieving revision 1.49 diff -u -b -r1.48 -r1.49 --- server/shape.cpp 12 Nov 2007 08:39:27 -0000 1.48 +++ server/shape.cpp 12 Nov 2007 10:22:41 -0000 1.49 @@ -59,6 +59,9 @@ { // See http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B.C3.A9zier_curves + if ( t == 0.0 ) return A; + else if ( t == 1.0 ) return B; + point Q1(A, C, t); point Q2(C, B, t); point R = point(Q1, Q2, t); @@ -393,40 +396,31 @@ // defined by the triangle ACB and it's square // distance from it is > then the requested one - // Brute force, try 100 times or give up + // Approximate the curve to segCount segments + // and compute distance of query point from each + // segment. // - // TODO: use a binary search like thing, in where - // we try to find the 't' value taking the average - // between the 2 best 't' values found so far - // (best is the ones giving closer distance) + // TODO: find an apprpriate value for segCount based + // on rendering scale ? // float minDist = std::numeric_limits<float>::max(); - bool gettingCloser = false; - int attempts = 100; - int i=0; - for (; i<=attempts; ++i) - { - float t = (float)i/attempts; - float d = edge::squareDistancePtCurve(A, C, B, p, t); + int segCount = 10; + point p0 = A; + for (int i=1; i<=segCount; ++i) + { + float t1 = (float)i/segCount; + point p1 = edge::pointOnCurve(A, C, B, t1); + + // distance from point and segment being an approximation + // of the curve + float d = edge::squareDistancePtSeg(p, p0, p1); + + //float d = edge::squareDistancePtCurve(A, C, B, p, t); //log_debug("Factor %26.26g, distance %g (asked %g)", t, sqrt(d), sqrt(dist)); if ( d <= dist ) return true; - if ( ! i ) minDist = d; - else if ( d < minDist ) - { - minDist = d; - gettingCloser = true; - } - else if ( d > minDist ) - { - if ( gettingCloser ) - { - // we were getting closer before... - break; - } - } + p0 = p1; } - // log_debug("Gave up at attempt %d", i); } px = np; _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit