[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [Calligra] b902835: assistants: fix RulerAssistant for horizontal line
From: Geoffry Song <goffrie () gmail ! com>
Date: 2010-12-21 21:29:41
Message-ID: 20101221212941.D9AB6A60B9 () git ! kde ! org
[Download RAW message or body]
commit b902835511c00d02d7b2e35ca648d7d01d8962a6
branch master
Author: Geoffry Song <goffrie@gmail.com>
Date: Tue Dec 21 15:15:09 2010 -0500
assistants: fix RulerAssistant for horizontal lines
diff --git a/krita/plugins/assistants/RulerAssistant/RulerAssistant.cc \
b/krita/plugins/assistants/RulerAssistant/RulerAssistant.cc index da75975..930daab \
100644
--- a/krita/plugins/assistants/RulerAssistant/RulerAssistant.cc
+++ b/krita/plugins/assistants/RulerAssistant/RulerAssistant.cc
@@ -36,16 +36,17 @@ RulerAssistant::RulerAssistant()
QPointF RulerAssistant::project(const QPointF& pt) const
{
Q_ASSERT(handles().size() == 2);
- double x1 = handles()[0]->x();
- double y1 = handles()[0]->y();
- double x2 = handles()[1]->x();
- double y2 = handles()[1]->y();
- double a1 = (y2 - y1) / (x2 - x1);
- double b1 = y1 - x1 * a1;
- double a2 = (x2 - x1) / (y1 - y2);
- double b2 = pt.y() - a2 * pt.x();
- double xm = (b2 - b1) / (a1 - a2);
- return QPointF(xm, xm * a1 + b1);
+ const QLineF line(*handles()[0], *handles()[1]);
+ const qreal
+ dx = line.dx(),
+ dy = line.dy(),
+ dx2 = dx * dx,
+ dy2 = dy * dy,
+ invsqrlen = 1.0 / (dx2 + dy2);
+ QPointF r(dx2 * pt.x() + dy2 * line.x1() + dx * dy * (pt.y() - line.y1()),
+ dx2 * line.y1() + dy2 * pt.y() + dx * dy * (pt.x() - line.x1()));
+ r *= invsqrlen;
+ return r;
}
QPointF RulerAssistant::adjustPosition(const QPointF& pt, const QPointF& \
/*strokeBegin*/)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic