From: Jean-Philippe Bruyère Date: Sat, 5 Mar 2022 06:43:29 +0000 (+0100) Subject: use _get_arcstep for stroke joins X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d08356a5fe31f1c1b9b5bd27dc5c3828d6f46ead;p=jp%2Fvkvg.git use _get_arcstep for stroke joins --- diff --git a/include/vkvg.h b/include/vkvg.h index a629fff..5e21396 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -90,6 +90,7 @@ extern "C" { #define VKVG_LOG_INFO_IBO 0x00000040 #define VKVG_LOG_INFO_VAO (VKVG_LOG_INFO_VBO|VKVG_LOG_INFO_IBO) #define VKVG_LOG_DBG_ARRAYS 0x00001000 +#define VKVG_LOG_STROKE 0x00010000 #define VKVG_LOG_FULL 0xffffffff #define VKVG_LOG_INFO 0x00008000//(VKVG_LOG_INFO_PTS|VKVG_LOG_INFO_PATH|VKVG_LOG_INFO_CMD|VKVG_LOG_INFO_VAO) @@ -1898,8 +1899,6 @@ void* vkvg_recording_get_data (VkvgRecording rec); vkvg_public void vkvg_recording_destroy (VkvgRecording rec); /*************************************/ - - #endif #ifdef __cplusplus diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 415037a..900c29a 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -240,10 +240,10 @@ void _add_point (VkvgContext ctx, float x, float y){ } float _normalizeAngle(float a) { - float res = ROUND_DOWN(fmodf(a, 2.0f * M_PIF), 100); + float res = ROUND_DOWN(fmodf(a, 2.0f * M_PIF), 100); if (res < 0.0f) - res += 2.0f * M_PIF; - return res; + res += 2.0f * M_PIF; + return res; } float _get_arc_step (VkvgContext ctx, float radius) { float sx, sy; @@ -902,14 +902,18 @@ bool _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool is vec2 v1 = vec2_sub(pR, p0); float length_v0 = vec2_length(v0); float length_v1 = vec2_length(v1); - if (length_v0 < FLT_EPSILON || length_v1 < FLT_EPSILON) + if (length_v0 < FLT_EPSILON || length_v1 < FLT_EPSILON) { + LOG(VKVG_LOG_STROKE, "vb_step discard, lengtharcStep) + str->arcStep = _get_arc_step (ctx, hw); float a = acosf(vp.x); if (vp.y < 0) a = -a; @@ -1079,17 +1085,17 @@ bool _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool is if (det<0){ a+=M_PIF; float a1 = a + alpha; - a-=step; + a-=str->arcStep; while (a > a1){ _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y); - a-=step; + a-=str->arcStep; } }else{ float a1 = a + alpha; - a+=step; + a+=str->arcStep; while (a < a1){ _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y); - a+=step; + a+=str->arcStep; } } VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index fdf951f..1303392 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -248,7 +248,8 @@ typedef struct { uint32_t cp;//current point VKVG_IBO_INDEX_TYPE firstIdx;//save first point idx for closed path - float lhMax;//miter limit * line width + float lhMax; //miter limit * line width + float arcStep; //cached arcStep, prevent compute multiple times for same stroke, 0 if not yet computed }stroke_context_t; void _check_vertex_cache_size (VkvgContext ctx);