[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59821] trunk/blender/source/blender: add positive_mod() utility function.

Campbell Barton ideasman42 at gmail.com
Thu Sep 5 23:00:47 CEST 2013


Hi Shinsuke,

Renamed positive_mod() -> mod_i() and it now works with negative
numbers (like Pythons modulo which is `correct` from math POV).

On Thu, Sep 5, 2013 at 11:32 PM, IRIE Shinsuke <irieshinsuke at yahoo.co.jp> wrote:
> Hi Campbell,
>
> Did you assume the 2nd argument in positive_mod() is a positive number?
> This function returns a strange value if the devisor is negative.
>
> Anyway, I think the function name "positive_mod" is inappropriate,
> because the mathematically proper modulo operation always yields a
> positive number if the deviser is a positive number.  The binary %
> operator in C language is not an actual modulo operator.
>
> IRIE Shinsuke
>
> 13/09/05, Campbell Barton wrote:
>> Revision: 59821
>>            http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59821
>> Author:   campbellbarton
>> Date:     2013-09-05 10:12:00 +0000 (Thu, 05 Sep 2013)
>> Log Message:
>> -----------
>> add positive_mod() utility function.
>>
>> Modified Paths:
>> --------------
>>      trunk/blender/source/blender/blenlib/BLI_math_base.h
>>      trunk/blender/source/blender/blenlib/intern/math_base_inline.c
>>      trunk/blender/source/blender/bmesh/operators/bmo_bridge.c
>>
>> Modified: trunk/blender/source/blender/blenlib/BLI_math_base.h
>> ===================================================================
>> --- trunk/blender/source/blender/blenlib/BLI_math_base.h      2013-09-05 09:39:38 UTC (rev 59820)
>> +++ trunk/blender/source/blender/blenlib/BLI_math_base.h      2013-09-05 10:12:00 UTC (rev 59821)
>> @@ -222,6 +222,7 @@
>>   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 float shell_angle_to_dist(const float angle);
>>
>>
>> Modified: trunk/blender/source/blender/blenlib/intern/math_base_inline.c
>> ===================================================================
>> --- trunk/blender/source/blender/blenlib/intern/math_base_inline.c    2013-09-05 09:39:38 UTC (rev 59820)
>> +++ trunk/blender/source/blender/blenlib/intern/math_base_inline.c    2013-09-05 10:12:00 UTC (rev 59821)
>> @@ -153,6 +153,11 @@
>>       return (2 * a + b) / (2 * b);
>>   }
>>
>> +MINLINE int positive_mod(int i, int n)
>> +{
>> +     return ((i = i % n) < 0) ? i + n : i;
>> +}
>> +
>>   MINLINE unsigned int highest_order_bit_i(unsigned int n)
>>   {
>>       n |= (n >>  1);
>>
>> Modified: trunk/blender/source/blender/bmesh/operators/bmo_bridge.c
>> ===================================================================
>> --- trunk/blender/source/blender/bmesh/operators/bmo_bridge.c 2013-09-05 09:39:38 UTC (rev 59820)
>> +++ trunk/blender/source/blender/bmesh/operators/bmo_bridge.c 2013-09-05 10:12:00 UTC (rev 59821)
>> @@ -273,8 +273,7 @@
>>               if (twist_offset != 0) {
>>                       const int len_b = BM_edgeloop_length_get(el_store_b);
>>                       ListBase *lb_b = BM_edgeloop_verts_get(el_store_b);
>> -                     const int offset = twist_offset % len_b;
>> -                     LinkData *el_b = BLI_rfindlink(lb_b, (offset < 0) ? (offset + len_b) : offset);
>> +                     LinkData *el_b = BLI_rfindlink(lb_b, positive_mod(twist_offset, len_b));
>>                       BLI_rotatelist(lb_b, el_b);
>>               }
>>       }
>>
>> _______________________________________________
>> Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers



-- 
- Campbell


More information about the Bf-committers mailing list