Commit 412453b1 by Volker Krause

### Produce valid results when simplifying areas close to the threshold

```When the simplified area extends not significantly more than the size
threshold in one direction, the result of the Douglas Peucker algorithm
can deteriorate into a area-less polygon. In this case we fall back to
the bounding box instead now.

It's not that those small features have much practical impact, but the
resulting broken polygons cause problems in subsequent use.```
parent 24760e75
 ... ... @@ -39,9 +39,18 @@ static QPolygonF douglasPeucker(const QPolygonF::const_iterator &begin, const QP return QPolygonF(QVector({*begin, (*std::prev(end))})); } QPolygonF PolygonSimplifier::douglasPeucker(const QPolygonF &poly, double distance) QPolygonF PolygonSimplifier::douglasPeucker(const QPolygonF &poly, double threshold) { auto result = douglasPeucker(poly.begin(), poly.end(), distance); qDebug() << "got" << poly.size() << "dropped" << poly.size() - result.size(); auto result = douglasPeucker(poly.begin(), poly.end(), threshold); qDebug() << "got" << poly.size() << "dropped" << poly.size() - result.size() << "remaining" << result.size(); // if the polygon itself is smaller than the threshold, the result can deteriorate into // an area-less structure, take the bounding rect in that case if (result.size() < 4) { qDebug() << " result deteriorated, taking bounding rect instead"; const auto bbox = poly.boundingRect(); return QPolygonF({ bbox.topLeft(), bbox.topRight(), bbox.bottomRight(), bbox.bottomLeft(), bbox.topLeft() }); } return result; }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment