forked from bartvdbraak/blender
use min/max inline functions where MIN2/MAX2 were doing type conversion.
This commit is contained in:
parent
ec67334e25
commit
9fc95bd7ee
@ -312,8 +312,8 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM
|
||||
|
||||
/* stay on the safe side and clamp repulse */
|
||||
if ( impulse > ALMOST_ZERO )
|
||||
repulse = MIN2 ( repulse, 5.0*impulse );
|
||||
repulse = MAX2 ( impulse, repulse );
|
||||
repulse = min_ff( repulse, 5.0*impulse );
|
||||
repulse = max_ff(impulse, repulse);
|
||||
|
||||
impulse = repulse / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); /* original 2.0 / 0.25 */
|
||||
VECADDMUL ( i1, collpair->normal, impulse );
|
||||
|
@ -899,7 +899,7 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
|
||||
elem->scalemax = sqrt(elem->scalemax);
|
||||
|
||||
/* clamp scaling */
|
||||
scaleclamp = MIN2(elem->totchild, 10.0f);
|
||||
scaleclamp = (float)min_ii(elem->totchild, 10);
|
||||
elem->scalemin = MIN2(scaleclamp, elem->scalemin);
|
||||
elem->scalemax = MIN2(scaleclamp, elem->scalemax);
|
||||
|
||||
|
@ -1194,7 +1194,7 @@ int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *s
|
||||
int get_render_subsurf_level(RenderData *r, int lvl)
|
||||
{
|
||||
if (r->mode & R_SIMPLIFY)
|
||||
return MIN2(r->simplify_subsurf, lvl);
|
||||
return min_ii(r->simplify_subsurf, lvl);
|
||||
else
|
||||
return lvl;
|
||||
}
|
||||
@ -1210,7 +1210,7 @@ int get_render_child_particle_number(RenderData *r, int num)
|
||||
int get_render_shadow_samples(RenderData *r, int samples)
|
||||
{
|
||||
if ((r->mode & R_SIMPLIFY) && samples > 0)
|
||||
return MIN2(r->simplify_shadowsamples, samples);
|
||||
return min_ii(r->simplify_shadowsamples, samples);
|
||||
else
|
||||
return samples;
|
||||
}
|
||||
|
@ -40,15 +40,22 @@
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
/* useful for finding bad use of min/max */
|
||||
#if 0
|
||||
/* gcc only */
|
||||
# define _TYPECHECK(a, b) ((void)(((typeof(a) *)0) == ((typeof(b) *)0)))
|
||||
#else
|
||||
# define _TYPECHECK(a, b) (void)0
|
||||
#endif
|
||||
|
||||
/* min/max */
|
||||
#define MIN2(x, y) ( (x) < (y) ? (x) : (y) )
|
||||
#define MIN3(x, y, z) MIN2(MIN2((x), (y)), (z) )
|
||||
#define MIN4(x, y, z, a) MIN2(MIN2((x), (y)), MIN2((z), (a)) )
|
||||
#define MIN2(x, y) (_TYPECHECK(x, y), (((x) < (y) ? (x) : (y))))
|
||||
#define MIN3(x, y, z) (MIN2(MIN2((x), (y)), (z)))
|
||||
#define MIN4(x, y, z, a) (MIN2(MIN2((x), (y)), MIN2((z), (a))))
|
||||
|
||||
#define MAX2(x, y) ( (x) > (y) ? (x) : (y) )
|
||||
#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z) )
|
||||
#define MAX4(x, y, z, a) MAX2(MAX2((x), (y)), MAX2((z), (a)) )
|
||||
#define MAX2(x, y) (_TYPECHECK(x, y), (((x) > (y) ? (x) : (y))))
|
||||
#define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z)))
|
||||
#define MAX4(x, y, z, a) (MAX2(MAX2((x), (y)), MAX2((z), (a))))
|
||||
|
||||
#define INIT_MINMAX(min, max) { \
|
||||
(min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
|
||||
@ -109,7 +116,7 @@
|
||||
#define CHECK_TYPE_INLINE(val, type) \
|
||||
((void)(((type *)0) != (val)))
|
||||
|
||||
#define SWAP(type, a, b) { \
|
||||
#define SWAP(type, a, b) { \
|
||||
type sw_ap; \
|
||||
CHECK_TYPE(a, type); \
|
||||
CHECK_TYPE(b, type); \
|
||||
|
@ -490,9 +490,9 @@ static void voronoi_finishEdge(VoronoiProcess *process, VoronoiParabola *parabol
|
||||
}
|
||||
|
||||
if (parabola->edge->direction[0] > 0.0f)
|
||||
mx = MAX2(process->width, parabola->edge->start[0] + 10);
|
||||
mx = max_ff(process->width, parabola->edge->start[0] + 10);
|
||||
else
|
||||
mx = MIN2(0.0, parabola->edge->start[0] - 10);
|
||||
mx = min_ff(0.0f, parabola->edge->start[0] - 10.0f);
|
||||
|
||||
parabola->edge->end[0] = mx;
|
||||
parabola->edge->end[1] = mx * parabola->edge->f + parabola->edge->g;
|
||||
|
@ -440,7 +440,7 @@ static void sk_cancelStroke(SK_Sketch *sketch)
|
||||
|
||||
static float sk_clampPointSize(SK_Point *pt, float size)
|
||||
{
|
||||
return MAX2(size * pt->size, size / 2);
|
||||
return max_ff(size * pt->size, size / 2);
|
||||
}
|
||||
|
||||
static void sk_drawPoint(GLUquadric *quad, SK_Point *pt, float size)
|
||||
|
@ -1697,7 +1697,7 @@ void ui_get_but_string(uiBut *but, char *str, size_t maxlen)
|
||||
}
|
||||
else if (buf && buf != str) {
|
||||
/* string was too long, we have to truncate */
|
||||
memcpy(str, buf, MIN2(maxlen, buf_len + 1));
|
||||
memcpy(str, buf, MIN2(maxlen, (size_t)buf_len + 1));
|
||||
MEM_freeN(buf);
|
||||
}
|
||||
}
|
||||
|
@ -1377,7 +1377,7 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
|
||||
/* turn button into search button */
|
||||
if (searchprop) {
|
||||
but->type = SEARCH_MENU;
|
||||
but->hardmax = MAX2(but->hardmax, 256);
|
||||
but->hardmax = MAX2(but->hardmax, 256.0f);
|
||||
but->rnasearchpoin = *searchptr;
|
||||
but->rnasearchprop = searchprop;
|
||||
but->flag |= UI_ICON_LEFT | UI_TEXT_LEFT;
|
||||
|
@ -671,7 +671,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
|
||||
|
||||
for (a = 0, fontw = 0, fonth = 0; a < data->totline; a++) {
|
||||
w = BLF_width(data->fstyle.uifont_id, data->lines[a]);
|
||||
fontw = MAX2(fontw, w);
|
||||
fontw = max_ff(fontw, (float)w);
|
||||
fonth += (a == 0) ? h : h + TIP_MARGIN_Y;
|
||||
}
|
||||
|
||||
|
@ -2774,8 +2774,8 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
|
||||
block = uiLayoutGetBlock(ui_abs);
|
||||
|
||||
width = BLF_width(style->widget.uifont_id, report->message);
|
||||
width = MIN2(rti->widthfac * width, width);
|
||||
width = MAX2(width, 10);
|
||||
width = min_ii((int)(rti->widthfac * width), width);
|
||||
width = max_ii(width, 10);
|
||||
|
||||
/* make a box around the report to make it stand out */
|
||||
uiBlockBeginAlign(block);
|
||||
|
@ -2407,7 +2407,7 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
|
||||
value = ui_get_but_val(but);
|
||||
|
||||
size = (but->softmax + but->a1 - but->softmin);
|
||||
size = MAX2(size, 2);
|
||||
size = max_ff(size, 2.0f);
|
||||
|
||||
/* position */
|
||||
rect1 = *rect;
|
||||
@ -2445,7 +2445,7 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
|
||||
|
||||
if (rect1.ymax > rect->ymax) {
|
||||
rect1.ymax = rect->ymax;
|
||||
rect1.ymin = MAX2(rect1.ymax - min, rect->ymin);
|
||||
rect1.ymin = max_ii(rect1.ymax - min, rect->ymin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4154,7 +4154,7 @@ int ED_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
|
||||
* isn't one already */
|
||||
if (mmd && !CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) {
|
||||
GridPaintMask *gmask;
|
||||
int level = MAX2(1, mmd->sculptlvl);
|
||||
int level = max_ii(1, mmd->sculptlvl);
|
||||
int gridsize = ccg_gridsize(level);
|
||||
int gridarea = gridsize * gridsize;
|
||||
int i, j;
|
||||
|
@ -254,8 +254,9 @@ static void get_keyframe_extents(bAnimContext *ac, float *min, float *max, const
|
||||
|
||||
/* find gp-frame which is less than or equal to cframe */
|
||||
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
||||
*min = MIN2(*min, gpf->framenum);
|
||||
*max = MAX2(*max, gpf->framenum);
|
||||
const float framenum = (float)gpf->framenum;
|
||||
*min = min_ff(*min, framenum);
|
||||
*max = max_ff(*max, framenum);
|
||||
}
|
||||
}
|
||||
else if (ale->datatype == ALE_MASKLAY) {
|
||||
@ -267,8 +268,9 @@ static void get_keyframe_extents(bAnimContext *ac, float *min, float *max, const
|
||||
masklay_shape;
|
||||
masklay_shape = masklay_shape->next)
|
||||
{
|
||||
*min = MIN2(*min, masklay_shape->frame);
|
||||
*max = MAX2(*max, masklay_shape->frame);
|
||||
const float framenum = (float)masklay_shape->frame;
|
||||
*min = min_ff(*min, framenum);
|
||||
*max = max_ff(*max, framenum);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -284,8 +286,8 @@ static void get_keyframe_extents(bAnimContext *ac, float *min, float *max, const
|
||||
}
|
||||
|
||||
/* try to set cur using these values, if they're more extreme than previously set values */
|
||||
*min = MIN2(*min, tmin);
|
||||
*max = MAX2(*max, tmax);
|
||||
*min = min_ff(*min, tmin);
|
||||
*max = max_ff(*max, tmax);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1018,7 +1018,7 @@ static void track_init_markers(SpaceClip *sc, MovieClip *clip, int *frames_limit
|
||||
if (frames_limit == 0)
|
||||
frames_limit = track->frames_limit;
|
||||
else
|
||||
frames_limit = MIN2(frames_limit, track->frames_limit);
|
||||
frames_limit = min_ii(frames_limit, (int)track->frames_limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *i
|
||||
BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
|
||||
|
||||
if (sima->image && ID_REAL_USERS(sima->image) <= 0)
|
||||
sima->image->id.us = MAX2(sima->image->id.us, 0) + 1;
|
||||
sima->image->id.us = max_ii(sima->image->id.us, 0) + 1;
|
||||
|
||||
if (obedit)
|
||||
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
|
||||
@ -98,7 +98,7 @@ void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
|
||||
|
||||
/* weak, but same as image/space */
|
||||
if (sima->mask_info.mask && ID_REAL_USERS(sima->mask_info.mask) <= 0)
|
||||
sima->mask_info.mask->id.us = MAX2(sima->mask_info.mask->id.us, 0) + 1;
|
||||
sima->mask_info.mask->id.us = max_ii(sima->mask_info.mask->id.us, 0) + 1;
|
||||
|
||||
if (C) {
|
||||
WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
|
||||
|
@ -136,7 +136,7 @@ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, in
|
||||
int a = 0;
|
||||
|
||||
for (sock = node->inputs.first; sock; sock = sock->next) {
|
||||
maxtype = MAX2(sock->type, maxtype);
|
||||
maxtype = max_ii(sock->type, maxtype);
|
||||
}
|
||||
|
||||
/* find sockets of higher 'types' first (i.e. image) */
|
||||
@ -1368,7 +1368,7 @@ static bNodeSocket *socket_best_match(ListBase *sockets)
|
||||
|
||||
/* find type range */
|
||||
for (sock = sockets->first; sock; sock = sock->next)
|
||||
maxtype = MAX2(sock->type, maxtype);
|
||||
maxtype = max_ii(sock->type, maxtype);
|
||||
|
||||
/* try all types, starting from 'highest' (i.e. colors, vectors, values) */
|
||||
for (type = maxtype; type >= 0; --type) {
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_sequence_types.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_ghash.h"
|
||||
@ -1649,7 +1650,7 @@ void draw_outliner(const bContext *C)
|
||||
|
||||
/* get actual width of column 1 */
|
||||
outliner_rna_width(soops, &soops->tree, &sizex_rna, 0);
|
||||
sizex_rna = MAX2(OL_RNA_COLX, sizex_rna + OL_RNA_COL_SPACEX);
|
||||
sizex_rna = max_ii(OL_RNA_COLX, sizex_rna + OL_RNA_COL_SPACEX);
|
||||
|
||||
/* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
|
||||
if (soops->outlinevis == SO_KEYMAP)
|
||||
|
@ -1789,7 +1789,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
|
||||
|
||||
text_font_begin(st);
|
||||
st->cwidth = BLF_fixed_width(mono);
|
||||
st->cwidth = MAX2(st->cwidth, 1);
|
||||
st->cwidth = MAX2(st->cwidth, (char)1);
|
||||
|
||||
/* draw line numbers background */
|
||||
if (st->showlinenrs) {
|
||||
@ -1873,7 +1873,7 @@ void text_update_character_width(SpaceText *st)
|
||||
{
|
||||
text_font_begin(st);
|
||||
st->cwidth = BLF_fixed_width(mono);
|
||||
st->cwidth = MAX2(st->cwidth, 1);
|
||||
st->cwidth = MAX2(st->cwidth, (char)1);
|
||||
text_font_end(st);
|
||||
}
|
||||
|
||||
|
@ -1268,7 +1268,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
|
||||
}
|
||||
}
|
||||
else
|
||||
handled= 0;
|
||||
handled = 0;
|
||||
|
||||
// Per transform event, if present
|
||||
if (t->handleEvent)
|
||||
|
@ -1079,7 +1079,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
|
||||
ret = -1;
|
||||
}
|
||||
else {
|
||||
BLI_strncpy(mstring->s, tmp_val, MIN2(PyBytes_Size(py_value), sizeof(mstring->s)));
|
||||
BLI_strncpy(mstring->s, tmp_val, min_ii(PyBytes_Size(py_value), sizeof(mstring->s)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
|
||||
return -1;
|
||||
|
||||
/* for 'translation' size will always be '3' even on 4x4 vec */
|
||||
num_row = MIN2(self->num_row, ((VectorObject *)bmo)->size);
|
||||
num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size);
|
||||
|
||||
for (row = 0; row < num_row; row++) {
|
||||
bmo->data[row] = MATRIX_ITEM(self, row, col);
|
||||
@ -203,7 +203,7 @@ static int mathutils_matrix_col_set(BaseMathObject *bmo, int col)
|
||||
return -1;
|
||||
|
||||
/* for 'translation' size will always be '3' even on 4x4 vec */
|
||||
num_row = MIN2(self->num_row, ((VectorObject *)bmo)->size);
|
||||
num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size);
|
||||
|
||||
for (row = 0; row < num_row; row++) {
|
||||
MATRIX_ITEM(self, row, col) = bmo->data[row];
|
||||
|
@ -295,11 +295,11 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl)
|
||||
}
|
||||
else {
|
||||
|
||||
minx= MAX2(minx, testrect.xmin);
|
||||
maxx= MIN2(maxx, testrect.xmax);
|
||||
minx = max_ii(minx, testrect.xmin);
|
||||
maxx = min_ii(maxx, testrect.xmax);
|
||||
|
||||
miny= MAX2(har->miny, testrect.ymin);
|
||||
maxy= MIN2(har->maxy, testrect.ymax);
|
||||
miny = max_ii(har->miny, testrect.ymin);
|
||||
maxy = min_ii(har->maxy, testrect.ymax);
|
||||
|
||||
for (y=miny; y<maxy; y++) {
|
||||
int rectofs= (y-disprect.ymin)*pa->rectx + (minx - disprect.xmin);
|
||||
|
@ -856,10 +856,10 @@ void threaded_makeshadowbufs(Render *re)
|
||||
if (lar->shb)
|
||||
totthread++;
|
||||
|
||||
totthread= MIN2(totthread, re->r.threads);
|
||||
totthread = min_ii(totthread, re->r.threads);
|
||||
}
|
||||
else
|
||||
totthread= 1; /* preview render */
|
||||
totthread = 1; /* preview render */
|
||||
|
||||
if (totthread <= 1) {
|
||||
for (lar=re->lampren.first; lar; lar= lar->next) {
|
||||
|
Loading…
Reference in New Issue
Block a user