From 96be683460ed968aa0f240a06a2ab2244b1951a2 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Mon, 17 Feb 2025 15:24:50 +0100 Subject: [PATCH] wg/gl_engine: standardize shapes closing precision The sw_engine, when determining the outline, converts floats to ints by multiplying them x64, resulting in a comparison precision of 1/64 = 0.015625. Both gl_engine and wg_engine operate on floats. Before adding a closing point to a shape, they performed a comparison to check if the point differed from the starting point: - wg: with a precision of 1e-3 (using length2, i.e., eps = 1e-6 - gl: used direct == comparison. Now, consistency has been ensured by introducing a comparison precision of 1/64 in both wg_engine and gl_engine. @issue: https://github.com/thorvg/thorvg/issues/2799 @issue: https://github.com/thorvg/thorvg/issues/3235 --- src/renderer/gl_engine/tvgGlTessellator.cpp | 2 +- src/renderer/wg_engine/tvgWgGeometry.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/gl_engine/tvgGlTessellator.cpp b/src/renderer/gl_engine/tvgGlTessellator.cpp index 4d90746f..eb794f6a 100644 --- a/src/renderer/gl_engine/tvgGlTessellator.cpp +++ b/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -1746,7 +1746,7 @@ void Stroker::strokeCubicTo(const Point& cnt1, const Point& cnt2, const Point& e void Stroker::strokeClose() { - if (mStrokeState.prevPt != mStrokeState.firstPt) { + if (length(mStrokeState.prevPt - mStrokeState.firstPt) > 0.015625f) { this->strokeLineTo(mStrokeState.firstPt); } diff --git a/src/renderer/wg_engine/tvgWgGeometry.h b/src/renderer/wg_engine/tvgWgGeometry.h index edf2ff71..caa889fc 100755 --- a/src/renderer/wg_engine/tvgWgGeometry.h +++ b/src/renderer/wg_engine/tvgWgGeometry.h @@ -148,7 +148,7 @@ struct WgVertexBuffer void close() { // check if last point is not to close to the first point - if (!tvg::zero(length2(data[0] - last()))) { + if (length(data[0] - last()) > 0.015625f) { append(data[0]); } closed = true;