From ac5c8d82011cdce3840e497f3da7c92b1aa38a41 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 10 Jan 2016 21:41:46 +0200 Subject: [PATCH] Do not remove a loop created by intersection point when it is the first or the last point of lines that intersect. --HG-- branch : develop --- src/libs/vlayout/vabstractdetail.cpp | 6 ++++- .../ValentinaTest/tst_vabstractdetail.cpp | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libs/vlayout/vabstractdetail.cpp b/src/libs/vlayout/vabstractdetail.cpp index 098882f18..6419c4c77 100644 --- a/src/libs/vlayout/vabstractdetail.cpp +++ b/src/libs/vlayout/vabstractdetail.cpp @@ -338,7 +338,11 @@ QVector VAbstractDetail::CheckLoops(const QVector &points) intersect = line1.intersect(line2, &crosPoint); if (intersect == QLineF::BoundedIntersection && not (i == 0 && j+1 == count-1 && closed)) { // Break, but not if intersects the first edge and the last edge in closed path - break; + if (line1.p1() != crosPoint && line1.p2() != crosPoint && + line2.p1() != crosPoint && line2.p2() != crosPoint) + { + break; + } } intersect = QLineF::NoIntersection; } diff --git a/src/test/ValentinaTest/tst_vabstractdetail.cpp b/src/test/ValentinaTest/tst_vabstractdetail.cpp index dbb2316c0..204ae3ad6 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.cpp +++ b/src/test/ValentinaTest/tst_vabstractdetail.cpp @@ -172,6 +172,33 @@ void TST_VAbstractDetail::PathRemoveLoop_data() const path.removeLast(); res.removeLast(); QTest::newRow("One loop, the second loop, unclosed a path (six unique points)") << path << res; + + path.clear(); + path << QPointF(20, 10); + path << QPointF(10, 10); + path << QPointF(20, 15); + path << QPointF(10, 20); + path << QPointF(20, 20); + path << QPointF(20, 10); + QTest::newRow("Correct closed a path, point on line (four unique points)") << path << path; + + path.removeLast(); + QTest::newRow("Corect unclosed a path, point on line (four unique points)") << path << path; + + path.clear(); + path << QPointF(20, 10); + path << QPointF(10, 10); + path << QPointF(0, 10); + path << QPointF(10, 15); + path << QPointF(0, 20); + path << QPointF(10, 20); + path << QPointF(20, 20); + path << QPointF(10, 15); + path << QPointF(20, 10); + QTest::newRow("Correct closed a path, point on line (six unique points)") << path << path; + + path.removeLast(); + QTest::newRow("Corect unclosed a path, point on line (six unique points)") << path << path; } //---------------------------------------------------------------------------------------------------------------------