wg_engine: fix shapes closing

Shapes were incorrectly closed in certain cases -
the decision to close a shape or not should be based on
path commands rather than the number of points and
their distances from each other.
This commit is contained in:
Mira Grudzinska 2024-06-24 00:35:27 +02:00 committed by Hermet Park
parent 38e2812004
commit 66048b31b5
2 changed files with 5 additions and 8 deletions

View file

@ -57,6 +57,7 @@ WgPolyline::WgPolyline()
constexpr uint32_t nPoints = 360;
pts.reserve(nPoints);
dist.reserve(nPoints);
closed = false;
}
@ -149,12 +150,7 @@ void WgPolyline::trim(WgPolyline* polyline, float trimBegin, float trimEnd) cons
void WgPolyline::close()
{
if (pts.count > 0) appendPoint(pts[0]);
}
bool WgPolyline::isClosed() const
{
return (pts.count >= 2) && (mathZero(pts[0].dist2(pts.last())));
closed = true;
}
@ -166,6 +162,7 @@ void WgPolyline::clear()
// clear points and distances
pts.clear();
dist.clear();
closed = false;
}
@ -406,7 +403,7 @@ void WgGeometryData::appendStroke(const WgPolyline* polyline, const RenderStroke
);
}
} else if (polyline->pts.count > 2) { // multi-lined sub-path
if (polyline->isClosed()) {
if (polyline->closed) {
WgPoint v0 = polyline->pts[polyline->pts.count - 2];
WgPoint v1 = polyline->pts[0];
WgPoint v2 = polyline->pts[1];

View file

@ -84,6 +84,7 @@ struct WgPolyline
uint32_t imaxy{};
// total polyline length
float len{};
bool closed{};
WgPolyline();
@ -95,7 +96,6 @@ struct WgPolyline
void close();
void clear();
bool isClosed() const;
void getBBox(WgPoint& pmin, WgPoint& pmax) const;
};