Remove redundant tests; speeds up contour plots by about 15%

This commit is contained in:
Neil Toronto 2014-04-05 11:12:57 -06:00
parent 1f60dbf57e
commit f00da37186
3 changed files with 10 additions and 12 deletions

View File

@ -149,9 +149,7 @@ above.
(defproc (heights->lines [xa real?] [xb real?] [ya real?] [yb real?] (defproc (heights->lines [xa real?] [xb real?] [ya real?] [yb real?]
[z real?] [z1 real?] [z2 real?] [z3 real?] [z4 real?] [z real?] [z1 real?] [z2 real?] [z3 real?] [z4 real?]
) (listof (list/c (vector/c real? real? real?) (vector/c real? real? real?))) ) (listof (list/c (vector/c real? real? real?) (vector/c real? real? real?)))
(cond [(and (z . < . z1) (z . < . z2) (z . < . z3) (z . < . z4)) empty] (cond [(= z z1 z2 z3 z4) empty]
[(and (z . > . z1) (z . > . z2) (z . > . z3) (z . > . z4)) empty]
[(= z z1 z2 z3 z4) empty]
[else [else
(define lines (do-heights->lines z z1 z2 z3 z4)) (define lines (do-heights->lines z z1 z2 z3 z4))
(for/list ([line (in-list lines)]) (for/list ([line (in-list lines)])
@ -591,8 +589,6 @@ above.
[z1 real?] [z2 real?] [z3 real?] [z4 real?] [z1 real?] [z2 real?] [z3 real?] [z4 real?]
) (listof (listof (vector/c real? real? real?))) ) (listof (listof (vector/c real? real? real?)))
(cond (cond
[(and (zb . < . z1) (zb . < . z2) (zb . < . z3) (zb . < . z4)) empty]
[(and (za . > . z1) (za . > . z2) (za . > . z3) (za . > . z4)) empty]
[(= za zb z1 z2 z3 z4) (list (list (vector xa ya z1) (vector xb ya z2) [(= za zb z1 z2 z3 z4) (list (list (vector xa ya z1) (vector xb ya z2)
(vector xb yb z3) (vector xa yb z4)))] (vector xb yb z3) (vector xa yb z4)))]
[else [else

View File

@ -89,14 +89,15 @@
(if identity-transforms? (if identity-transforms?
(match-lambda (match-lambda
[(vector (? rational? x) (? rational? y)) [(vector (? rational? x) (? rational? y))
(vector (fl (/ (- (inexact->exact x) x-min) x-size)) (vector (fl (/ (- x x-min) x-size))
(fl (/ (- (inexact->exact y) y-min) y-size)))] (fl (/ (- y y-min) y-size)))]
[(vector x y) [(vector x y)
(vector +nan.0 +nan.0)]) (vector +nan.0 +nan.0)])
(match-lambda (match-lambda
[(vector (? rational? x) (? rational? y)) [(vector (? rational? x) (? rational? y))
(vector (fl (/ (- (inexact->exact (fx x)) x-min) x-size)) (let ([x (fx x)] [y (fy y)])
(fl (/ (- (inexact->exact (fy y)) y-min) y-size)))] (vector (if (rational? x) (fl (/ (- (inexact->exact x) x-min) x-size)) +nan.0)
(if (rational? y) (fl (/ (- (inexact->exact y) y-min) y-size)) +nan.0)))]
[(vector x y) [(vector x y)
(vector +nan.0 +nan.0)]))) (vector +nan.0 +nan.0)])))

View File

@ -152,9 +152,10 @@
(flvector +nan.0 +nan.0 +nan.0)]) (flvector +nan.0 +nan.0 +nan.0)])
(match-lambda (match-lambda
[(vector (? rational? x) (? rational? y) (? rational? z)) [(vector (? rational? x) (? rational? y) (? rational? z))
(flvector (fl (/ (- (inexact->exact (fx x)) x-mid) x-size)) (let ([x (fx x)] [y (fy y)] [z (fz z)])
(fl (/ (- (inexact->exact (fy y)) y-mid) y-size)) (flvector (if (rational? x) (fl (/ (- (inexact->exact x) x-mid) x-size)) +nan.0)
(fl (/ (- (inexact->exact (fz z)) z-mid) z-size)))] (if (rational? y) (fl (/ (- (inexact->exact y) y-mid) y-size)) +nan.0)
(if (rational? z) (fl (/ (- (inexact->exact z) z-mid) z-size)) +nan.0)))]
[(vector x y z) [(vector x y z)
(flvector +nan.0 +nan.0 +nan.0)]))) (flvector +nan.0 +nan.0 +nan.0)])))