r16319 by fschmid - Applied fixes from latest Koffice branch.

scribus-commit scribus-commit at lists.scribus.net
Sat Jan 29 23:03:25 CET 2011


Author: fschmid
Date: Sat Jan 29 22:03:24 2011
New Revision: 16319

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16319
Log:
Applied fixes from latest Koffice branch.

Modified:
    trunk/Scribus/scribus/KarbonCurveFit.cpp

Modified: trunk/Scribus/scribus/KarbonCurveFit.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16319&path=/trunk/Scribus/scribus/KarbonCurveFit.cpp
==============================================================================
--- trunk/Scribus/scribus/KarbonCurveFit.cpp (original)
+++ trunk/Scribus/scribus/KarbonCurveFit.cpp Sat Jan 29 22:03:24 2011
@@ -21,7 +21,9 @@
 */
 
 #include "KarbonCurveFit.h"
+#include <QVector>
 #include <math.h>
+const qreal Zero = 10e-12;
 
 /*
 	An Algorithm for Automatically Fitting Digitized Curves
@@ -32,7 +34,7 @@
 	http://www.acm.org/pubs/tog/GraphicsGems/gems/README
 */
 
-#define MAXPOINTS	1000		/* The most points you can have */
+//#define MAXPOINTS	1000		/* The most points you can have */
 
 class FitVector {
 	public:
@@ -53,7 +55,7 @@
 
 	void normalize(){
 		double len=length();
-		if(len==0.0f)
+		if (qFuzzyCompare(len, 0.0)) 
 			return;
 		m_X/=len; m_Y/=len;
 	}
@@ -65,7 +67,7 @@
 
 	void scale(double s){
 		double len = length();
-		if(len==0.0f)
+		if (qFuzzyCompare(len, 0.0)) 
 			return;
 		m_X *= s/len;
 		m_Y *= s/len;
@@ -128,9 +130,11 @@
 		u[i-first] = u[i-first-1] +
 	  			distance(points.at(i), points.at(i-1));
     }
-
+    double denominator = u[last-first];
+    if (qFuzzyCompare(denominator, 0.0))
+      denominator = Zero;
     for (i = first + 1; i <= last; i++) {
-		u[i-first] = u[i-first] / u[last-first];
+		u[i-first] = u[i-first] / denominator;
     }
 
     return(u);
@@ -208,7 +212,7 @@
 QPointF* GenerateBezier(const QList<QPointF> &points, int first, int last, double *uPrime,FitVector tHat1,FitVector tHat2)
 {
     int 	i;
-    FitVector	A[MAXPOINTS][2];	/* Precomputed rhs for eqn	*/
+//    FitVector	A[MAXPOINTS][2];	/* Precomputed rhs for eqn	*/
     int 	nPts;			/* Number of pts in sub-curve */
     double 	C[2][2];			/* Matrix C		*/
     double 	X[2];			/* Matrix X			*/
@@ -223,7 +227,7 @@
     curve = new QPointF[4];
     nPts = last - first + 1;
 
- 
+    QVector< QVector<FitVector> > A(nPts, QVector<FitVector>(2));
     /* Compute the A's	*/
     for (i = 0; i < nPts; i++) {
 		FitVector v1, v2;
@@ -274,9 +278,11 @@
     det_X_C1  = X[0]    * C[1][1] - X[1]    * C[0][1];
 
     /* Finally, derive alpha values	*/
-    if (det_C0_C1 == 0.0) {
+     if (qFuzzyCompare(det_C0_C1, 0.0)) {
 		det_C0_C1 = (C[0][0] * C[1][1]) * 10e-12;
     }
+    if (qFuzzyCompare(det_C0_C1, 0.0))
+      det_C0_C1 = Zero;
     alpha_l = det_X_C1 / det_C0_C1;
     alpha_r = det_C0_X / det_C0_C1;
 
@@ -408,7 +414,8 @@
     numerator = (Q_u.x() - P.x()) * (Q1_u.x()) + (Q_u.y() - P.y()) * (Q1_u.y());
     denominator = (Q1_u.x()) * (Q1_u.x()) + (Q1_u.y()) * (Q1_u.y()) +
 		      	  (Q_u.x() - P.x()) * (Q2_u.x()) + (Q_u.y() - P.y()) * (Q2_u.y());
-    
+    if (qFuzzyCompare(denominator, 0.0)) 
+      denominator = Zero;
     /* u = u - f(u)/f'(u) */
     uPrime = u - (numerator/denominator);
     return (uPrime);




More information about the scribus-commit mailing list