From 2657d8f96be996cf2888ac7d9071af7cc7c95df1 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Mon, 17 Dec 2012 16:58:43 -0700 Subject: [PATCH] Plots whose functions raise errors now have an empty spot instead of failing --- collects/plot/common/sample.rkt | 9 ++++++--- collects/plot/tests/plot2d-tests.rkt | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/collects/plot/common/sample.rkt b/collects/plot/common/sample.rkt index e788db0620..d6d406cf2e 100644 --- a/collects/plot/common/sample.rkt +++ b/collects/plot/common/sample.rkt @@ -134,7 +134,8 @@ (defproc (make-function->sampler [transform-thnk (-> axis-transform/c)] ) (-> (real? . -> . real?) ivl? sampler/c) - (λ (f inner-ivl) + (λ (g inner-ivl) + (define f (λ (x) (with-handlers ([exn:fail? (λ (_) +nan.0)]) (g x)))) (define memo (make-hash)) (λ (outer-ivl num) (define tx (transform-thnk)) @@ -155,7 +156,8 @@ ) (-> (real? real? . -> . real?) (vector/c ivl? ivl?) 2d-sampler/c) - (λ (f inner-rect) + (λ (g inner-rect) + (define f (λ (x y) (with-handlers ([exn:fail? (λ (_) +nan.0)]) (g x y)))) (define memo (make-hash)) (λ (outer-rect nums) (define tx (transform-x-thnk)) @@ -186,7 +188,8 @@ ) (-> (real? real? real? . -> . real?) (vector/c ivl? ivl? ivl?) 3d-sampler/c) - (λ (f inner-rect) + (λ (g inner-rect) + (define f (λ (x y z) (with-handlers ([exn:fail? (λ (_) +nan.0)]) (g x y z)))) (define memo (make-hash)) (λ (outer-rect nums) (define tx (transform-x-thnk)) diff --git a/collects/plot/tests/plot2d-tests.rkt b/collects/plot/tests/plot2d-tests.rkt index b80544aada..e81ac52fe6 100644 --- a/collects/plot/tests/plot2d-tests.rkt +++ b/collects/plot/tests/plot2d-tests.rkt @@ -4,6 +4,8 @@ ;(plot-new-window? #t) +(plot (function / -249 250)) + (time (define xs (build-list 10000 (λ _ (random)))) (plot (density xs 1/2)))