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-08-20 19:29:02 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-08-20 19:29:02 +0400
commit26f073b327ac31d683e1719ce8371b6e28bf01d6 (patch)
treefecb4fdc3f279436ab3814e60266633ba02de50a /source/blender/blenlib
parent831eaf2d7feb63ee6df55a2b00e1d76f793c0a5c (diff)
macros for rectangle center and size
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_rect.h9
-rw-r--r--source/blender/blenlib/intern/rct.c8
2 files changed, 13 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index d6579afcd0d..43639b141e1 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -75,6 +75,15 @@ void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src);
void print_rctf(const char *str, const struct rctf *rect);
void print_rcti(const char *str, const struct rcti *rect);
+#define BLI_RCT_SIZE_X(rct) ((rct)->xmax - (rct)->xmin)
+#define BLI_RCT_SIZE_Y(rct) ((rct)->ymax - (rct)->ymin)
+
+#define BLI_RCT_CENTER_X(rct) (((rct)->xmin + (rct)->xmax) / 2)
+#define BLI_RCT_CENTER_Y(rct) (((rct)->ymin + (rct)->ymax) / 2)
+
+#define BLI_RCT_CENTER_X_FL(rct) ((float)((rct)->xmin + (rct)->xmax) / 2.0f)
+#define BLI_RCT_CENTER_Y_FL(rct) ((float)((rct)->ymin + (rct)->ymax) / 2.0f)
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 9c65c26c72b..61408610520 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -252,8 +252,8 @@ void BLI_rctf_translate(rctf *rect, float x, float y)
/* change width & height around the central location */
void BLI_rcti_resize(rcti *rect, int x, int y)
{
- rect->xmin = rect->xmax = (rect->xmax + rect->xmin) / 2;
- rect->ymin = rect->ymax = (rect->ymax + rect->ymin) / 2;
+ rect->xmin = rect->xmax = BLI_RCT_CENTER_X(rect);
+ rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect);
rect->xmin -= x / 2;
rect->ymin -= y / 2;
rect->xmax = rect->xmin + x;
@@ -262,8 +262,8 @@ void BLI_rcti_resize(rcti *rect, int x, int y)
void BLI_rctf_resize(rctf *rect, float x, float y)
{
- rect->xmin = rect->xmax = (rect->xmax + rect->xmin) * 0.5f;
- rect->ymin = rect->ymax = (rect->ymax + rect->ymin) * 0.5f;
+ rect->xmin = rect->xmax = BLI_RCT_CENTER_X(rect);
+ rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect);
rect->xmin -= x * 0.5f;
rect->ymin -= y * 0.5f;
rect->xmax = rect->xmin + x;