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
{
if (globalI <= 0 || globalI > EdgesCount())
if (globalI <= 0 || globalI > GlobalEdgesCount())
{
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->shift == 0)
{
return 1;
}
const int n = qFloor(EmptySheetEdge().length()/d->shift);
if (n <= 0)
{
return 1;
}
else
{
return n;
}
return 10;
}
else
{
@ -236,36 +223,28 @@ QLineF VContour::GlobalEdge(int i) const
if (d->globalContour.isEmpty()) //-V807
{
// Because sheet is blank we have one global edge for all cases - Ox axis.
const QLineF axis = EmptySheetEdge();
if (d->shift == 0)
{
return axis;
}
const int n = qFloor(axis.length()/d->shift);
if (i < 1 || i > n)
if (i < 1 || i > GlobalEdgesCount())
{ // 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);
}
else
{
if (i < 1 || i > EdgesCount())
if (i < 1 || i > GlobalEdgesCount())
{ // Doesn't exist such edge
return QLineF();
}
QLineF edge;
if (i < EdgesCount())
if (i < GlobalEdgesCount())
{
edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i));
}
else
{ // 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;
}
@ -280,23 +259,39 @@ QVector<QPointF> VContour::CutEdge(const QLineF &edge) const
points.append(edge.p1());
points.append(edge.p2());
}
const int n = qFloor(edge.length()/d->shift);
if (n <= 0)
{
points.append(edge.p1());
points.append(edge.p2());
}
else
{
const qreal nShift = edge.length()/n;
for (int i = 1; i <= n+1; ++i)
const int n = qFloor(edge.length()/d->shift);
if (n <= 0)
{
QLineF l1 = edge;
l1.setLength(nShift*(i-1));
points.append(l1.p2());
points.append(edge.p1());
points.append(edge.p2());
}
else
{
const qreal nShift = edge.length()/n;
for (int i = 1; i <= n+1; ++i)
{
QLineF l1 = edge;
l1.setLength(nShift*(i-1));
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;
}

View File

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

View File

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