[Bf-blender-cvs] [6172bdb] master: Remove redundant error checks in grease-pencil tessellation

Campbell Barton noreply at git.blender.org
Mon May 9 15:42:40 CEST 2016


Commit: 6172bdbde86642dbbfdc3c119de6eaf7db7e5993
Author: Campbell Barton
Date:   Mon May 9 23:46:36 2016 +1000
Branches: master
https://developer.blender.org/rB6172bdbde86642dbbfdc3c119de6eaf7db7e5993

Remove redundant error checks in grease-pencil tessellation

===================================================================

M	source/blender/editors/gpencil/drawgpencil.c

===================================================================

diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 7715169..c364f89 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) {




More information about the Bf-blender-cvs mailing list