diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 17:41:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:18:11 +0300 |
commit | d140e70c496122915eb5c05aba83153e2e0d7998 (patch) | |
tree | 1e589247d69da64aa7b0e7802319237ec050b5d6 /source/blender/blenlib/intern/rct.c | |
parent | 147bd16ed1bb3415b30408b0eab110d0854eadd2 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-experimentstemp-ghash-experiments
Note that 'store hash' feature was removed for now - to complex to maintain (conflicts)
and relatively easy to re-add if we ever really want this one day.
Conflicts:
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/hash_mm2a.c
source/blender/bmesh/tools/bmesh_region_match.c
tests/gtests/blenlib/BLI_ghash_performance_test.cc
tests/gtests/blenlib/BLI_ghash_test.cc
tests/gtests/blenlib/CMakeLists.txt
Diffstat (limited to 'source/blender/blenlib/intern/rct.c')
-rw-r--r-- | source/blender/blenlib/intern/rct.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 61e5783cd3e..8de5d2ef172 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -123,6 +123,38 @@ bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) } /** + * \returns shortest distance from \a rect to x/y (0 if inside) +*/ + +int BLI_rcti_length_x(const rcti *rect, const int x) +{ + if (x < rect->xmin) return rect->xmin - x; + if (x > rect->xmax) return x - rect->xmax; + return 0; +} + +int BLI_rcti_length_y(const rcti *rect, const int y) +{ + if (y < rect->ymin) return rect->ymin - y; + if (y > rect->ymax) return y - rect->ymax; + return 0; +} + +float BLI_rctf_length_x(const rctf *rect, const float x) +{ + if (x < rect->xmin) return rect->xmin - x; + if (x > rect->xmax) return x - rect->xmax; + return 0.0f; +} + +float BLI_rctf_length_y(const rctf *rect, const float y) +{ + if (y < rect->ymin) return rect->ymin - y; + if (y > rect->ymax) return y - rect->ymax; + return 0.0f; +} + +/** * is \a rct_b inside \a rct_a */ bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b) @@ -571,3 +603,46 @@ 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_rcti_size_x(rect), BLI_rcti_size_y(rect)); } + + +/* -------------------------------------------------------------------- */ +/* Comprehensive math (float only) */ + +/** \name Rect math functions + * \{ */ + +#define ROTATE_SINCOS(r_vec, mat2, vec) { \ + (r_vec)[0] = (mat2)[1] * (vec)[0] + (+(mat2)[0]) * (vec)[1]; \ + (r_vec)[1] = (mat2)[0] * (vec)[0] + (-(mat2)[1]) * (vec)[1]; \ +} ((void)0) + +/** + * Expand the rectangle to fit a rotated \a src. + */ +void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, const float angle) +{ + const float mat2[2] = {sinf(angle), cosf(angle)}; + const float cent[2] = {BLI_rctf_cent_x(src), BLI_rctf_cent_y(src)}; + float corner[2], corner_rot[2], corder_max[2]; + + /* x is same for both corners */ + corner[0] = src->xmax - cent[0]; + corner[1] = src->ymax - cent[1]; + ROTATE_SINCOS(corner_rot, mat2, corner); + corder_max[0] = fabsf(corner_rot[0]); + corder_max[1] = fabsf(corner_rot[1]); + + corner[1] *= -1; + ROTATE_SINCOS(corner_rot, mat2, corner); + corder_max[0] = MAX2(corder_max[0], fabsf(corner_rot[0])); + corder_max[1] = MAX2(corder_max[1], fabsf(corner_rot[1])); + + dst->xmin = cent[0] - corder_max[0]; + dst->xmax = cent[0] + corder_max[0]; + dst->ymin = cent[1] - corder_max[1]; + dst->ymax = cent[1] + corder_max[1]; +} + +#undef ROTATE_SINCOS + +/** \} */ |