summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-11-22 11:43:18 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-11-22 11:43:18 +0100
commit8d3e4df8cf302fe668f332f3eb849ea4f64c6239 (patch)
tree61ad34a56b6c3856c6c64fb000ab2bd71111753f
parent20c1cbace2b9f92380531cd72d86b9dbbcdc7eda (diff)
add nan test in _build_vb_step to prevent stroke building for two consecutive points that are equalsnewvertex
-rw-r--r--src/vectors.c8
-rw-r--r--src/vectors.h2
-rw-r--r--src/vkvg_context_internal.c5
-rw-r--r--tests/curved_rect.c9
4 files changed, 20 insertions, 4 deletions
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 7721be8..d9578ad 100644
--- a/src/vkvg_context_internal.c
+++ b/src/vkvg_context_internal.c
@@ -773,8 +773,13 @@ void add_line(vkvg_context* ctx, vec2 p1, vec2 p2, vec4 col){
}
void _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;
vec2 v1n = vec2_line_norm(ctx->points[i], ctx->points[iR]);
+ if (vec2_isnan(v1n))
+ return;
vec2 bisec = vec2_norm(vec2_add(v0n,v1n));
diff --git a/tests/curved_rect.c b/tests/curved_rect.c
index e7363d5..34e739f 100644
--- a/tests/curved_rect.c
+++ b/tests/curved_rect.c
@@ -6,6 +6,7 @@ void test(){
float x = 50, y = 50, width = 150, height = 140, radius = 30;
vkvg_scale(ctx,2,2);
+ //vkvg_rotate(ctx,0.5f);
vkvg_set_line_width(ctx,15);
vkvg_set_source_rgba(ctx, 0, 0.5f, 0.4f, 1);
@@ -15,16 +16,16 @@ void test(){
radius = MIN(height / 2, width / 2);
vkvg_move_to(ctx, x, y + radius);
- //vkvg_arc(ctx, x + radius, y + radius, radius, M_PIF, (float)-M_PI_2);
+ vkvg_arc(ctx, x + radius, y + radius, radius, M_PIF, (float)-M_PI_2);
vkvg_line_to(ctx, x + width - radius, y);
- //vkvg_arc(ctx, x + width - radius, y + radius, radius, (float)-M_PI_2, 0);
- /*vkvg_line_to(ctx, x + width, y + height - radius);
+ vkvg_arc(ctx, x + width - radius, y + radius, radius, (float)-M_PI_2, 0);
+ vkvg_line_to(ctx, x + width, y + height - radius);
vkvg_arc(ctx, x + width - radius, y + height - radius, radius, 0, (float)M_PI_2);
vkvg_line_to(ctx, x + radius, y + height);
vkvg_arc(ctx, x + radius, y + height - radius, radius, (float)M_PI_2, M_PIF);
vkvg_line_to(ctx, x, y + radius);
vkvg_close_path(ctx);
- vkvg_fill_preserve(ctx);*/
+ vkvg_fill_preserve(ctx);
vkvg_set_source_rgba(ctx,0.5,0,0,0.5);
vkvg_stroke(ctx);