diff --git a/math.scad b/math.scad index 8da658b..28f365a 100644 --- a/math.scad +++ b/math.scad @@ -96,7 +96,7 @@ function constrain(v, minval, maxval) = min(maxval, max(minval, v)); // Arguments: // x = The value to constrain. // m = Modulo value. -function posmod(x,m) = (x % m + m) % m; +function posmod(x,m) = (x%m) + (x<0)? m : 0; // Function: modrange() @@ -119,7 +119,7 @@ function modrange(x, y, m, step=1) = a = posmod(x, m), b = posmod(y, m), c = step>0? (a>b? b+m : b) : (a