From 38f91db37c4789dfbca03676f2a92a2f85417d72 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Jul 2012 09:24:17 +0000 Subject: add bli rect min/max functions. --- source/blender/blenlib/BLI_rect.h | 3 +++ source/blender/blenlib/intern/rct.c | 16 ++++++++++++++++ source/blender/editors/sculpt_paint/paint_utils.c | 11 +++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index 49d10eb0be6..8a9794b77c9 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -46,6 +46,9 @@ void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax); void BLI_rcti_init_minmax(struct rcti *rect); void BLI_rctf_init_minmax(struct rctf *rect); +void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]); +void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]); + void BLI_translate_rctf(struct rctf *rect, float x, float y); void BLI_translate_rcti(struct rcti *rect, int x, int y); void BLI_resize_rcti(struct rcti *rect, int x, int y); diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 4ac30da2369..c1ef3e27291 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -211,6 +211,22 @@ void BLI_rctf_init_minmax(struct rctf *rect) rect->xmax = rect->ymax = FLT_MIN; } +void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]) +{ + if (xy[0] < rect->xmin) rect->xmin = xy[0]; + if (xy[0] > rect->xmax) rect->xmax = xy[0]; + if (xy[1] < rect->ymin) rect->ymin = xy[1]; + if (xy[1] > rect->ymax) rect->ymax = xy[1]; +} + +void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]) +{ + if (xy[0] < rect->xmin) rect->xmin = xy[0]; + if (xy[0] > rect->xmax) rect->xmax = xy[0]; + if (xy[1] < rect->ymin) rect->ymin = xy[1]; + if (xy[1] > rect->ymax) rect->ymax = xy[1]; +} + void BLI_translate_rcti(rcti *rect, int x, int y) { rect->xmin += x; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 26c51596a5e..3c8f39a44b1 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -93,16 +93,19 @@ int paint_convert_bb_to_rect(rcti *rect, for (j = 0; j < 2; ++j) { for (k = 0; k < 2; ++k) { float vec[3], proj[2]; + int proj_i[2]; vec[0] = i ? bb_min[0] : bb_max[0]; vec[1] = j ? bb_min[1] : bb_max[1]; vec[2] = k ? bb_min[2] : bb_max[2]; /* convert corner to screen space */ ED_view3d_project_float_v2(ar, vec, proj, projection_mat); /* expand 2D rectangle */ - rect->xmin = MIN2(rect->xmin, proj[0]); - rect->xmax = MAX2(rect->xmax, proj[0]); - rect->ymin = MIN2(rect->ymin, proj[1]); - rect->ymax = MAX2(rect->ymax, proj[1]); + + /* we could project directly to int? */ + proj_i[0] = proj[0]; + proj_i[1] = proj[1]; + + BLI_rcti_do_minmax_v(rect, proj_i); } } } -- cgit v1.2.3