[Bf-blender-cvs] [dd3aa1b] master: Cleanup: replace confusing 'if' statements

Campbell Barton noreply at git.blender.org
Mon Apr 6 08:42:20 CEST 2015


Commit: dd3aa1b3725c9cd739a0cc0d22f4a3bcfed4fe0b
Author: Campbell Barton
Date:   Mon Apr 6 16:40:26 2015 +1000
Branches: master
https://developer.blender.org/rBdd3aa1b3725c9cd739a0cc0d22f4a3bcfed4fe0b

Cleanup: replace confusing 'if' statements

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

M	source/blender/editors/screen/area.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/render/intern/source/render_texture.c
M	source/blender/render/intern/source/shadeinput.c
M	source/blender/render/intern/source/zbuf.c

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

diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index c423d81..be9336c 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -773,7 +773,7 @@ static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
 	
 	switch (az->edge) {
 		case AE_TOP_TO_BOTTOMRIGHT:
-			if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
+			add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
 			az->x1 = ar->winrct.xmax - 2.5f * AZONEPAD_TAB_PLUSW;
 			az->y1 = ar->winrct.ymax - add;
 			az->x2 = ar->winrct.xmax - 1.5f * AZONEPAD_TAB_PLUSW;
@@ -818,7 +818,7 @@ static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
 	
 	switch (az->edge) {
 		case AE_TOP_TO_BOTTOMRIGHT:
-			if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
+			add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
 			az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
 			az->y1 = ar->winrct.ymax - add;
 			az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
@@ -863,7 +863,7 @@ static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
 	
 	switch (az->edge) {
 		case AE_TOP_TO_BOTTOMRIGHT:
-			if (ar->winrct.ymax == sa->totrct.ymin) add = 1; else add = 0;
+			add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
 			az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
 			az->y1 = ar->winrct.ymax - add;
 			az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 8600c11..e480593 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1482,14 +1482,15 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax,
 	short xminc, yminc, xmaxc, ymaxc, xs, ys;
 	
 	/* clip */
-	if (xmin < 0) xminc = 0; else xminc = xmin;
-	if (xmax >= vc->ar->winx) xmaxc = vc->ar->winx - 1; else xmaxc = xmax;
-	if (xminc > xmaxc) return NULL;
+	xminc = max_ii(xmin, 0);
+	yminc = max_ii(ymin, 0);
+	xmaxc = min_ii(xmax, vc->ar->winx - 1);
+	ymaxc = min_ii(ymax, vc->ar->winy - 1);
+
+	if (UNLIKELY((xminc > xmaxc) || (yminc > ymaxc))) {
+		return NULL;
+	}
 
-	if (ymin < 0) yminc = 0; else yminc = ymin;
-	if (ymax >= vc->ar->winy) ymaxc = vc->ar->winy - 1; else ymaxc = ymax;
-	if (yminc > ymaxc) return NULL;
-	
 	ibuf = IMB_allocImBuf((xmaxc - xminc + 1), (ymaxc - yminc + 1), 32, IB_rect);
 
 	view3d_validate_backbuf(vc);
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index dc8c714..c6a80c8 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -1348,7 +1348,7 @@ int multitex_ext_safe(Tex *tex, float texvec[3], TexResult *texres, struct Image
 /* fact = texture strength, facg = button strength value */
 void texture_rgb_blend(float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype)
 {
-	float facm, col;
+	float facm;
 	
 	switch (blendtype) {
 	case MTEX_BLEND:
@@ -1435,13 +1435,10 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa
 
 	case MTEX_LIGHT:
 		fact*= facg;
-		
-		col= fact*tex[0];
-		if (col > out[0]) in[0]= col; else in[0]= out[0];
-		col= fact*tex[1];
-		if (col > out[1]) in[1]= col; else in[1]= out[1];
-		col= fact*tex[2];
-		if (col > out[2]) in[2]= col; else in[2]= out[2];
+
+		in[0] = max_ff(fact * tex[0], out[0]);
+		in[1] = max_ff(fact * tex[1], out[1]);
+		in[2] = max_ff(fact * tex[2], out[2]);
 		break;
 		
 	case MTEX_BLEND_HUE:
diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c
index 01055d8..9ea7cb6 100644
--- a/source/blender/render/intern/source/shadeinput.c
+++ b/source/blender/render/intern/source/shadeinput.c
@@ -633,7 +633,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float v
 					dyco[2] = 0.0f;
 				
 				if (dxyview) {
-					if (co[2] != 0.0f) fac = 1.0f / co[2]; else fac = 0.0f;
+					fac = (co[2] != 0.0f) ? (1.0f / co[2]) : 0.0f;
 					dxyview[0] = -R.viewdx * fac;
 					dxyview[1] = -R.viewdy * fac;
 				}
diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c
index be2927d..d5d8595 100644
--- a/source/blender/render/intern/source/zbuf.c
+++ b/source/blender/render/intern/source/zbuf.c
@@ -330,8 +330,8 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr,
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	if (my2<my0) return;
 	
@@ -1073,8 +1073,8 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr,
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;
@@ -1196,8 +1196,8 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr,
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;
@@ -1324,8 +1324,8 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr),
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 	
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;
@@ -1426,8 +1426,8 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2,
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 	
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;
@@ -1526,8 +1526,8 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 	
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;
@@ -2480,8 +2480,8 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr,
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 	
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	if (my2<my0) return;
 	
@@ -2681,8 +2681,8 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float
 	/* clipped */
 	if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 	
-	if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-	if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+	my0 = max_ii(zspan->miny1, zspan->miny2);
+	my2 = min_ii(zspan->maxy1, zspan->maxy2);
 	
 	//	printf("my %d %d\n", my0, my2);
 	if (my2<my0) return;




More information about the Bf-blender-cvs mailing list