diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-06 00:54:32 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-06 00:54:32 +0400 |
commit | 3b72f1824cf06216c70101ee0d29004cc6dc632d (patch) | |
tree | 56981fdefd7a0de0d37e4feab3acaea7c1b744ef /source/blender/blenlib | |
parent | f6b37f34ec2593b12b67046cf032acc202e2fa54 (diff) |
rename positive_mod to mod_i, make it work with nagative numbers (matching pythons modulo), and use in a few more places.
allow mesh-checker-deselect to have a negative offset.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 86aabf76350..1cb28d25b6c 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -222,7 +222,7 @@ MINLINE int power_of_2_max_i(int n); MINLINE int power_of_2_min_i(int n); MINLINE int divide_round_i(int a, int b); -MINLINE int positive_mod(int i, int n); +MINLINE int mod_i(int i, int n); MINLINE float shell_angle_to_dist(const float angle); diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index f68970b832d..e6509db1c5e 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -153,9 +153,12 @@ MINLINE int divide_round_i(int a, int b) return (2 * a + b) / (2 * b); } -MINLINE int positive_mod(int i, int n) +/** + * modulo that handles negative numbers, works the same as Python's. + */ +MINLINE int mod_i(int i, int n) { - return ((i = i % n) < 0) ? i + n : i; + return (i % n + n) % n; } MINLINE unsigned int highest_order_bit_i(unsigned int n) |