Endge of empty sheet shouldn't depend on shift value.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-03-27 22:53:41 +03:00
parent a2aaf0ccff
commit 09d2b96e73
4 changed files with 44 additions and 48 deletions

View File

@ -133,7 +133,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
} }
else else
{ {
if (globalI <= 0 || globalI > EdgesCount()) if (globalI <= 0 || globalI > GlobalEdgesCount())
{ {
return QVector<QPointF>(); return QVector<QPointF>();
} }
@ -205,24 +205,11 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VContour::EdgesCount() const int VContour::GlobalEdgesCount() const
{ {
if (d->globalContour.isEmpty()) if (d->globalContour.isEmpty())
{ {
if (d->shift == 0) return 10;
{
return 1;
}
const int n = qFloor(EmptySheetEdge().length()/d->shift);
if (n <= 0)
{
return 1;
}
else
{
return n;
}
} }
else else
{ {
@ -236,36 +223,28 @@ QLineF VContour::GlobalEdge(int i) const
if (d->globalContour.isEmpty()) //-V807 if (d->globalContour.isEmpty()) //-V807
{ {
// Because sheet is blank we have one global edge for all cases - Ox axis. // Because sheet is blank we have one global edge for all cases - Ox axis.
const QLineF axis = EmptySheetEdge(); if (i < 1 || i > GlobalEdgesCount())
if (d->shift == 0)
{
return axis;
}
const int n = qFloor(axis.length()/d->shift);
if (i < 1 || i > n)
{ // Doesn't exist such edge { // Doesn't exist such edge
return QLineF(); return EmptySheetEdge();
} }
const qreal nShift = axis.length()/n; const qreal nShift = EmptySheetEdge().length()/GlobalEdgesCount();
return QLineF(nShift*(i-1), 0, nShift*i, 0); return QLineF(nShift*(i-1), 0, nShift*i, 0);
} }
else else
{ {
if (i < 1 || i > EdgesCount()) if (i < 1 || i > GlobalEdgesCount())
{ // Doesn't exist such edge { // Doesn't exist such edge
return QLineF(); return QLineF();
} }
QLineF edge; QLineF edge;
if (i < EdgesCount()) if (i < GlobalEdgesCount())
{ {
edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i)); edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i));
} }
else else
{ // Closed countour { // Closed countour
edge = QLineF(d->globalContour.at(EdgesCount()-1), d->globalContour.at(0)); edge = QLineF(d->globalContour.at(GlobalEdgesCount()-1), d->globalContour.at(0));
} }
return edge; return edge;
} }
@ -280,7 +259,8 @@ QVector<QPointF> VContour::CutEdge(const QLineF &edge) const
points.append(edge.p1()); points.append(edge.p1());
points.append(edge.p2()); points.append(edge.p2());
} }
else
{
const int n = qFloor(edge.length()/d->shift); const int n = qFloor(edge.length()/d->shift);
if (n <= 0) if (n <= 0)
@ -298,6 +278,21 @@ QVector<QPointF> VContour::CutEdge(const QLineF &edge) const
points.append(l1.p2()); points.append(l1.p2());
} }
} }
}
return points;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VContour::CutEmptySheetEdge() const
{
QVector<QPointF> points;
const qreal nShift = EmptySheetEdge().length()/GlobalEdgesCount();
for (int i = 1; i <= GlobalEdgesCount()+1; ++i)
{
QLineF l1 = EmptySheetEdge();
l1.setLength(nShift*(i-1));
points.append(l1.p2());
}
return points; return points;
} }

View File

@ -66,9 +66,10 @@ public:
QVector<QPointF> UniteWithContour(const VLayoutDetail &detail, int globalI, int detJ, BestFrom type) const; QVector<QPointF> UniteWithContour(const VLayoutDetail &detail, int globalI, int detJ, BestFrom type) const;
QLineF EmptySheetEdge() const; QLineF EmptySheetEdge() const;
int EdgesCount() const; int GlobalEdgesCount() const;
QLineF GlobalEdge(int i) const; QLineF GlobalEdge(int i) const;
QVector<QPointF> CutEdge(const QLineF &edge) const; QVector<QPointF> CutEdge(const QLineF &edge) const;
QVector<QPointF> CutEmptySheetEdge() const;
const QPointF & at(int i) const; const QPointF & at(int i) const;

View File

@ -198,7 +198,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, volatile bool &stop)
thread_pool->setExpiryTimeout(1000); thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads; QVector<VPosition *> threads;
for (int j=1; j <= d->globalContour.EdgesCount(); ++j) for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j)
{ {
for (int i=1; i<= detail.EdgesCount(); i++) for (int i=1; i<= detail.EdgesCount(); i++)
{ {

View File

@ -162,7 +162,7 @@ void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail,
QPainterPath p; QPainterPath p;
if (contour.GetContour().isEmpty()) if (contour.GetContour().isEmpty())
{ {
p = DrawContour(contour.CutEdge(contour.EmptySheetEdge())); p = DrawContour(contour.CutEmptySheetEdge());
p.translate(biasWidth/2, biasHeight/2); p.translate(biasWidth/2, biasHeight/2);
paint.drawPath(p); paint.drawPath(p);
} }
@ -410,7 +410,7 @@ bool VPosition::CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPosition::CrossingType VPosition::Crossing(const VLayoutDetail &detail, const int &globalI, const int &detailI) const VPosition::CrossingType VPosition::Crossing(const VLayoutDetail &detail, const int &globalI, const int &detailI) const
{ {
int globalEdgesCount = gContour.EdgesCount(); int globalEdgesCount = gContour.GlobalEdgesCount();
if (globalEdgesCount == 0) if (globalEdgesCount == 0)
{ {
globalEdgesCount = 1;// For blank sheet globalEdgesCount = 1;// For blank sheet
@ -489,7 +489,7 @@ VPosition::InsideType VPosition::InsideContour(const VLayoutDetail &detail, cons
} }
else else
{ {
const int polyCorners = gContour.EdgesCount(); const int polyCorners = gContour.GlobalEdgesCount();
int j = polyCorners-1; int j = polyCorners-1;
QVector<qreal> constant; QVector<qreal> constant;