From: Jean-Philippe Bruyère Date: Wed, 22 Jan 2020 20:06:44 +0000 (+0100) Subject: add nan test in _build_vb_step to prevent stroke building for two consecutive points... X-Git-Tag: v0.1-alpha~45 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=ba0f72391af2f4007c9e3d4e1775f18f7f5b147e;p=jp%2Fvkvg.git add nan test in _build_vb_step to prevent stroke building for two consecutive points that are equals --- diff --git a/src/vectors.c b/src/vectors.c index 686db85..b29180b 100644 --- a/src/vectors.c +++ b/src/vectors.c @@ -108,3 +108,11 @@ void vec2_inv (vec2* v){ v->x = -v->x; v->y = -v->y; } +// test if one component of float vector is nan +inline bool vec2_isnan (vec2 v){ + return (bool)(isnanf (v.x) || isnanf (v.y)); +} +// test if one component of double vector is nan +inline bool vec2d_isnan (vec2d v){ + return (bool)(isnan (v.x) || isnan (v.y)); +} diff --git a/src/vectors.h b/src/vectors.h index 6352e5e..97b0f6c 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -80,6 +80,7 @@ vec2 vec2_sub (vec2 a, vec2 b); vec2 vec2_mult (vec2 a, float m); bool vec2_equ (vec2 a, vec2 b); vec2 vec2_line_norm (vec2 a, vec2 b); +bool vec2_isnan (vec2 v); double vec2d_length(vec2d v); vec2d vec2d_norm (vec2d a); @@ -88,6 +89,7 @@ vec2d vec2d_add (vec2d a, vec2d b); vec2d vec2d_sub (vec2d a, vec2d b); vec2d vec2d_mult (vec2d a, double m); vec2d vec2d_line_norm(vec2d a, vec2d b); +bool vec2d_isnan (vec2d v); vec2 vec2d_to_vec2(vec2d vd); void vec2_inv (vec2* v); diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index e3136a7..76e7f0a 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -665,8 +665,13 @@ void _init_descriptor_sets (VkvgContext ctx){ } float _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_t i, uint32_t iR, bool isCurve){ + //if two of the three points are equal, normal is null vec2 v0n = vec2_line_norm(ctx->points[iL], ctx->points[i]); + if (vec2_isnan(v0n)) + return 0; vec2 v1n = vec2_line_norm(ctx->points[i], ctx->points[iR]); + if (vec2_isnan(v1n)) + return 0; vec2 bisec = vec2_norm(vec2_add(v0n,v1n));