[Bf-blender-cvs] [388bb6ec857] greasepencil-object: Cleanup: Use M_PI instead of converting from degrees to radians

Joshua Leung noreply at git.blender.org
Tue Jan 30 07:05:32 CET 2018


Commit: 388bb6ec857585b5961102298c10d8f7397c6259
Author: Joshua Leung
Date:   Tue Jan 30 15:44:03 2018 +1300
Branches: greasepencil-object
https://developer.blender.org/rB388bb6ec857585b5961102298c10d8f7397c6259

Cleanup: Use M_PI instead of converting from degrees to radians

Note: While the center/radius calcs may benefit from using the
BLI_math funcs, the current implementation is more direct.

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index fce09ba6036..17063128d81 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -247,15 +247,15 @@ static void gp_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D)
 }
 
 /* create a circle */
-// TODO: vectorise, use M_PI, ...
 static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
 {
 	const int totpoints = tgpi->tot_edges;
-	const float step = DEG2RADF(360.0f / (float)(totpoints));
+	const float step = (2.0f * M_PI) / (float)(totpoints);
 	float center[2];
 	float radius[2];
 	float a = 0.0f;
 	
+	/* TODO: Use math-lib functions for these? */
 	center[0] = tgpi->top[0] + ((tgpi->bottom[0] - tgpi->top[0]) / 2.0f);
 	center[1] = tgpi->top[1] + ((tgpi->bottom[1] - tgpi->top[1]) / 2.0f);
 	radius[0] = fabsf(((tgpi->bottom[0] - tgpi->top[0]) / 2.0f));
@@ -264,8 +264,8 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
 	for (int i = 0; i < totpoints; i++) {
 		tGPspoint *p2d = &points2D[i];
 		
-		p2d->x = (int)(center[0] + cos(a) * radius[0]);
-		p2d->y = (int)(center[1] + sin(a) * radius[1]);
+		p2d->x = (int)(center[0] + cosf(a) * radius[0]);
+		p2d->y = (int)(center[1] + sinf(a) * radius[1]);
 		a += step;
 	}
 }



More information about the Bf-blender-cvs mailing list