code cleanup: use min_/max_ math functions, add minmax_v2_v2v2.
This commit is contained in:
@@ -226,6 +226,7 @@ MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
|
||||
MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);
|
||||
|
||||
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]);
|
||||
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2]);
|
||||
|
||||
void dist_ensure_v3_v3fl(float v1[3], const float v2[3], const float dist);
|
||||
void dist_ensure_v2_v2fl(float v1[2], const float v2[2], const float dist);
|
||||
|
||||
@@ -451,6 +451,15 @@ void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
|
||||
if (max[2] < vec[2]) max[2] = vec[2];
|
||||
}
|
||||
|
||||
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
|
||||
{
|
||||
if (min[0] > vec[0]) min[0] = vec[0];
|
||||
if (min[1] > vec[1]) min[1] = vec[1];
|
||||
|
||||
if (max[0] < vec[0]) max[0] = vec[0];
|
||||
if (max[1] < vec[1]) max[1] = vec[1];
|
||||
}
|
||||
|
||||
/** ensure \a v1 is \a dist from \a v2 */
|
||||
void dist_ensure_v3_v3fl(float v1[3], const float v2[3], const float dist)
|
||||
{
|
||||
|
||||
@@ -465,11 +465,11 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
|
||||
if (ar->drawrct.xmin == ar->drawrct.xmax)
|
||||
ar->drawrct = winrct;
|
||||
else {
|
||||
/* extra clip for safety */
|
||||
ar->drawrct.xmin = MAX2(winrct.xmin, ar->drawrct.xmin);
|
||||
ar->drawrct.ymin = MAX2(winrct.ymin, ar->drawrct.ymin);
|
||||
ar->drawrct.xmax = MIN2(winrct.xmax, ar->drawrct.xmax);
|
||||
ar->drawrct.ymax = MIN2(winrct.ymax, ar->drawrct.ymax);
|
||||
/* extra clip for safety (intersect the rects, could use API func) */
|
||||
ar->drawrct.xmin = max_ii(winrct.xmin, ar->drawrct.xmin);
|
||||
ar->drawrct.ymin = max_ii(winrct.ymin, ar->drawrct.ymin);
|
||||
ar->drawrct.xmax = min_ii(winrct.xmax, ar->drawrct.xmax);
|
||||
ar->drawrct.ymax = min_ii(winrct.ymax, ar->drawrct.ymax);
|
||||
}
|
||||
|
||||
/* note; this sets state, so we can use wmOrtho and friends */
|
||||
@@ -1664,8 +1664,8 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
|
||||
v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
|
||||
|
||||
/* ensure tot is set correctly, to keep views on bottons, with sliders */
|
||||
y = MAX2(-y, -v2d->cur.ymin);
|
||||
|
||||
y = min_ii(y, v2d->cur.ymin);
|
||||
y = -y;
|
||||
}
|
||||
else {
|
||||
/* for now, allow scrolling in both directions (since layouts are optimized for vertical,
|
||||
@@ -1679,7 +1679,7 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
|
||||
|
||||
/* don't jump back when panels close or hide */
|
||||
if (!newcontext)
|
||||
x = MAX2(x, v2d->cur.xmax);
|
||||
x = max_ii(x, v2d->cur.xmax);
|
||||
y = -y;
|
||||
}
|
||||
|
||||
|
||||
@@ -600,8 +600,8 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
|
||||
/* The maximum pixel amounts the image can be cropped
|
||||
* at the lower left without exceeding the origin.
|
||||
*/
|
||||
int off_x = floor(MAX2(ix, 0));
|
||||
int off_y = floor(MAX2(iy, 0));
|
||||
int off_x = floor(max_ff(ix, 0.0f));
|
||||
int off_y = floor(max_ff(iy, 0.0f));
|
||||
|
||||
/* The zoomed space coordinate of the raster position
|
||||
* (starting at the lower left most unclipped pixel).
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
@@ -631,10 +632,8 @@ static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
|
||||
max[0] = max[1] = 0.0f;
|
||||
|
||||
for (sv = sc->vertbase.first; sv; sv = sv->next) {
|
||||
min[0] = MIN2(min[0], sv->vec.x);
|
||||
min[1] = MIN2(min[1], sv->vec.y);
|
||||
max[0] = MAX2(max[0], sv->vec.x);
|
||||
max[1] = MAX2(max[1], sv->vec.y);
|
||||
const float fv[2] = {(float)sv->vec.x, (float)sv->vec.y};
|
||||
minmax_v2v2_v2(min, max, fv);
|
||||
}
|
||||
|
||||
/* always make 0.0 left under */
|
||||
|
||||
@@ -703,7 +703,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
|
||||
|
||||
/* COLOR */
|
||||
if (mloopcol) {
|
||||
unsigned int totloop_clamp = MIN2(4, mp->totloop);
|
||||
unsigned int totloop_clamp = min_ii(4, mp->totloop);
|
||||
unsigned int j;
|
||||
lcol = &mloopcol[mp->loopstart];
|
||||
|
||||
|
||||
@@ -578,7 +578,7 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char
|
||||
glTranslatef(0.0f, 0.0f, 0.0f);
|
||||
|
||||
/* Calculate Image scale */
|
||||
scale = (ob->empty_drawsize / (float)MAX2(ima_x * sca_x, ima_y * sca_y));
|
||||
scale = (ob->empty_drawsize / max_ff((float)ima_x * sca_x, (float)ima_y * sca_y));
|
||||
|
||||
/* Set the object scale */
|
||||
glScalef(scale * sca_x, scale * sca_y, 1.0f);
|
||||
|
||||
@@ -2474,7 +2474,7 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
|
||||
/* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
|
||||
* because of float point precision problems at large values [#23908] */
|
||||
float v1[3], v2[3];
|
||||
float len1, len2;
|
||||
float len_px, len_sc;
|
||||
|
||||
v1[0] = rv3d->persmat[0][0];
|
||||
v1[1] = rv3d->persmat[1][0];
|
||||
@@ -2484,10 +2484,10 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
|
||||
v2[1] = rv3d->persmat[1][1];
|
||||
v2[2] = rv3d->persmat[2][1];
|
||||
|
||||
len1 = 1.0f / len_v3(v1);
|
||||
len2 = 1.0f / len_v3(v2);
|
||||
len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
|
||||
len_sc = (float)MAX2(ar->winx, ar->winy);
|
||||
|
||||
rv3d->pixsize = (2.0f * MAX2(len1, len2)) / (float)MAX2(ar->winx, ar->winy);
|
||||
rv3d->pixsize = len_px / len_sc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user