From 6172bdbde86642dbbfdc3c119de6eaf7db7e5993 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 9 May 2016 23:46:36 +1000 Subject: Remove redundant error checks in grease-pencil tessellation --- source/blender/editors/gpencil/drawgpencil.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'source/blender/editors/gpencil/drawgpencil.c') diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 7715169cafb..c364f89dc9f 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -378,9 +378,10 @@ static void gp_stroke_2d_flat(bGPDspoint *points, int totpoints, float(*points2d static void gp_triangulate_stroke_fill(bGPDstroke *gps) { BLI_assert(gps->totpoints >= 3); - + gps->tot_triangles = gps->totpoints - 2; + /* allocate memory for temporary areas */ - unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->totpoints, "GP Stroke temp triangulation"); + unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points"); int direction = 0; @@ -388,24 +389,7 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps) /* convert to 2d and triangulate */ gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); BLI_polyfill_calc((const float(*)[2])points2d, (unsigned int)gps->totpoints, direction, (unsigned int(*)[3])tmp_triangles); - - /* count number of valid triangles, slower but safer */ - gps->tot_triangles = 0; - for (int i = 0; i < gps->totpoints; i++) { - if ((tmp_triangles[i][0] >= 0) && (tmp_triangles[i][0] < gps->totpoints) && - (tmp_triangles[i][1] >= 0) && (tmp_triangles[i][1] < gps->totpoints) && - (tmp_triangles[i][2] >= 0) && (tmp_triangles[i][2] < gps->totpoints)) - { - gps->tot_triangles++; - } - } - - if (gps->tot_triangles > gps->totpoints - 2) { - /* avoid problems with extra (unwanted) triangles getting created */ - gps->tot_triangles = gps->totpoints - 2; - } - //printf("tot triangles: %d / %d - direction = %d\n", gps->tot_triangles, gps->totpoints, direction); - + /* save triangulation data in stroke cache */ if (gps->tot_triangles > 0) { if (gps->triangles == NULL) { -- cgit v1.2.3