Fix for method UniteWithContour.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-20 14:50:24 +02:00
parent 2355e435a5
commit 7970678575
4 changed files with 33 additions and 8 deletions

View File

@ -65,10 +65,13 @@ public:
void setWidth(const qreal &value); void setWidth(const qreal &value);
static QVector<QPointF> Equidistant(const QVector<QPointF> &points, const EquidistantType &eqv, qreal width); static QVector<QPointF> Equidistant(const QVector<QPointF> &points, const EquidistantType &eqv, qreal width);
protected:
static QVector<QPointF> RemoveDublicates(const QVector<QPointF> &points);
private: private:
QSharedDataPointer<VAbstractDetailData> d; QSharedDataPointer<VAbstractDetailData> d;
static QVector<QPointF> RemoveDublicates(const QVector<QPointF> &points);
static QVector<QPointF> CorrectEquidistantPoints(const QVector<QPointF> &points); static QVector<QPointF> CorrectEquidistantPoints(const QVector<QPointF> &points);
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points); static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);
static QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width); static QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width);

View File

@ -50,6 +50,7 @@ enum class LayoutErrors : char
//# define SHOW_ROTATION //# define SHOW_ROTATION
//# define SHOW_COMBINE //# define SHOW_COMBINE
//# define SHOW_MIRROR //# define SHOW_MIRROR
//# define SHOW_CANDIDATE_BEST
# define SHOW_BEST # define SHOW_BEST
#endif//LAYOUT_DEBUG #endif//LAYOUT_DEBUG

View File

@ -75,7 +75,7 @@ void VLayoutDetail::SetCountourPoints(const QVector<QPointF> &points)
d->contour.removeLast(); d->contour.removeLast();
} }
d->contour = RoundPoints(d->contour); d->contour = RemoveDublicates(RoundPoints(d->contour));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -94,7 +94,7 @@ void VLayoutDetail::SetSeamAllowencePoints(const QVector<QPointF> &points)
d->seamAllowence.removeLast(); d->seamAllowence.removeLast();
} }
d->seamAllowence = RoundPoints(d->seamAllowence); d->seamAllowence = RemoveDublicates(RoundPoints(d->seamAllowence));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -245,7 +245,8 @@ QRectF VLayoutDetail::BoundingRect() const
{ {
QVector<QPointF> points = GetLayoutAllowencePoints(); QVector<QPointF> points = GetLayoutAllowencePoints();
points.append(points.first()); points.append(points.first());
return QPolygonF(points).boundingRect(); QRectF rec = QPolygonF(points).boundingRect();
return rec;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -260,11 +260,18 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail, bool &stop)
int dEdge = i;// For mirrored detail edge will be different int dEdge = i;// For mirrored detail edge will be different
if (CheckCombineEdges(workDetail, j, dEdge)) if (CheckCombineEdges(workDetail, j, dEdge))
{ {
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
DrawDebug(workDetail, d->frame+2);
# endif
#endif
const QRectF rec = workDetail.BoundingRect(); const QRectF rec = workDetail.BoundingRect();
bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, dEdge, bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, dEdge,
workDetail.GetMatrix(), workDetail.IsMirror()); workDetail.GetMatrix(), workDetail.IsMirror());
} }
d->frame = d->frame + 2; d->frame = d->frame + 3;
for (int angle = 0; angle <= 360; angle = angle+20) for (int angle = 0; angle <= 360; angle = angle+20)
{ {
@ -280,6 +287,13 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail, bool &stop)
if (CheckRotationEdges(workDetail, j, i, angle)) if (CheckRotationEdges(workDetail, j, i, angle))
{ {
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
++d->frame;
DrawDebug(workDetail, d->frame);
# endif
#endif
const QRectF rec = workDetail.BoundingRect(); const QRectF rec = workDetail.BoundingRect();
bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, i, bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, i,
workDetail.GetMatrix(), workDetail.IsMirror()); workDetail.GetMatrix(), workDetail.IsMirror());
@ -314,13 +328,19 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
int dEdge = i;// For mirror detail edge will be different int dEdge = i;// For mirror detail edge will be different
if (CheckCombineEdges(workDetail, j, dEdge)) if (CheckCombineEdges(workDetail, j, dEdge))
{ {
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
DrawDebug(workDetail, d->frame+2);
# endif
#endif
QVector<QPointF> newGContour = UniteWithContour(workDetail, j, dEdge); QVector<QPointF> newGContour = UniteWithContour(workDetail, j, dEdge);
newGContour.append(newGContour.first()); newGContour.append(newGContour.first());
const QRectF rec = QPolygonF(newGContour).boundingRect(); const QRectF rec = QPolygonF(newGContour).boundingRect();
bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, dEdge, bestResult.NewResult(static_cast<qint64>(rec.width()*rec.height()), j, dEdge,
workDetail.GetMatrix(), workDetail.IsMirror()); workDetail.GetMatrix(), workDetail.IsMirror());
} }
d->frame = d->frame + 2; d->frame = d->frame + 3;
} }
} }
@ -695,7 +715,7 @@ QVector<QPointF> VLayoutPaper::UniteWithContour(const VLayoutDetail &detail, int
} }
++processedEdges; ++processedEdges;
++j; ++j;
}while (processedEdges <= nD); }while (processedEdges < nD);
} }
else else
{ {
@ -911,7 +931,7 @@ void VLayoutPaper::DrawDebug(const VLayoutDetail &detail, int frame) const
QPainter paint; QPainter paint;
paint.begin(&frameImage); paint.begin(&frameImage);
paint.setPen(QPen(Qt::darkRed, 3, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); paint.setPen(QPen(Qt::darkRed, 10, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
paint.drawRect(QRectF(d->paperWidth/2, d->paperHeight/2, d->paperWidth, d->paperHeight)); paint.drawRect(QRectF(d->paperWidth/2, d->paperHeight/2, d->paperWidth, d->paperHeight));
paint.setPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); paint.setPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));