mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
wg_engine: fix stroke trimming
Fix cases when begin < 0 - this require handling the stroke in two parts: begin - 0 and 0 - end. Improve trimming for simultaneous=true.
This commit is contained in:
parent
fa17fcde81
commit
2fc0aad2d1
2 changed files with 25 additions and 14 deletions
|
@ -125,15 +125,8 @@ struct WgVertexBuffer {
|
|||
|
||||
// append source vertex buffer in index range from start to end (end not included)
|
||||
void appendRange(const WgVertexBuffer& buff, size_t start_index, size_t end_index) {
|
||||
if (start_index <= end_index)
|
||||
for (size_t i = start_index; i < end_index; i++)
|
||||
append(buff.vbuff[i]);
|
||||
if (start_index > end_index) {
|
||||
for (size_t i = start_index; i < buff.vcount; i++)
|
||||
append(buff.vbuff[i]);
|
||||
for (size_t i = 0; i < end_index; i++)
|
||||
append(buff.vbuff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// append circle (list of triangles)
|
||||
|
|
|
@ -365,6 +365,7 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
|||
} else {
|
||||
float tbeg{}, tend{};
|
||||
if (!rshape.stroke->strokeTrim(tbeg, tend)) { tbeg = 0.0f; tend = 1.0f; }
|
||||
bool loop = tbeg > tend;
|
||||
if (tbeg == tend) {
|
||||
pbuff.decodePath(rshape, false, [&](const WgVertexBuffer& path_buff) {
|
||||
appendShape(context, path_buff);
|
||||
|
@ -372,7 +373,12 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
|||
} else if (rshape.stroke->trim.simultaneous) {
|
||||
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
||||
appendShape(context, path_buff);
|
||||
if (loop) {
|
||||
proceedStrokes(context, rshape.stroke, tbeg, 1.0f, path_buff);
|
||||
proceedStrokes(context, rshape.stroke, 0.0f, tend, path_buff);
|
||||
} else {
|
||||
proceedStrokes(context, rshape.stroke, tbeg, tend, path_buff);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
float totalLen = 0.0f;
|
||||
|
@ -386,10 +392,22 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
|||
// append strokes
|
||||
pbuff.decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
||||
float len_path = path_buff.total(); // current path length
|
||||
float tbeg = ((len_acc <= len_beg) && (len_acc + len_path > len_beg)) ? (len_beg - len_acc) / len_path : 0.0f;
|
||||
float tend = ((len_acc <= len_end) && (len_acc + len_path > len_end)) ? (len_end - len_acc) / len_path : 1.0f;
|
||||
if ((len_acc + len_path >= len_beg) && (len_acc <= len_end))
|
||||
if (loop) {
|
||||
if (len_acc + len_path >= len_beg) {
|
||||
auto tbeg = len_acc <= len_beg ? (len_beg - len_acc) / len_path : 0.0f;
|
||||
proceedStrokes(context, rshape.stroke, tbeg, 1.0f, path_buff);
|
||||
}
|
||||
if (len_acc < len_end) {
|
||||
auto tend = len_acc + len_path >= len_end ? (len_end - len_acc) / len_path : 1.0f;
|
||||
proceedStrokes(context, rshape.stroke, 0.0f, tend, path_buff);
|
||||
}
|
||||
} else {
|
||||
if (len_acc + len_path >= len_beg && len_acc <= len_end) {
|
||||
auto tbeg = len_acc <= len_beg ? (len_beg - len_acc) / len_path : 0.0f;
|
||||
auto tend = len_acc + len_path >= len_end ? (len_end - len_acc) / len_path : 1.0f;
|
||||
proceedStrokes(context, rshape.stroke, tbeg, tend, path_buff);
|
||||
}
|
||||
}
|
||||
len_acc += len_path;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue