Fixed SumTrapezoids method
--HG-- branch : feature
This commit is contained in:
parent
40ef4732ca
commit
d679187f15
|
@ -508,29 +508,33 @@ QPointF VAbstractDetail::SingleParallelPoint(const QLineF &line, const qreal &an
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VAbstractDetail::SumTrapezoids(int n, QVector<qreal> x, QVector<qreal> y)
|
||||
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();
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
if(n > 2)
|
||||
{
|
||||
if (i == 0)
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
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)
|
||||
if (i == 0)
|
||||
{
|
||||
s = x.at(i)*(y.at(i-1) - y.at(0)); // if i == n-1, then y[i+1] replace on y[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
|
||||
{
|
||||
s = x.at(i)*(y.at(i-1) - y.at(i+1));
|
||||
res += s;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
void setWidth(const qreal &value);
|
||||
|
||||
static QVector<QPointF> Equidistant(const QVector<QPointF> &points, const EquidistantType &eqv, qreal width);
|
||||
static qreal SumTrapezoids(int n, QVector<qreal> x, QVector<qreal> y);
|
||||
static qreal SumTrapezoids(const QVector<QPointF> &points);
|
||||
|
||||
|
||||
protected:
|
||||
|
|
|
@ -288,21 +288,10 @@ qint64 VLayoutDetail::Square() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
const int n = d->layoutAllowence.count();
|
||||
qint64 sq = 0;
|
||||
const QVector<QPointF> points = d->layoutAllowence;
|
||||
const qreal res = SumTrapezoids(points);
|
||||
|
||||
QVector<qreal> x;
|
||||
QVector<qreal> y;
|
||||
|
||||
for (int i=0; i < n; ++i)
|
||||
{
|
||||
x.append(d->layoutAllowence.at(i).x());
|
||||
y.append(d->layoutAllowence.at(i).y());
|
||||
}
|
||||
|
||||
qreal res = this->SumTrapezoids(n, x, y);
|
||||
|
||||
sq = qFloor(qAbs(res/2.0));
|
||||
const qint64 sq = qFloor(qAbs(res/2.0));
|
||||
return sq;
|
||||
}
|
||||
|
||||
|
|
|
@ -463,11 +463,11 @@ bool DialogDetail::DetailIsValid() const
|
|||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
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() + "\"/>" + QString(" ");
|
||||
|
||||
if (ui.listWidget->count() < 3)
|
||||
{
|
||||
url += QString(" ") + tr("You need more points!");
|
||||
url += tr("You need more points!");
|
||||
ui.helpLabel->setText(url);
|
||||
return false;
|
||||
}
|
||||
|
@ -475,13 +475,13 @@ bool DialogDetail::DetailIsValid() const
|
|||
{
|
||||
if(not DetailIsClockwise())
|
||||
{
|
||||
url += QString(" ") +tr("You have to choose points in a clockwise direction!");
|
||||
url += tr("You have to choose points in a clockwise direction!");
|
||||
ui.helpLabel->setText(url);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ bool DialogDetail::DetailIsValid() const
|
|||
|
||||
if (QString::compare(previousRow, nextRow) == 0)
|
||||
{
|
||||
url += QString(" ") +tr("You have double points!");
|
||||
url += tr("You have double points!");
|
||||
ui.helpLabel->setText(url);
|
||||
return false;
|
||||
}
|
||||
|
@ -528,28 +528,19 @@ bool DialogDetail::FirstPointEqualLast() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool DialogDetail::DetailIsClockwise() const
|
||||
{
|
||||
VDetail detail;
|
||||
if(ui.listWidget->count() < 3)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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)));
|
||||
}
|
||||
QVector<QPointF> points = detail.ContourPoints(data);
|
||||
const QVector<QPointF> points = detail.ContourPoints(data);
|
||||
|
||||
QVector<qreal> x;
|
||||
QVector<qreal> y;
|
||||
const int n = points.size();
|
||||
for (int i=0; i < n; ++i)
|
||||
{
|
||||
x.append(points.at(i).x());
|
||||
y.append(points.at(i).y());
|
||||
}
|
||||
|
||||
qreal res = detail.SumTrapezoids(n, x, y);
|
||||
const qreal res = VDetail::SumTrapezoids(points);
|
||||
if (res < 0)
|
||||
{
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user