diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index 802e3bc92..c03992c02 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -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 { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index c3485d5c1..3bfff25c4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -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; diff --git a/src/test/ValentinaTest/tst_findpoint.cpp b/src/test/ValentinaTest/tst_findpoint.cpp index f29a6388a..43acd44bf 100644 --- a/src/test/ValentinaTest/tst_findpoint.cpp +++ b/src/test/ValentinaTest/tst_findpoint.cpp @@ -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 @@ -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("axis"); + QTest::addColumn("line"); + QTest::addColumn("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("axisP1"); + QTest::addColumn("axisP2"); + QTest::addColumn("firstPoint"); + QTest::addColumn("secondPoint"); + QTest::addColumn("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); +} diff --git a/src/test/ValentinaTest/tst_findpoint.h b/src/test/ValentinaTest/tst_findpoint.h index e8ff331e9..694deb3a4 100644 --- a/src/test/ValentinaTest/tst_findpoint.h +++ b/src/test/ValentinaTest/tst_findpoint.h @@ -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