mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
wg_engine: fix stroke trimming
Prevent crash for begin == end;
This commit is contained in:
parent
47d3d7e7d5
commit
b3b619349d
1 changed files with 27 additions and 28 deletions
|
@ -362,26 +362,24 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
|||
appendShape(context, path_buff);
|
||||
});
|
||||
// append shape with strokes
|
||||
} else if (rshape.stroke->trim.simultaneous) {
|
||||
} else {
|
||||
float tbeg{}, tend{};
|
||||
if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; }
|
||||
if (tbeg == tend) return;
|
||||
if (tbeg == tend) {
|
||||
pbuff.decodePath(rshape, false, [&](const WgVertexBuffer& path_buff) {
|
||||
appendShape(context, path_buff);
|
||||
});
|
||||
} else if (rshape.stroke->trim.simultaneous) {
|
||||
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
||||
appendShape(context, path_buff);
|
||||
proceedStrokes(context, rshape.stroke, tbeg, tend, path_buff);
|
||||
});
|
||||
// append shape with strokes with simultaneous flag
|
||||
} else {
|
||||
float totalLen = 0.0f;
|
||||
// append shapes
|
||||
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
||||
appendShape(context, path_buff);
|
||||
totalLen += path_buff.total();
|
||||
});
|
||||
// append strokes
|
||||
float tbeg{}, tend{};
|
||||
if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; }
|
||||
if (tbeg == tend) return;
|
||||
float len_beg = totalLen * tbeg; // trim length begin
|
||||
float len_end = totalLen * tend; // trim length end
|
||||
float len_acc = 0.0; // accumulated length
|
||||
|
@ -395,6 +393,7 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
|||
len_acc += len_path;
|
||||
});
|
||||
}
|
||||
}
|
||||
// update shapes bbox
|
||||
updateAABB(tr);
|
||||
meshDataBBox.update(context, pMin, pMax);
|
||||
|
|
Loading…
Add table
Reference in a new issue