From 02ac4031b95b21e5752d28df6607e7d3a2a9baaf Mon Sep 17 00:00:00 2001 From: Laqrix Date: Mon, 2 Jan 2012 22:06:21 -0500 Subject: [PATCH] fmod -> mod (R6RS handles floating point modulo) --- math.ss | 9 ++------- objects.ss | 2 +- user-shaders.ss | 12 ++++++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/math.ss b/math.ss index f7ead72..0cec1dc 100644 --- a/math.ss +++ b/math.ss @@ -10,11 +10,6 @@ (define (sqr x) (* x x)) -(define (fmod n modulus) - (if (negative? n) - (do ([n n (+ n modulus)]) ((positive? n) n)) - (do ([n n (- n modulus)]) ((negative? n) (+ n modulus))))) - (define (clamp x xmin xmax) (max xmin (min x xmax))) @@ -171,13 +166,13 @@ (- (step edge0 x) (step edge1 x))) (define (pulsetrain edge period x) - (pulse edge period (fmod x period))) + (pulse edge period (mod x period))) (define (smoothpulse e0 e1 e2 e3 x) (- (smoothstep e0 e1 x) (smoothstep e2 e3 x))) (define (smoothpulsetrain e0 e1 e2 e3 period x) - (smoothpulse e0 e1 e2 e3 (fmod x period))) + (smoothpulse e0 e1 e2 e3 (mod x period))) (define (fadeout g g-avg featuresize fwidth) (mix-num g g-avg (smoothstep .2 .6 (/ fwidth featuresize)))) diff --git a/objects.ss b/objects.ss index c569be4..c1d1e3b 100644 --- a/objects.ss +++ b/objects.ss @@ -171,7 +171,7 @@ 0.5)) (define (plane-point->texture object point) - (make-vec (fmod (vec-i point) 1) (fmod (vec-j point) 1) 0)) + (make-vec (mod (vec-i point) 1) (mod (vec-j point) 1) 0)) (define (polyhedron-intersections obj ray) (let ([origin ( origin ray)] diff --git a/user-shaders.ss b/user-shaders.ss index 410fb0c..84c7dcb 100644 --- a/user-shaders.ss +++ b/user-shaders.ss @@ -45,7 +45,7 @@ (let ([pnt (point->surface object intersect-point)] [Nf (faceforward (vec-normalize normal) incoming)]) (let* ([t (vec-j pnt)] - [tmod (fmod (* t frequency) 1)]) + [tmod (mod (* t frequency) 1)]) (color-mul Os (if (< tmod .5) Cs @@ -57,9 +57,9 @@ (define-shader checker ([Kd 1] [Ka .5] [frequency 4] [blackcolor black]) (let ([pnt (point->surface object intersect-point)] [Nf (faceforward (vec-normalize normal) incoming)]) - (let ([xmod (fmod (* (vec-i pnt) frequency) (+ 1 EPSILON))] - [ymod (fmod (* (vec-j pnt) frequency) (+ 1 EPSILON))] - [zmod (fmod (* (vec-k pnt) frequency) (+ 1 EPSILON))]) + (let ([xmod (mod (* (vec-i pnt) frequency) (+ 1 EPSILON))] + [ymod (mod (* (vec-j pnt) frequency) (+ 1 EPSILON))] + [zmod (mod (* (vec-k pnt) frequency) (+ 1 EPSILON))]) (color-mul Os (if (< zmod .5) (if (< xmod .5) @@ -249,8 +249,8 @@ ([Ka 1] [Kd .75] [Ks .4] [roughness .1] [specularcolor white] [density .25] [frequency 20]) (let ([st (point->texture object (point->surface object intersect-point))]) - (if (or (< (fmod (* (vec-i st) frequency) 1) density) - (< (fmod (* (vec-j st) frequency) 1) density)) + (if (or (< (mod (* (vec-i st) frequency) 1) density) + (< (mod (* (vec-j st) frequency) 1) density)) (let ([Nf (faceforward (vec-normalize normal) incoming)] [V (vec-normalize (vec-reverse incoming))]) (values