Optimize searching special shoulder point.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-03-27 10:30:31 +03:00
parent 50a5119960
commit c20f94e5f0

View File

@ -111,33 +111,37 @@ void VToolShoulderPoint::setDialog()
* @param length length form shoulder point to our. * @param length length form shoulder point to our.
* @return point. * @return point.
*/ */
//TODO find better way calculate point.
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
const qreal &length) const qreal &length)
{ {
QPointF shoulderPoint = p2Line; // Position if result was not found
if (length <= 0)
{
return shoulderPoint;
}
QLineF line = QLineF(p1Line, p2Line); QLineF line = QLineF(p1Line, p2Line);
qreal toolLength = length; const qreal baseLength = line.length();
qreal dist = line.length(); const int baseAngle = qRound(line.angle());
if (dist>toolLength) line.setLength(length*2);
QPointF p1;
QPointF p2;
const qint32 res = VGObject::LineIntersectCircle(pShoulder, length, line, p1, p2);
// If possition is right we will find only one result.
// If found two cases this is wrong result. Return default position.
if (res == 1)
{ {
qDebug()<<"Correction of length in shoulder point tool. Parameter length too small."; const QLineF line = QLineF(p1Line, p1);
toolLength = dist; if (line.length() > baseLength && baseAngle == qRound(line.angle()))
}
if (VFuzzyComparePossibleNulls(dist, toolLength))
{ {
return line.p2(); shoulderPoint = p1;
}
qreal step = 0.01;
while (1)
{
line.setLength(line.length()+step);
QLineF line2 = QLineF(pShoulder, line.p2());
if (line2.length()>=toolLength)
{
return line.p2();
} }
} }
return QPointF();
return shoulderPoint;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------