[Uml-devel] kdesdk/umbrello/umbrello
Klas Kalass
klas.kalass at gmx.de
Wed Mar 19 03:58:03 UTC 2003
CVS commit by kalass:
avoid using sin and cos on the angle delivered by atan because those values
have significant errors.
Fixed rounding errors, this improves the rendering quality of associations
and compositions.
M +14 -11 linepath.cpp 1.5
--- kdesdk/umbrello/umbrello/linepath.cpp #1.4:1.5
@@ -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,16 +368,16 @@ 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 = halfLength * deltaX/hypotenuse;
- double siny = halfLength * sin(slope);
+ double siny = halfLength * deltaY/hypotenuse;
double arrowSlope = slope + arrowAngle;
m_LastPoint = getPoint(size - 1);
- m_ArrowPointA.setX( (int)(m_LastPoint.x() - halfLength * cos(arrowSlope) ) );
- m_ArrowPointA.setY( (int)(m_LastPoint.y() - halfLength * sin(arrowSlope)) );
+ m_ArrowPointA.setX( (int)round(m_LastPoint.x() - halfLength * cos(arrowSlope) ) );
+ m_ArrowPointA.setY( (int)round(m_LastPoint.y() - halfLength * sin(arrowSlope)) );
arrowSlope = slope - arrowAngle;
- m_ArrowPointB.setX( (int)(m_LastPoint.x() - halfLength * cos(arrowSlope)) );
- m_ArrowPointB.setY( (int)(m_LastPoint.y() - halfLength * sin(arrowSlope)) );
+ m_ArrowPointB.setX( (int)round(m_LastPoint.x() - halfLength * cos(arrowSlope)) );
+ m_ArrowPointB.setY( (int)round(m_LastPoint.y() - halfLength * sin(arrowSlope)) );
if(xa > xb)
@@ -388,8 +391,8 @@ void LinePath::calculateHead() {
siny = siny > 0 ? siny * -1 : siny;
- m_MidPoint.setX( (int)(m_LastPoint.x() + cosx) );
- m_MidPoint.setY( (int)(m_LastPoint.y() + siny) );
- m_FullPoint.setX( (int)(m_LastPoint.x() + cosx * 2) );
- m_FullPoint.setY( (int)(m_LastPoint.y() + siny * 2) );
+ m_MidPoint.setX( (int)round(m_LastPoint.x() + cosx) );
+ m_MidPoint.setY( (int)round(m_LastPoint.y() + siny) );
+ m_FullPoint.setX( (int)round(m_LastPoint.x() + cosx * 2) );
+ m_FullPoint.setY( (int)round(m_LastPoint.y() + siny * 2) );
m_PointArray.setPoint(0, m_LastPoint);
More information about the umbrello-devel
mailing list