diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_rect.h | 26 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rct.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_cursor_utf8.c | 2 |
3 files changed, 29 insertions, 15 deletions
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index eb9915d6c9b..e64fb1a72b3 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -75,14 +75,28 @@ 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) +/* hrmf, we need to work out this inline stuff */ +#if defined(_MSC_VER) +# define BLI_INLINE static __forceinline +#elif defined(__GNUC__) +# define BLI_INLINE static inline __attribute((always_inline)) +#else +/* #warning "MSC/GNUC defines not found, inline non-functional" */ +# define BLI_INLINE static +#endif -#define BLI_RCT_CENTER_X(rct) (((rct)->xmin + (rct)->xmax) / 2) -#define BLI_RCT_CENTER_Y(rct) (((rct)->ymin + (rct)->ymax) / 2) +#include "DNA_vec_types.h" +BLI_INLINE float BLI_rcti_cent_x_fl(const struct rcti *rct) { return (float)(rct->xmin + rct->xmax) / 2.0f; } +BLI_INLINE float BLI_rcti_cent_y_fl(const struct rcti *rct) { return (float)(rct->ymin + rct->ymax) / 2.0f; } +BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct) { return (rct->xmin + rct->xmax) / 2; } +BLI_INLINE int BLI_rcti_cent_y(const struct rcti *rct) { return (rct->ymin + rct->ymax) / 2; } +BLI_INLINE int BLI_rctf_cent_x(const struct rctf *rct) { return (rct->xmin + rct->xmax) / 2.0f; } +BLI_INLINE int BLI_rctf_cent_y(const struct rctf *rct) { return (rct->ymin + rct->ymax) / 2.0f; } -#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) +BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct) { return (rct->xmax - rct->xmin); } +BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct) { return (rct->ymax - rct->ymin); } +BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct) { return (rct->xmax - rct->xmin); } +BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct) { return (rct->ymax - rct->ymin); } #ifdef __cplusplus } diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 225ede8a8ef..fd0dac5bc3d 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 = BLI_RCT_CENTER_X(rect); - rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect); + rect->xmin = rect->xmax = BLI_rcti_cent_x(rect); + rect->ymin = rect->ymax = BLI_rcti_cent_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 = BLI_RCT_CENTER_X(rect); - rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect); + rect->xmin = rect->xmax = BLI_rctf_cent_x(rect); + rect->ymin = rect->ymax = BLI_rctf_cent_y(rect); rect->xmin -= x * 0.5f; rect->ymin -= y * 0.5f; rect->xmax = rect->xmin + x; @@ -366,9 +366,9 @@ int BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest) void BLI_rcti_rctf_copy(rcti *dst, const rctf *src) { dst->xmin = floorf(src->xmin + 0.5f); - dst->xmax = dst->xmin + floorf(BLI_RCT_SIZE_X(src) + 0.5f); + dst->xmax = dst->xmin + floorf(BLI_rctf_size_x(src) + 0.5f); dst->ymin = floorf(src->ymin + 0.5f); - dst->ymax = dst->ymin + floorf(BLI_RCT_SIZE_Y(src) + 0.5f); + dst->ymax = dst->ymin + floorf(BLI_rctf_size_y(src) + 0.5f); } void BLI_rctf_rcti_copy(rctf *dst, const rcti *src) @@ -382,11 +382,11 @@ void BLI_rctf_rcti_copy(rctf *dst, const rcti *src) void print_rctf(const char *str, const rctf *rect) { printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str, - rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect)); + rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_rctf_size_x(rect), BLI_rctf_size_y(rect)); } void print_rcti(const char *str, const rcti *rect) { printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str, - rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect)); + rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)); } diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 422a600e51c..bab144266a4 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -147,7 +147,7 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, strCursorJumpDirection direction, strCursorJumpType jump) { - const short pos_prev = *pos; + const int pos_prev = *pos; if (direction == STRCUR_DIR_NEXT) { BLI_str_cursor_step_next_utf8(str, maxlen, pos); |