From f4c2d116d965bcce6baadedc7ec87563a3a377c3 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 13 Feb 2025 18:24:49 +0100 Subject: [PATCH] wg_engine: fix dash offset behavior For an odd number of dash/gap segments, the offset was handled incorrectly because the non-doubled count of dashes and gaps was used. Additionally, in ddcbbf7, an error was introduced by overlooking the fact that the offset can shift the dash pattern in such a way that the first segment of the dashed line becomes a gap. --- src/renderer/wg_engine/tvgWgGeometry.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/wg_engine/tvgWgGeometry.h b/src/renderer/wg_engine/tvgWgGeometry.h index ce6156f4..70a8e12a 100755 --- a/src/renderer/wg_engine/tvgWgGeometry.h +++ b/src/renderer/wg_engine/tvgWgGeometry.h @@ -295,21 +295,22 @@ struct WgVertexBufferInd float len_total = dashPattern[index_dash]; // get dashes length float dashes_lenth{}; - for (uint32_t i = 0; i < dashCnt; i++) - dashes_lenth += dashPattern[i]; + for (uint32_t i = 0; i < dashCnt * (dashCnt % 2 + 1); i++) + dashes_lenth += dashPattern[i % dashCnt]; if (dashes_lenth == 0) return; // normalize dash offset float dashOffset = rstroke->dashOffset; while(dashOffset < 0) dashOffset += dashes_lenth; while(dashOffset > dashes_lenth) dashOffset -= dashes_lenth; + auto gap = false; // scip dashes by offset - while(len_total < dashOffset) { + while(len_total < dashOffset) { index_dash = (index_dash + 1) % dashCnt; len_total += dashPattern[index_dash]; + gap = !gap; } len_total -= dashOffset; // iterate by polyline points - auto gap = false; for (uint32_t i = 0; i < buff.vcount - 1; i++) { // append current polyline point if (!gap) dashed.append(buff.vbuff[i]);