dust3d/src/cutface.cpp

41 lines
1.2 KiB
C++
Raw Normal View History

#include <QStringList>
#include "cutface.h"
IMPL_CutFaceFromString
IMPL_CutFaceToString
TMPL_CutFaceToPoints
void normalizeCutFacePoints(std::vector<QVector2D> *points)
{
QVector2D center;
if (nullptr == points || points->empty())
return;
float xLow = std::numeric_limits<float>::max();
float xHigh = std::numeric_limits<float>::lowest();
float yLow = std::numeric_limits<float>::max();
float yHigh = std::numeric_limits<float>::lowest();
for (const auto &position: *points) {
if (position.x() < xLow)
xLow = position.x();
else if (position.x() > xHigh)
xHigh = position.x();
if (position.y() < yLow)
yLow = position.y();
else if (position.y() > yHigh)
yHigh = position.y();
}
float xMiddle = (xHigh + xLow) * 0.5;
float yMiddle = (yHigh + yLow) * 0.5;
float xSize = xHigh - xLow;
float ySize = yHigh - yLow;
float longSize = ySize;
if (xSize > longSize)
longSize = xSize;
if (qFuzzyIsNull(longSize))
longSize = 0.000001;
for (auto &position: *points) {
position.setX((position.x() - xMiddle) * 2 / longSize);
position.setY((position.y() - yMiddle) * 2 / longSize);
}
}