From 8aa623c2e80c87a1338a700ddf358cae89d5d432 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Sun, 25 Nov 2012 23:28:54 -0700 Subject: [PATCH] Made plots in `plot' and `math' render nicely in PDFs (plots in docs are picts now) Fixed errors in `linear-seq' when end <= start --- collects/math/scribblings/utils.rkt | 4 ++-- collects/plot/common/sample.rkt | 2 ++ collects/plot/scribblings/common.rkt | 4 ++-- collects/plot/scribblings/intro.scrbl | 18 +++++++++++++----- collects/plot/scribblings/porting.scrbl | 5 ++++- collects/plot/scribblings/ticks.scrbl | 6 ++++-- collects/plot/tests/low-level-tests.rkt | 5 +++++ 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/collects/math/scribblings/utils.rkt b/collects/math/scribblings/utils.rkt index a4f7f77c17..0eeb797760 100644 --- a/collects/math/scribblings/utils.rkt +++ b/collects/math/scribblings/utils.rkt @@ -33,6 +33,6 @@ (define eval (make-base-eval)) (eval '(require math)) (eval '(require (rename-in (except-in plot plot plot3d) - [plot-bitmap plot] - [plot3d-bitmap plot3d]))) + [plot-pict plot] + [plot3d-pict plot3d]))) eval) diff --git a/collects/plot/common/sample.rkt b/collects/plot/common/sample.rkt index 9f311bd37e..e788db0620 100644 --- a/collects/plot/common/sample.rkt +++ b/collects/plot/common/sample.rkt @@ -28,6 +28,8 @@ [(zero? num) empty] ; ambiguous request: arbitrarily return start [(and start? end? (= 1 num)) (list start)] + [(end . < . start) (reverse (linear-seq end start num #:start? end? #:end? start?))] + [(end . = . start) (build-list num (λ _ start))] [else (define size (- end start)) (define step (/ size (cond [(and start? end?) (- num 1)] diff --git a/collects/plot/scribblings/common.rkt b/collects/plot/scribblings/common.rkt index dcfce8bd94..18878af32c 100644 --- a/collects/plot/scribblings/common.rkt +++ b/collects/plot/scribblings/common.rkt @@ -34,8 +34,8 @@ (eval '(begin (require racket/math racket/match racket/list racket/draw racket/class (rename-in (except-in plot plot plot3d) - [plot-bitmap plot] - [plot3d-bitmap plot3d]) + [plot-pict plot] + [plot3d-pict plot3d]) plot/utils))) eval)) diff --git a/collects/plot/scribblings/intro.scrbl b/collects/plot/scribblings/intro.scrbl index 746f8074ff..eec524cb97 100644 --- a/collects/plot/scribblings/intro.scrbl +++ b/collects/plot/scribblings/intro.scrbl @@ -108,11 +108,19 @@ In both cases, @(racket plot) and @(racket function-interval) work together to d It is not always possible for renderers and @(racket plot) or @(racket plot3d) to determine the bounds: @interaction[#:eval plot-eval - (plot (function sqr)) - (plot (function sqr #f #f)) - (plot (function sqr (- pi))) - (plot (list (function sqr #f 0) - (function sqr 0 #f)))] + (eval:alts + (plot (function sqr)) + (eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]")) + (eval:alts + (plot (function sqr #f #f)) + (eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]")) + (eval:alts + (plot (function sqr (- pi))) + (eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [-3.141592653589793,#f], y ∈ [#f,#f]")) + (eval:alts + (plot (list (function sqr #f 0) + (function sqr 0 #f))) + (eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [0,0], y ∈ [0,0]"))] There is a difference between passing bounds to renderers and passing bounds to @(racket plot) or @(racket plot3d): bounds passed to @(racket plot) or @(racket plot3d) cannot be changed by a renderer that requests different bounds. We might say that bounds passed to renderers are @italic{suggestions}, and bounds passed to @(racket plot) and @(racket plot3d) are @italic{commandments}. diff --git a/collects/plot/scribblings/porting.scrbl b/collects/plot/scribblings/porting.scrbl index 914139da23..8457dcff0b 100644 --- a/collects/plot/scribblings/porting.scrbl +++ b/collects/plot/scribblings/porting.scrbl @@ -52,7 +52,10 @@ The safest way to ensure that @(racket plot) can determine bounds for the plot a Because PLoT is now smarter about choosing bounds, there are better ways. For example, suppose you have -@interaction[#:eval plot-eval (plot (line sin))] +@interaction[#:eval plot-eval + (eval:alts + (plot (line sin)) + (eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]"))] You could either change it to diff --git a/collects/plot/scribblings/ticks.scrbl b/collects/plot/scribblings/ticks.scrbl index e1d9bfa565..0f10faf661 100644 --- a/collects/plot/scribblings/ticks.scrbl +++ b/collects/plot/scribblings/ticks.scrbl @@ -50,8 +50,10 @@ A log transform. Use this to generate plots with log-scale axes. Any such axis m The beginning of the @secref["ticks and transforms"] section has a working example. An example of exceeding the bounds is @interaction[#:eval plot-eval - (parameterize ([plot-x-transform log-transform]) - (plot (function (λ (x) x) -1 1)))] + (eval:alts + (parameterize ([plot-x-transform log-transform]) + (plot (function (λ (x) x) -1 1))) + (eval:result "" "" "log-transform: expects type as 1st argument, given: -1; other arguments were: 1"))] See @racket[axis-transform-bound] and @racket[axis-transform-append] for ways to get around an axis transform's bounds limitations. } diff --git a/collects/plot/tests/low-level-tests.rkt b/collects/plot/tests/low-level-tests.rkt index 5924de1346..2e19a05b6a 100644 --- a/collects/plot/tests/low-level-tests.rkt +++ b/collects/plot/tests/low-level-tests.rkt @@ -17,10 +17,15 @@ int-str->e-str frac-str->e-str) plot/common/worker-thread) +(check-equal? (linear-seq 1 1 2) '(1 1)) (check-equal? (linear-seq 0 1 2 #:start? #t #:end? #t) '(0 1)) (check-equal? (linear-seq 0 1 2 #:start? #t #:end? #f) '(0 2/3)) (check-equal? (linear-seq 0 1 2 #:start? #f #:end? #t) '(1/3 1)) (check-equal? (linear-seq 0 1 2 #:start? #f #:end? #f) '(1/4 3/4)) +(check-equal? (linear-seq 1 0 2 #:start? #t #:end? #t) '(1 0)) +(check-equal? (linear-seq 1 0 2 #:start? #t #:end? #f) '(1 1/3)) +(check-equal? (linear-seq 1 0 2 #:start? #f #:end? #t) '(2/3 0)) +(check-equal? (linear-seq 1 0 2 #:start? #f #:end? #f) '(3/4 1/4)) (check-exn exn:fail:contract? (λ () (vector-field (λ (v [z 0]) v) -4 4 -4 4))