mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
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:
parent
38e2812004
commit
66048b31b5
2 changed files with 5 additions and 8 deletions
|
@ -57,6 +57,7 @@ WgPolyline::WgPolyline()
|
||||||
constexpr uint32_t nPoints = 360;
|
constexpr uint32_t nPoints = 360;
|
||||||
pts.reserve(nPoints);
|
pts.reserve(nPoints);
|
||||||
dist.reserve(nPoints);
|
dist.reserve(nPoints);
|
||||||
|
closed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,12 +150,7 @@ void WgPolyline::trim(WgPolyline* polyline, float trimBegin, float trimEnd) cons
|
||||||
void WgPolyline::close()
|
void WgPolyline::close()
|
||||||
{
|
{
|
||||||
if (pts.count > 0) appendPoint(pts[0]);
|
if (pts.count > 0) appendPoint(pts[0]);
|
||||||
}
|
closed = true;
|
||||||
|
|
||||||
|
|
||||||
bool WgPolyline::isClosed() const
|
|
||||||
{
|
|
||||||
return (pts.count >= 2) && (mathZero(pts[0].dist2(pts.last())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,6 +162,7 @@ void WgPolyline::clear()
|
||||||
// clear points and distances
|
// clear points and distances
|
||||||
pts.clear();
|
pts.clear();
|
||||||
dist.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
|
} 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 v0 = polyline->pts[polyline->pts.count - 2];
|
||||||
WgPoint v1 = polyline->pts[0];
|
WgPoint v1 = polyline->pts[0];
|
||||||
WgPoint v2 = polyline->pts[1];
|
WgPoint v2 = polyline->pts[1];
|
||||||
|
|
|
@ -84,6 +84,7 @@ struct WgPolyline
|
||||||
uint32_t imaxy{};
|
uint32_t imaxy{};
|
||||||
// total polyline length
|
// total polyline length
|
||||||
float len{};
|
float len{};
|
||||||
|
bool closed{};
|
||||||
|
|
||||||
WgPolyline();
|
WgPolyline();
|
||||||
|
|
||||||
|
@ -95,7 +96,6 @@ struct WgPolyline
|
||||||
void close();
|
void close();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool isClosed() const;
|
|
||||||
void getBBox(WgPoint& pmin, WgPoint& pmax) const;
|
void getBBox(WgPoint& pmin, WgPoint& pmax) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue