Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-26 02:47:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-26 02:47:54 +0400
commitb32bf2c462970912c2e8013fcf6f0ee5e3eaadd5 (patch)
tree1f676fef36a65b7f9f55ffbf63bf3f68e4a727e0 /source/blender
parent2223ca1c20cf480ca77365ff3593066c655de9fa (diff)
code cleanup: use min_/max_ math functions, add minmax_v2_v2v2.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_math_vector.h1
-rw-r--r--source/blender/blenlib/intern/math_vector.c9
-rw-r--r--source/blender/editors/screen/area.c16
-rw-r--r--source/blender/editors/screen/glutil.c4
-rw-r--r--source/blender/editors/screen/screen_edit.c7
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c2
-rw-r--r--source/blender/editors/space_view3d/drawobject.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c8
8 files changed, 29 insertions, 20 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 83b07bae53f..77c0ec0a88f 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -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);
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 4196bab0474..7c9c5f60126 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -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)
{
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 586f734129f..fa0ce8c4d07 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -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;
}
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index c1811adf2d8..ce2d045dc80 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -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).
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index ff53a6b9e92..60aad14efcf 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -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 */
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index c506abd9bd3..cb5556396dd 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -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];
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index c82d65b1d87..1e52df8ba53 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -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);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 639ab24d862..0cb4fc0ef7f 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -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;
}
}