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

[XaraXtreme-commits] Commit Complete



Commit by  : gavin
Repository : xara
Revision   : 1517
Date       : Mon Jul 24 22:05:42 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/valfunc.cpp

Fixes a bug with path stroking using the Propeller profile. This was a consequence of taking the asin of a value that was a fraction larger than 1. I've replaced the previous cos(asin(x)) functions by sqrt(1-x*x) which is much faster. I also now ensure that x is always less than 1.


Diff:
Index: Trunk/XaraLX/Kernel/valfunc.cpp
===================================================================
--- Trunk/XaraLX/Kernel/valfunc.cpp	(revision 1516)
+++ Trunk/XaraLX/Kernel/valfunc.cpp	(revision 1517)
@@ -1711,8 +1711,10 @@
 	if (Position < 0.15)
 	{
 		//Draw a curved beginning bit...
-		Position = 1.0 - (Position / 0.15);
-		Value = cos(asin(Position));
+		Position = 1.0 - Position/0.15;
+		if ( Position>1.0 )
+			Position = 1.0;
+		Value = sqrt(1-Position*Position);
 	}
 	else
 	{
@@ -1720,7 +1722,9 @@
 		{
 			//Draw a curved end bit...
 			Position = (Position - 0.85) / 0.15;
-			Value = cos(asin(Position));
+			if ( Position>1.0 )
+				Position = 1.0;
+			Value = sqrt(1-Position*Position);
 		}
 		else
 		{
@@ -2539,8 +2543,10 @@
 	double Value;
 	if (Position < MaxPos)
 	{
-		Position = 1.0 - (Position / MaxPos);
-		Value = cos(asin(Position));
+		Position = 1.0 - Position/MaxPos;
+		if ( Position>1.0 )
+			Position = 1.0;
+		Value = sqrt(1-Position*Position);
 	}
 	else
 	{
@@ -2548,7 +2554,7 @@
 		Value = (cos( Position * Pi) + 1.0) / 2.0;
 	}
 
-	return(Value);
+	return Value;
 }
 
 
@@ -2598,8 +2604,10 @@
 	double Value;
 	if (Position < 0.2)
 	{
-		Position = 1.0 - (Position / 0.2);
-		Value = cos(asin(Position));
+		Position = 1.0 - Position/0.2;
+		if ( Position>1.0 )
+			Position = 1.0;
+		Value = sqrt(1-Position*Position);
 	}
 	else
 	{
@@ -2690,11 +2698,12 @@
 double ValueFunctionEllipse::GetValue(double Position)
 {
 	if (Position < MaxPos)
-		Position = 1.0 - (Position / MaxPos);
+		Position = 1.0 - Position/MaxPos;
 	else
 		Position = (Position - MaxPos) / (1.0 - MaxPos);
-
-	return(cos(asin(Position)));
+	if ( Position>1.0 )
+		Position = 1.0;
+	return sqrt(1-Position*Position);
 }
 
 
@@ -2749,11 +2758,13 @@
 double ValueFunctionThumbtack::GetValue(double Position)
 {
 	if (Position < MaxPos)
-		Position = (Position / MaxPos);
+		Position = Position / MaxPos;
 	else
 		Position = 1.0 - ((Position - MaxPos) / (1.0 - MaxPos));
 
-	return(1.0 - cos(asin(Position)));
+	if ( Position>1.0 )
+		Position = 1.0;
+	return 1.0 - sqrt(1-Position*Position);
 }
 
 


Xara