Port changes for issue #603.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-12-23 14:00:50 +02:00
parent 0419f60e0b
commit ff87b32ae9

View File

@ -203,7 +203,7 @@ qreal VAbstractPiece::SumTrapezoids(const QVector<QPointF> &points)
*/ */
QVector<QPointF> VAbstractPiece::CheckLoops(const QVector<QPointF> &points) QVector<QPointF> VAbstractPiece::CheckLoops(const QVector<QPointF> &points)
{ {
const int count = points.size(); int count = points.size();
/*If we got less than 4 points no need seek loops.*/ /*If we got less than 4 points no need seek loops.*/
if (count < 4) if (count < 4)
{ {
@ -302,13 +302,32 @@ QVector<QPointF> VAbstractPiece::CheckLoops(const QVector<QPointF> &points)
switch (status) switch (status)
{ {
case ParallelIntersection: case ParallelIntersection:
{
/*We have found a loop.*/ /*We have found a loop.*/
// Theoretically there is no big difference which point j or jNext to select. // Very tricky case
// In the end we will draw a line in any case. // See the file "collection/bugs/Issue_#603.val"
const QLineF line1(points.at(i+1), points.at(j));
const QLineF line2(points.at(i), points.at(jNext));
if (line1.length() <= line2.length())
{
// In this case we did not check a loop edges and can just skip them
ekvPoints.append(points.at(i)); ekvPoints.append(points.at(i));
ekvPoints.append(points.at(jNext)); ekvPoints.append(points.at(jNext));
i = j;
i = j; // Skip a loo
}
else
{
// In this case a loop edges probably was also chacked and added to the list
ekvPoints.clear();// Previous data is wrong and belong to loop.
ekvPoints.append(points.at(j));
ekvPoints.append(points.at(i+1));
count = j+1;// All beyond this belong to loop.
}
break; break;
}
case BoundedIntersection: case BoundedIntersection:
/*We have found a loop.*/ /*We have found a loop.*/
ekvPoints.append(points.at(i)); ekvPoints.append(points.at(i));