diff --git a/plot-lib/plot/private/common/draw.rkt b/plot-lib/plot/private/common/draw.rkt index 024216a0..bfc7f83c 100644 --- a/plot-lib/plot/private/common/draw.rkt +++ b/plot-lib/plot/private/common/draw.rkt @@ -242,6 +242,10 @@ (define (margin-fixpoint x-min x-max y-min y-max init-left init-right init-top init-bottom get-vs) + (define x- (+ x-min init-left)) + (define x+ (- x-max init-right 1)) + (define y- (+ y-min init-top)) + (define y+ (- y-max init-bottom 1)) (let/ec return : (Values Real Real Real Real) (for/fold ([left : Real init-left] [right : Real init-right] @@ -250,15 +254,15 @@ ([i (in-range 3)]) (match-define (list (vector #{xs : (Listof Real)} #{ys : (Listof Real)}) ...) (get-vs left right top bottom)) - (define param-x-min (apply min x-min xs)) - (define param-x-max (apply max (sub1 x-max) xs)) - (define param-y-min (apply min y-min ys)) - (define param-y-max (apply max (sub1 y-max) ys)) + (define param-x-min (apply min x- xs)) + (define param-x-max (apply max x+ xs)) + (define param-y-min (apply min y- ys)) + (define param-y-max (apply max y+ ys)) - (define new-left (round (+ left (- x-min param-x-min)))) - (define new-right (round (- right (- (sub1 x-max) param-x-max)))) - (define new-top (round (+ top (- y-min param-y-min)))) - (define new-bottom (round (- bottom (- (sub1 y-max) param-y-max)))) + (define new-left (round (+ left (- x- param-x-min)))) + (define new-right (round (- right (- x+ param-x-max)))) + (define new-top (round (+ top (- y- param-y-min)))) + (define new-bottom (round (- bottom (- y+ param-y-max)))) ;; Not enough space? (define area-x-min (+ x-min new-left)) diff --git a/plot-lib/plot/private/plot2d/plot-area.rkt b/plot-lib/plot/private/plot2d/plot-area.rkt index 18202772..61890557 100644 --- a/plot-lib/plot/private/plot2d/plot-area.rkt +++ b/plot-lib/plot/private/plot2d/plot-area.rkt @@ -552,7 +552,7 @@ (define: top : Real 0) (define: bottom : Real 0) (let-values ([(left-val right-val top-val bottom-val) - (margin-fixpoint 0 dc-x-size init-top-margin dc-y-size 0 0 init-top-margin 0 + (margin-fixpoint 0 dc-x-size 0 dc-y-size 0 0 init-top-margin 0 (λ ([left : Real] [right : Real] [top : Real] [bottom : Real]) (get-param-vs/set-view->dc! left right top bottom)))]) (set! left left-val) diff --git a/plot-test/plot/tests/PRs/75.rkt b/plot-test/plot/tests/PRs/75.rkt new file mode 100644 index 00000000..3b5f8033 --- /dev/null +++ b/plot-test/plot/tests/PRs/75.rkt @@ -0,0 +1,23 @@ +#lang racket +(require rackunit + plot pict + racket/runtime-path + "../helpers.rkt") + +;; Tests for: https://github.com/racket/plot/pull/75 + +(define (do-plot-margin-calc output-fn) + (output-fn (function values 0 1) + #:title (standard-fish 700 350))) + +(define-runtime-path pr75-data "./test-data/pr75.dat") + +(define pr75-test-suite + (test-suite + "PR#75: margin error" + (test-case "pr75-margin" + (check-draw-steps do-plot-margin-calc pr75-data)))) + +(module+ test + (require rackunit/text-ui) + (run-tests pr75-test-suite)) diff --git a/plot-test/plot/tests/PRs/test-data/pr75.dat b/plot-test/plot/tests/PRs/test-data/pr75.dat new file mode 100644 index 00000000..55583442 Binary files /dev/null and b/plot-test/plot/tests/PRs/test-data/pr75.dat differ diff --git a/plot-test/plot/tests/PRs/test-data/pr75.png b/plot-test/plot/tests/PRs/test-data/pr75.png new file mode 100644 index 00000000..52e4954a Binary files /dev/null and b/plot-test/plot/tests/PRs/test-data/pr75.png differ diff --git a/plot-test/plot/tests/test-data/p3d-14.dat b/plot-test/plot/tests/test-data/p3d-14.dat index ede2a272..022715d8 100644 Binary files a/plot-test/plot/tests/test-data/p3d-14.dat and b/plot-test/plot/tests/test-data/p3d-14.dat differ diff --git a/plot-test/plot/tests/test-data/p3d-14.png b/plot-test/plot/tests/test-data/p3d-14.png index daab0f3d..d2bef3bc 100644 Binary files a/plot-test/plot/tests/test-data/p3d-14.png and b/plot-test/plot/tests/test-data/p3d-14.png differ