--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-22 17:02:08 +02:00
commit e8570f9812
5 changed files with 72 additions and 39 deletions

View File

@ -506,3 +506,37 @@ QPointF VAbstractDetail::SingleParallelPoint(const QLineF &line, const qreal &an
pLine.setLength( width ); pLine.setLength( width );
return pLine.p2(); return pLine.p2();
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VAbstractDetail::SumTrapezoids(const QVector<QPointF> &points)
{
// Calculation a polygon area through the sum of the areas of trapezoids
qreal s, res = 0;
const int n = points.size();
if(n > 2)
{
for (int i = 0; i < n; ++i)
{
if (i == 0)
{
s = points.at(i).x()*(points.at(n-1).y() - points.at(i+1).y()); //if i == 0, then y[i-1] replace on y[n-1]
res += s;
}
else
{
if (i == n-1)
{
s = points.at(i).x()*(points.at(i-1).y() - points.at(0).y()); // if i == n-1, then y[i+1] replace on y[0]
res += s;
}
else
{
s = points.at(i).x()*(points.at(i-1).y() - points.at(i+1).y());
res += s;
}
}
}
}
return res;
}

View File

@ -65,6 +65,8 @@ 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);
static qreal SumTrapezoids(const QVector<QPointF> &points);
protected: protected:
static QVector<QPointF> RemoveDublicates(const QVector<QPointF> &points); static QVector<QPointF> RemoveDublicates(const QVector<QPointF> &points);

View File

@ -288,42 +288,9 @@ qint64 VLayoutDetail::Square() const
return 0; return 0;
} }
const int n = d->layoutAllowence.count(); const qreal res = SumTrapezoids(d->layoutAllowence);
qreal s, res = 0;
qint64 sq = 0;
QVector<qreal> x; const qint64 sq = qFloor(qAbs(res/2.0));
QVector<qreal> y;
for (int i=0; i < n; ++i)
{
x.append(d->layoutAllowence.at(i).x());
y.append(d->layoutAllowence.at(i).y());
}
// Calculation a polygon area through the sum of the areas of trapezoids
for (int i = 0; i < n; ++i)
{
if (i == 0)
{
s = x.at(i)*(y.at(n-1) - y.at(i+1)); //if i == 0, then y[i-1] replace on y[n-1]
res += s;
}
else
{
if (i == n-1)
{
s = x.at(i)*(y.at(i-1) - y.at(0)); // if i == n-1, then y[i+1] replace on y[0]
res += s;
}
else
{
s = x.at(i)*(y.at(i-1) - y.at(i+1));
res += s;
}
}
}
sq = qFloor(qAbs(res/2.0));
return sq; return sq;
} }

View File

@ -463,19 +463,25 @@ bool DialogDetail::DetailIsValid() const
QByteArray byteArray; QByteArray byteArray;
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
pixmap.save(&buffer, "PNG"); pixmap.save(&buffer, "PNG");
QString url = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + "\"/>"; QString url = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + QLatin1Literal("\"/> ");
if (ui.listWidget->count() < 3) if (ui.listWidget->count() < 3)
{ {
url += QString(" ") + tr("You need more points!"); url += tr("You need more points!");
ui.helpLabel->setText(url); ui.helpLabel->setText(url);
return false; return false;
} }
else else
{ {
if(not DetailIsClockwise())
{
url += tr("You have to choose points in a clockwise direction!");
ui.helpLabel->setText(url);
return false;
}
if (FirstPointEqualLast()) if (FirstPointEqualLast())
{ {
url += QString(" ") +tr("First point can not equal the last point!"); url += tr("First point can not equal the last point!");
ui.helpLabel->setText(url); ui.helpLabel->setText(url);
return false; return false;
} }
@ -488,7 +494,7 @@ bool DialogDetail::DetailIsValid() const
if (QString::compare(previousRow, nextRow) == 0) if (QString::compare(previousRow, nextRow) == 0)
{ {
url += QString(" ") +tr("You have double points!"); url += tr("You have double points!");
ui.helpLabel->setText(url); ui.helpLabel->setText(url);
return false; return false;
} }
@ -518,3 +524,26 @@ bool DialogDetail::FirstPointEqualLast() const
} }
return false; return false;
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogDetail::DetailIsClockwise() const
{
if(ui.listWidget->count() < 3)
{
return false;
}
VDetail detail;
for (qint32 i = 0; i < ui.listWidget->count(); ++i)
{
QListWidgetItem *item = ui.listWidget->item(i);
detail.append( qvariant_cast<VNodeDetail>(item->data(Qt::UserRole)));
}
const QVector<QPointF> points = detail.ContourPoints(data);
const qreal res = VDetail::SumTrapezoids(points);
if (res < 0)
{
return true;
}
return false;
}

View File

@ -78,6 +78,7 @@ private:
bool flagWidth; bool flagWidth;
bool DetailIsValid() const; bool DetailIsValid() const;
bool FirstPointEqualLast() const; bool FirstPointEqualLast() const;
bool DetailIsClockwise() const;
void NewItem(quint32 id, const Tool &typeTool, const NodeDetail &typeNode, void NewItem(quint32 id, const Tool &typeTool, const NodeDetail &typeNode,
qreal mx = 0, qreal my = 0, bool reverse = false); qreal mx = 0, qreal my = 0, bool reverse = false);