[Bf-blender-cvs] [a4258d4] master: BLI_utildefines: add SQUARE macro

Campbell Barton noreply at git.blender.org
Mon Oct 13 15:36:25 CEST 2014


Commit: a4258d40a1c7148034d3ed704fda7609b2cbb55b
Author: Campbell Barton
Date:   Mon Oct 13 15:35:41 2014 +0200
Branches: master
https://developer.blender.org/rBa4258d40a1c7148034d3ed704fda7609b2cbb55b

BLI_utildefines: add SQUARE macro

also minor cleanup

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

M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenlib/BLI_utildefines.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/transform/transform_conversions.c

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

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 76b0cad..ae6ae60 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -937,7 +937,7 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2],
 	do {
 		rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
 		rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
-	} while (len_squared_v2(rand_pos) > (0.5f * 0.5f));
+	} while (len_squared_v2(rand_pos) > SQUARE(0.5f));
 
 
 	if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 755ce91..7a8843f 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1126,7 +1126,7 @@ static LodLevel *lod_level_select(Object *ob, const float camera_position[3])
 	}
 	else {
 		/* check for lower LoD */
-		while (current->next && dist_sq > (current->next->distance * current->next->distance)) {
+		while (current->next && dist_sq > SQUARE(current->next->distance)) {
 			current = current->next;
 		}
 	}
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index a829cc6..7365783 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -309,10 +309,14 @@
 #define ABS(a)  ({ \
 	typeof(a) a_ = (a); \
 	((a_) < 0 ? (-(a_)) : (a_)); })
+#define SQUARE(a)  ({ \
+	typeof(a) a_ = (a); \
+	((a_) * (a_)); })
 
 #else
 
 #define ABS(a)  ((a) < 0 ? (-(a)) : (a))
+#define SQUARE(a)  ((a) * (a))
 
 #endif
 
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index fc9d1d9..1e9e42f 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -8747,13 +8747,12 @@ static int ui_handler_pie(bContext *C, const wmEvent *event, uiPopupBlockHandle
 				if (!is_click_style) {
 					float len_sq = len_squared_v2v2(event_xy, block->pie_data.pie_center_init);
 
-					if (len_sq > PIE_CLICK_THRESHOLD_SQ)
-					{
+					if (len_sq > PIE_CLICK_THRESHOLD_SQ) {
 						block->pie_data.flags |= UI_PIE_DRAG_STYLE;
 					}
 
 					if ((U.pie_menu_confirm >= U.pie_menu_threshold) &&
-					    (sqrtf(len_sq) >= U.pie_menu_confirm))
+					    (len_sq >= SQUARE(U.pie_menu_confirm)))
 					{
 						block->pie_data.flags |= UI_PIE_GESTURE_END_WAIT;
 						copy_v2_v2(block->pie_data.last_pos, event_xy);
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 509a7f3..431dd54 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -919,7 +919,7 @@ static float calc_vp_strength_col_dl(VPaint *vp, ViewContext *vc, const float co
 	{
 		const float dist_sq = len_squared_v2v2(mval, co_ss);
 
-		if (dist_sq <= brush_size_pressure * brush_size_pressure) {
+		if (dist_sq <= SQUARE(brush_size_pressure)) {
 			Brush *brush = BKE_paint_brush(&vp->paint);
 			const float dist = sqrtf(dist_sq);
 			float factor;
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 0358c1a..58001d4 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -605,7 +605,7 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(
 static int node_tweak_area_reroute(bNode *node, int x, int y)
 {
 	/* square of tweak radius */
-	static const float tweak_radius_sq = 576;  /* 24 * 24 */
+	static const float tweak_radius_sq = SQUARE(24);
 	
 	bNodeSocket *sock = node->inputs.first;
 	float dx = sock->locx - x;
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 86e6e61..e27dafc 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -249,7 +249,7 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
 					}
 
 					dist_sq = len_squared_v3(vec);
-					if ((tob->rdist == -1.0f) || (dist_sq < (tob->rdist * tob->rdist))) {
+					if ((tob->rdist == -1.0f) || (dist_sq < SQUARE(tob->rdist))) {
 						tob->rdist = sqrtf(dist_sq);
 					}
 				}




More information about the Bf-blender-cvs mailing list