diff --git a/collects/plot/common/format.rkt b/collects/plot/common/format.rkt index 8cb4c1b826..a507cb9cf5 100644 --- a/collects/plot/common/format.rkt +++ b/collects/plot/common/format.rkt @@ -83,6 +83,9 @@ (defproc (real->plot-label [x real?] [digits exact-integer?] [scientific? boolean? #t]) any (cond [(zero? x) "0"] + [(eqv? x +nan.0) "+nan.0"] + [(eqv? x +inf.0) "+inf.0"] + [(eqv? x -inf.0) "-inf.0"] [else (define front-sign (if (x . < . 0) "-" "")) (define mid-sign (if (x . < . 0) "-" "+")) @@ -133,6 +136,26 @@ [frac-zero? (format "~a~a" front-sign int-str)] [else (format "~a~a.~a" front-sign int-str frac-str)])]))])) +(define (format-special x) + (case x + [(#f) "#f"] + [(+nan.0) "+nan.0"] + [(+inf.0) "+inf.0"] + [(-inf.0) "-inf.0"] + [else ""])) + +(defproc (ivl->string [i ivl?] [extra-digits exact-integer? 3]) string? + (match-define (ivl a b) i) + (cond [(and (not (regular-real? a)) (not (regular-real? b))) + (format "[~a,~a]" (format-special a) (format-special b))] + [(not (regular-real? a)) (format "[~a,~a]" (format-special a) (real->plot-label b 15))] + [(not (regular-real? b)) (format "[~a,~a]" (real->plot-label a 15) (format-special b))] + [else + (define digits (digits-for-range a b extra-digits)) + (format "[~a,~a]" + (real->plot-label a digits) + (real->plot-label b digits))])) + (defproc (->plot-label [a any/c] [digits exact-integer? 7]) string? (let loop ([a a]) (cond [(string? a) a] diff --git a/collects/plot/contracted/format.rkt b/collects/plot/contracted/format.rkt index d43e5bb206..d637f44b42 100644 --- a/collects/plot/contracted/format.rkt +++ b/collects/plot/contracted/format.rkt @@ -7,5 +7,5 @@ integer->superscript digits-for-range real->decimal-string* real->string/trunc - real->plot-label ->plot-label + real->plot-label ivl->string ->plot-label parse-format-string apply-formatter)) diff --git a/collects/plot/plot2d/plot.rkt b/collects/plot/plot2d/plot.rkt index c7bf219e8b..9e43afda9e 100644 --- a/collects/plot/plot2d/plot.rkt +++ b/collects/plot/plot2d/plot.rkt @@ -14,6 +14,7 @@ "../common/file-type.rkt" "../common/deprecation-warning.rkt" "../common/contract-doc.rkt" + "../common/format.rkt" "plot-area.rkt") ;; Require lazily: without this, Racket complains while generating documentation: @@ -37,9 +38,9 @@ (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) (when (or (not (rect-regular? plot-bounds-rect)) (rect-zero-area? plot-bounds-rect)) - (match-define (vector (ivl x-min x-max) (ivl y-min y-max)) plot-bounds-rect) - (error 'plot "could not determine sensible plot bounds; got x ∈ [~a,~a], y ∈ [~a,~a]" - x-min x-max y-min y-max)) + (match-define (vector x-ivl y-ivl) plot-bounds-rect) + (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a" + (ivl->string x-ivl) (ivl->string y-ivl))) plot-bounds-rect) (define (get-ticks renderer-list bounds-rect) diff --git a/collects/plot/plot3d/plot.rkt b/collects/plot/plot3d/plot.rkt index 3e660596a0..e40b7021a1 100644 --- a/collects/plot/plot3d/plot.rkt +++ b/collects/plot/plot3d/plot.rkt @@ -14,6 +14,7 @@ "../common/file-type.rkt" "../common/deprecation-warning.rkt" "../common/contract-doc.rkt" + "../common/format.rkt" "plot-area.rkt") ;; Require lazily: without this, Racket complains while generating documentation: @@ -38,9 +39,9 @@ (define plot-bounds-rect (bounds-fixpoint renderer-list given-bounds-rect)) (when (or (not (rect-regular? plot-bounds-rect)) (rect-zero-area? plot-bounds-rect)) - (match-define (vector (ivl x-min x-max) (ivl y-min y-max) (ivl z-min z-max)) plot-bounds-rect) - (error 'plot "could not determine sensible plot bounds; got x ∈ [~a,~a], y ∈ [~a,~a], z ∈ [~a,~a]" - x-min x-max y-min y-max z-min z-max)) + (match-define (vector x-ivl y-ivl z-ivl) plot-bounds-rect) + (error 'plot "could not determine sensible plot bounds; got x ∈ ~a, y ∈ ~a, z ∈ ~a" + (ivl->string x-ivl) (ivl->string y-ivl) (ivl->string z-ivl))) plot-bounds-rect) (define (get-ticks renderer-list bounds-rect)