diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-07-29 22:14:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-07-29 22:14:20 +0400 |
commit | 7217927414407f8929a02c610fb06e61c0bff930 (patch) | |
tree | e1b473aa26d01cdf9f0f7597c8ac255be56362de /source/blender | |
parent | f608b3c44402ef5c58217481d93e7fa83c9cd7cf (diff) |
add inline functions for max/min ints, good to use when the arguments are function calls (we had a few of these).
Diffstat (limited to 'source/blender')
13 files changed, 32 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index f0907d20ce2..545ec0812ee 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -545,7 +545,9 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, Sequence *metase * since sound is played outside of evaluating the imbufs, */ for (seq = metaseq->seqbase.first; seq; seq = seq->next) { if (seq->type == SEQ_TYPE_META) { - seq_update_sound_bounds_recursive_rec(scene, seq, MAX2(start, metaseq_start(seq)), MIN2(end, metaseq_end(seq))); + seq_update_sound_bounds_recursive_rec(scene, seq, + maxi(start, metaseq_start(seq)), + mini(end, metaseq_end(seq))); } else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { if (seq->scene_sound) { @@ -3140,7 +3142,7 @@ int seq_tx_get_final_left(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return MAX2(seq_tx_get_final_left(seq, 0), seq_tx_get_final_left((Sequence *)seq->tmp, 1) ); + return maxi(seq_tx_get_final_left(seq, 0), seq_tx_get_final_left((Sequence *)seq->tmp, TRUE)); } else { return (seq->start - seq->startstill) + seq->startofs; @@ -3151,7 +3153,7 @@ int seq_tx_get_final_right(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return MIN2(seq_tx_get_final_right(seq, 0), seq_tx_get_final_right((Sequence *)seq->tmp, 1) ); + return mini(seq_tx_get_final_right(seq, 0), seq_tx_get_final_right((Sequence *)seq->tmp, TRUE)); } else { return ((seq->start + seq->len) + seq->endstill) - seq->endofs; diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 9a2b94b2c7e..2b3c314131b 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -648,7 +648,7 @@ static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index // This functions returns the number of branches needed to have the requested number of leafs. static int implicit_needed_branches(int tree_type, int leafs) { - return MAX2(1, (leafs + tree_type - 3) / (tree_type - 1) ); + return maxi(1, (leafs + tree_type - 3) / (tree_type - 1) ); } /* diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index b2d5392c596..97fc431d8fa 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -143,12 +143,20 @@ MINLINE float minf(float a, float b) { return (a < b) ? a : b; } - MINLINE float maxf(float a, float b) { return (a > b) ? a : b; } +MINLINE int mini(int a, int b) +{ + return (a < b) ? a : b; +} +MINLINE int maxi(int a, int b) +{ + return (b < a) ? a : b; +} + MINLINE float signf(float f) { return (f < 0.f) ? -1.f : 1.f; diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 9b05f0fc976..b4b546d9167 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -663,7 +663,7 @@ void BLI_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, bvh->totgrid = totgrid; bvh->gridkey = *key; bvh->grid_hidden = grid_hidden; - bvh->leaf_limit = MAX2(LEAF_LIMIT / ((gridsize - 1) * (gridsize - 1)), 1); + bvh->leaf_limit = maxi(LEAF_LIMIT / ((gridsize - 1) * (gridsize - 1)), 1); BB_reset(&cb); diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index c8052667fa0..f8628be3ff8 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -303,7 +303,7 @@ void ScreenLensDistortionOperation::updateVariables(float distortion, float disp { this->m_kg = maxf(minf(distortion, 1.0f), -0.999f); // smaller dispersion range for somewhat more control - const float d = 0.25f * MAX2(MIN2(dispersion, 1.f), 0.f); + const float d = 0.25f * maxf(minf(dispersion, 1.0f), 0.0f); this->m_kr = maxf(minf((this->m_kg + d), 1.0f), -0.999f); this->m_kb = maxf(minf((this->m_kg - d), 1.0f), -0.999f); this->m_maxk = MAX3(this->m_kr, this->m_kg, this->m_kb); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 83366ec204b..25361bc8de9 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2418,7 +2418,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi * on the first item */ offset[0] = 0; for (bt = block->buttons.first; bt; bt = bt->next) - offset[0] = MIN2(offset[0], -(bt->x1 + 0.8f * (bt->x2 - bt->x1))); + offset[0] = mini(offset[0], -(bt->x1 + 0.8f * (bt->x2 - bt->x1))); offset[1] = 1.5 * UI_UNIT_Y; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 7b139d81a1c..b439271b23d 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -346,7 +346,8 @@ static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, fl const int vnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)) == (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT) || (roundboxalign & (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) == (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) ? 1 : 2; - minsize = MIN2((rect->xmax - rect->xmin) * hnum, (rect->ymax - rect->ymin) * vnum); + minsize = mini((rect->xmax - rect->xmin) * hnum, + (rect->ymax - rect->ymin) * vnum); if (2.0f * rad > minsize) rad = 0.5f * minsize; diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 0f1ffb856e7..5296c8615ab 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -624,8 +624,8 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo * covers the entire screen). */ glGetFloatv(GL_SCISSOR_BOX, scissor); - draw_w = MIN2(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom)); - draw_h = MIN2(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom)); + draw_w = mini(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom)); + draw_h = mini(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom)); if (draw_w > 0 && draw_h > 0) { int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index c546eda1998..820245ed03f 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -852,7 +852,7 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, (int)(rect.xmin + NODE_MARGIN_X), (int)(rect.ymax + (group_header - (2.5f * dpi_fac))), - MIN2((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle()); + mini((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle()); RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr); uiTemplateIDBrowse(layout, (bContext *)C, &ptr, "node_tree", NULL, NULL, NULL); uiBlockLayoutResolve(gnode->block, NULL, NULL); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index f90b2cf4deb..e52c7fff5ca 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1049,7 +1049,7 @@ static void draw_seq_backdrop(View2D *v2d) glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); /* Alternating horizontal stripes */ - i = MAX2(1, ((int)v2d->cur.ymin) - 1); + i = maxi(1, ((int)v2d->cur.ymin) - 1); glBegin(GL_QUADS); while (i < v2d->cur.ymax) { @@ -1068,7 +1068,7 @@ static void draw_seq_backdrop(View2D *v2d) glEnd(); /* Darker lines separating the horizontal bands */ - i = MAX2(1, ((int)v2d->cur.ymin) - 1); + i = maxi(1, ((int)v2d->cur.ymin) - 1); UI_ThemeColor(TH_GRID); glBegin(GL_LINES); diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.c b/source/blender/nodes/composite/nodes/node_composite_defocus.c index 2ae3cd6ba56..d9ee067efe3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_defocus.c +++ b/source/blender/nodes/composite/nodes/node_composite_defocus.c @@ -587,8 +587,8 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, // n-agonal int ov, nv; float mind, maxd, lwt; - ys = MAX2((int)floor(bkh_b[2]*ct_crad + y), 0); - ye = MIN2((int)ceil(bkh_b[3]*ct_crad + y), new->y - 1); + ys = maxi((int)floor(bkh_b[2] * ct_crad + y), 0); + ye = mini((int)ceil(bkh_b[3] * ct_crad + y), new->y - 1); for (sy=ys; sy<=ye; sy++) { float fxs = 1e10f, fxe = -1e10f; float yf = (sy - y)/ct_crad; diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index 9318e1758a6..a0d730c5b8a 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -88,8 +88,8 @@ static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_b RE_RC_COUNT(isec->raycounter->bb.test); - if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; - if (t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; + if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0; if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; RE_RC_COUNT(isec->raycounter->bb.hit); diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index 538c5493282..5ae716ac942 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -649,9 +649,9 @@ static void RE_rayobject_octree_done(RayObject *tree) t02 = oc->max[2] - oc->min[2]; /* this minus 0.1 is old safety... seems to be needed? */ - oc->ocfacx = (oc->ocres - 0.1) / t00; - oc->ocfacy = (oc->ocres - 0.1) / t01; - oc->ocfacz = (oc->ocres - 0.1) / t02; + oc->ocfacx = (oc->ocres - 0.1f) / t00; + oc->ocfacy = (oc->ocres - 0.1f) / t01; + oc->ocfacz = (oc->ocres - 0.1f) / t02; oc->ocsize = sqrt(t00 * t00 + t01 * t01 + t02 * t02); /* global, max size octree */ |