sw_engine: fix max length of trimmed strokes

The error was visible when multiple shapes were
simultaneously trimmed. The length of a single
shape was zeroed out only in selected cases,
which caused accumulation that could lead to
incorrect extension of the variable determining
the maximum length.

@issue: https://github.com/thorvg/thorvg/issues/2173
This commit is contained in:
Mira Grudzinska 2024-04-17 04:25:27 +02:00 committed by GitHub
parent f61efc6d84
commit 3a03fd7080
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -370,8 +370,8 @@ static float _outlineLength(const RenderShape* rshape)
const Point* close = nullptr; const Point* close = nullptr;
auto length = 0.0f; auto length = 0.0f;
auto slength = 0.0f; auto slength = -1.0f;
auto simutaneous = !rshape->stroke->trim.individual; auto simultaneous = !rshape->stroke->trim.individual;
//Compute the whole length //Compute the whole length
while (cmdCnt-- > 0) { while (cmdCnt-- > 0) {
@ -379,8 +379,8 @@ static float _outlineLength(const RenderShape* rshape)
case PathCommand::Close: { case PathCommand::Close: {
length += mathLength(pts - 1, close); length += mathLength(pts - 1, close);
//retrieve the max length of the shape if the simultaneous mode. //retrieve the max length of the shape if the simultaneous mode.
if (simutaneous && slength < length) { if (simultaneous) {
slength = length; if (slength < length) slength = length;
length = 0.0f; length = 0.0f;
} }
break; break;
@ -403,7 +403,7 @@ static float _outlineLength(const RenderShape* rshape)
} }
++cmds; ++cmds;
} }
if (simutaneous && slength > length) return slength; if (simultaneous && slength > length) return slength;
else return length; else return length;
} }