diff --git a/collects/plot/plot2d/bounds.rkt b/collects/plot/plot2d/bounds.rkt index 554d436920..5d440f3603 100644 --- a/collects/plot/plot2d/bounds.rkt +++ b/collects/plot/plot2d/bounds.rkt @@ -17,9 +17,9 @@ ;; Attempts to comptute a fixpoint of, roughly, the bounds functions for the given renderers. ;; More precisely, starting with the given plot bounds, it attempts to compute a fixpoint of ;; apply-bounds*, overridden at every iteration by the plot bounds (if given). -;; Because a fixpoint doesn't always exist, or only exists in the limit, it stops after max-iters. +;; Because a fixpoint doesn't always exist, or may only exist in the limit, it stops after max-iters. (define (renderer2d-bounds-fixpoint renderers plot-x-min plot-x-max plot-y-min plot-y-max - [max-iters 4]) + [max-iters 2]) (let/ec break ;; Shortcut eval: if the plot bounds are all specified, the code below just returns them (when (and plot-x-min plot-x-max plot-y-min plot-y-max) @@ -61,18 +61,14 @@ (cond [(and x-min x-max) (match-define (list xs ys) (f x-min x-max samples)) (define rys (filter regular? ys)) (cond [(empty? rys) (values x-min x-max y-min y-max)] - [else (values x-min x-max - (if y-min y-min (apply min* rys)) - (if y-max y-max (apply max* rys)))])] + [else (values x-min x-max (apply min* rys) (apply max* rys))])] [else (values x-min x-max y-min y-max)])) (define ((inverse-bounds-fun f samples) x-min x-max y-min y-max) (cond [(and y-min y-max) (match-define (list ys xs) (f y-min y-max samples)) (define rxs (filter regular? xs)) (cond [(empty? rxs) (values x-min x-max y-min y-max)] - [else (values (if x-min x-min (apply min* rxs)) - (if x-max x-max (apply max* rxs)) - y-min y-max)])] + [else (values (apply min* rxs) (apply max* rxs) y-min y-max)])] [else (values x-min x-max y-min y-max)])) (define ((function-interval-bounds-fun f1 f2 samples) x-min x-max y-min y-max) @@ -81,9 +77,7 @@ (match-define (list x2s y2s) (f2 x-min x-max samples)) (define rys (filter regular? (append y1s y2s))) (cond [(empty? rys) (values x-min x-max y-min y-max)] - [else (values x-min x-max - (if y-min y-min (apply min* rys)) - (if y-max y-max (apply max* rys)))])] + [else (values x-min x-max (apply min* rys) (apply max* rys))])] [else (values x-min x-max y-min y-max)])) (define ((inverse-interval-bounds-fun f1 f2 samples) x-min x-max y-min y-max) @@ -92,7 +86,5 @@ (match-define (list y2s x2s) (f2 y-min y-max samples)) (define rxs (filter regular? (append x1s x2s))) (cond [(empty? rxs) (values x-min x-max y-min y-max)] - [else (values (if x-min x-min (apply min* rxs)) - (if x-max x-max (apply max* rxs)) - y-min y-max)])] + [else (values (apply min* rxs) (apply max* rxs) y-min y-max)])] [else (values x-min x-max y-min y-max)])) diff --git a/collects/plot/plot3d/bounds.rkt b/collects/plot/plot3d/bounds.rkt index 09a04b00f0..ed66b7b0af 100644 --- a/collects/plot/plot3d/bounds.rkt +++ b/collects/plot/plot3d/bounds.rkt @@ -15,9 +15,9 @@ ;; Attempts to comptute a fixpoint of, roughly, the bounds functions for the given renderers. ;; More precisely, starting with the given plot bounds, it attempts to compute a fixpoint of ;; apply-bounds*, overridden at every iteration by the plot bounds (if given). -;; Because a fixpoint doesn't always exist, or only exists in the limit, it stops after max-iters. +;; Because a fixpoint doesn't always exist, or may only exist in the limit, it stops after max-iters. (define (renderer3d-bounds-fixpoint renderers plot-x-min plot-x-max plot-y-min plot-y-max - plot-z-min plot-z-max [max-iters 4]) + plot-z-min plot-z-max [max-iters 2]) (let/ec break ;; Shortcut eval: if the plot bounds are all specified, the code below just returns them (when (and plot-x-min plot-x-max plot-y-min plot-y-max plot-z-min plot-z-max) @@ -65,7 +65,5 @@ (match-define (list xs ys zss) (f x-min x-max samples y-min y-max samples)) (define zs (filter regular? (2d-sample->list zss))) (cond [(empty? zs) (values x-min x-max y-min y-max z-min z-max)] - [else (values x-min x-max y-min y-max - (if z-min z-min (apply min* zs)) - (if z-max z-max (apply max* zs)))])] + [else (values x-min x-max y-min y-max (apply min* zs) (apply max* zs))])] [else (values x-min x-max y-min y-max z-min z-max)])) diff --git a/collects/plot/tests/plot2d-tests.rkt b/collects/plot/tests/plot2d-tests.rkt index 9db7b8634a..c7165bd497 100644 --- a/collects/plot/tests/plot2d-tests.rkt +++ b/collects/plot/tests/plot2d-tests.rkt @@ -1,7 +1,6 @@ #lang racket -(require "../main.rkt" - "../utils.rkt") +(require rackunit plot plot/utils) ;(plot-new-window? #t) @@ -137,9 +136,10 @@ #:color "blue") (axes 1 0 #:y-ticks? #f))) -#;; error: could not determine x bounds -(plot (list (function sqr #f -1) - (function sqr 1 #f))) +;; error: could not determine x bounds +(check-exn exn:fail? + (λ () (plot (list (function sqr #f -1) + (function sqr 1 #f))))) ; draws first function with x in [-2,-1] (plot (list (function sqr #f -1) @@ -156,6 +156,10 @@ (function sqr 1 #f)) #:x-min -2 #:x-max 2) +; draws both in full (particularly, without chopping off the top of the parabola), in [-2,2] +(plot (list (function sqr) + (function sin -2 2))) + (time (plot (list (discrete-histogram (build-list 10 (λ (n) (vector (string-ref "abcdefghij" n)