[Uml-devel] kdesdk/umbrello/umbrello

Klas Kalass klas.kalass at gmx.de
Wed Mar 19 13:53:11 UTC 2003


CVS commit by kalass: 

new version of the anti-cos and anti-sin patch to get more exact results. This time make sure that a division by zero never happens. This should be rock-stable now :-)


  M +7 -4      linepath.cpp   1.9


--- kdesdk/umbrello/umbrello/linepath.cpp  #1.8:1.9
@@ -8,5 +8,5 @@
  ***************************************************************************/
 
-#include <math.h>
+#include <cmath>
 
 #include <kdebug.h>
@@ -358,4 +358,7 @@ void LinePath::calculateHead() {
         int xb = getPoint(size -1).x();
         int yb = getPoint(size -1).y();
+        double deltaX = xb - xa;
+        double deltaY = yb - ya;
+        double hypotenuse = sqrt(deltaX*deltaX + deltaY*deltaY); // the length
         int halfLength = 10;
         double arrowAngle = 0.5 * atan(sqrt(3.0) / 3.0);
@@ -365,8 +368,8 @@ void LinePath::calculateHead() {
                 halfLength += 3;        // longer
         }
-        double slope = atan2(double(yb - ya), double(xb - xa)); //slope of line
-        double cosx = halfLength * cos(slope);
+        double slope = atan2(deltaY, deltaX);   //slope of line
+        double cosx = hypotenuse==0?1:halfLength * deltaX/hypotenuse;
 
-        double siny = halfLength * sin(slope);
+        double siny = hypotenuse==0?0:halfLength * deltaY/hypotenuse;
         double arrowSlope = slope + arrowAngle;
 






More information about the umbrello-devel mailing list