Merged in ValentinaZhuravska/valentina/feature (pull request #130)

Fixed issue #516. Valentina crashes when use "Point intersect line and axis" instrument.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-06-28 09:14:00 +03:00
commit c434a498ef
4 changed files with 76 additions and 1 deletions

View File

@ -157,7 +157,14 @@ QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line
QLineF::IntersectType intersect = axis.intersect(line, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
{
return fPoint;
if(axis.angle() == line.angle() || qAbs(axis.angle() - line.angle()) == 180)
{
return QPointF();
}
else
{
return fPoint;
}
}
else
{

View File

@ -182,6 +182,10 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c
{
return QPointF();
}
if (axis.angle() == hypotenuse.angle() || qAbs(axis.angle() - hypotenuse.angle()) == 180)
{
return QPointF();
}
qreal step = 1;

View File

@ -29,6 +29,8 @@
#include "tst_findpoint.h"
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h"
#include "../vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h"
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h"
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h"
#include <QtTest>
@ -208,3 +210,59 @@ void TST_FindPoint::TestTrueDarts()
QCOMPARE(p1.toPoint(), expectP1.toPoint());
QCOMPARE(p2.toPoint(), expectP2.toPoint());
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestLineIntersectAxis_data()
{
QTest::addColumn<QLineF>("axis");
QTest::addColumn<QLineF>("line");
QTest::addColumn<QPointF>("point");
const QLineF axis(0, 0, 1, 0);
const QLineF line(0, 1, 1, 1);
const QPointF point(0, 0);
QTest::newRow("Parallel lines") << axis << line << point;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestLineIntersectAxis()
{
QFETCH(QLineF, axis);
QFETCH(QLineF, line);
QFETCH(QPointF, point);
QPointF resultPoint = VToolLineIntersectAxis::FindPoint(axis, line);
QCOMPARE(point, resultPoint);
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestTriangle_data()
{
QTest::addColumn<QPointF>("axisP1");
QTest::addColumn<QPointF>("axisP2");
QTest::addColumn<QPointF>("firstPoint");
QTest::addColumn<QPointF>("secondPoint");
QTest::addColumn<QPointF>("point");
const QPointF axisP1(0, 0);
const QPointF axisP2(0, 1);
const QPointF firstPoint(1, 0);
const QPointF secondPoint(1, 1);
const QPointF point(0, 0);
QTest::newRow("Parallel lines") << axisP1 << axisP2 << firstPoint << secondPoint << point;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_FindPoint::TestTriangle()
{
QFETCH(QPointF, axisP1);
QFETCH(QPointF, axisP2);
QFETCH(QPointF, firstPoint);
QFETCH(QPointF, secondPoint);
QFETCH(QPointF, point);
QPointF resultPoint = VToolTriangle::FindPoint(axisP1, axisP2, firstPoint, secondPoint);
QCOMPARE(point, resultPoint);
}

View File

@ -44,6 +44,12 @@ private slots:
void TestTrueDarts_data();
void TestTrueDarts();
void TestLineIntersectAxis_data();
void TestLineIntersectAxis();
void TestTriangle_data();
void TestTriangle();
};
#endif // TST_FINDPOINT_H