|
| 1 | +#lang racket |
| 2 | +(require rackunit |
| 3 | + racket/draw pict (only-in racket/gui/base sleep/yield) |
| 4 | + plot (submod plot/private/common/plotmetrics untyped)) |
| 5 | + |
| 6 | +; tests for PR#90, https://github.com/racket/plot/pull/90 |
| 7 | +; "Plotmetrics: access/calculate data about the plot area" |
| 8 | + |
| 9 | + |
| 10 | +(define pr90-test-suite |
| 11 | + (make-test-suite |
| 12 | + "PR#90: plotmetrics" |
| 13 | + (append |
| 14 | + (let* ([bm (make-object bitmap% 400 400)] |
| 15 | + [dc (make-object bitmap-dc% bm)] |
| 16 | + [pm (plot/dc (polar (λ (x) x)) dc 0 0 400 400)]) |
| 17 | + (list (test-suite "PR90: plot-metrics get-plot-bounds" |
| 18 | + (check-within (send pm get-plot-bounds) |
| 19 | + #(#(-3.2883704095701205 6.283185307179586) |
| 20 | + #(-4.8144539337330965 1.81970262809755)) |
| 21 | + 1e-15)) |
| 22 | + (test-suite "PR90: plot-metrics plot->dc & dc->plot" |
| 23 | + (check-within (send pm dc->plot (send pm plot->dc #(0 0))) |
| 24 | + #(0 0) 1e-15)) |
| 25 | + (test-suite "PR90: plot-metrics plane-vector" |
| 26 | + (check-equal? (send pm plane-vector) |
| 27 | + #(0 0 1))))) |
| 28 | + |
| 29 | + (let ([pmbm (plot3d-bitmap (polar3d (λ (ϕ θ) ϕ)))]) |
| 30 | + (list (test-suite "PR90: bitmap" (check-true (is-a? pmbm bitmap%))) |
| 31 | + (test-suite "PR90: 3d/bitmap get-plot-bounds" |
| 32 | + (check-within (send pmbm get-plot-bounds) |
| 33 | + #(#(-3.287703432872698 6.282003882664296) |
| 34 | + #(-4.812750657123522 1.819088586099858) |
| 35 | + #(-6.283185307179587 6.283185307179587)) |
| 36 | + 1e-15)) |
| 37 | + (test-suite "PR90: 3d/bitmap plot->dc & dc->plot" |
| 38 | + (check-within (send pmbm plot->dc (send pmbm dc->plot #(200 200))) |
| 39 | + #(200 200) 1e-15)) |
| 40 | + (test-suite "PR90: 3d/bitmap plane-vector" |
| 41 | + (check-equal? (send pmbm plot->dc (send pmbm plane-vector)) |
| 42 | + (send pmbm plot->dc #(0 0 0)))))) |
| 43 | + |
| 44 | + (let ([pp (plot-pict (function (λ (x) x) 1 2))]) |
| 45 | + (list (test-suite "PR90: plot-pict" (check-true (and (plot-pict? pp) (pict? pp)))) |
| 46 | + (test-suite "PR90: plot-pict get-plot-bounds" |
| 47 | + (check-equal? (plot-pict-bounds pp) |
| 48 | + #(#(1 2) #(1 2)))) |
| 49 | + (test-suite "PR90: plot-pict plot->dc & dc->plot" |
| 50 | + (check-within ((plot-pict-dc->plot pp) ((plot-pict-plot->dc pp) #(0 0))) |
| 51 | + #(0 0) 1e-15)) |
| 52 | + (test-suite "PR90: plot-pict plane-vector" |
| 53 | + (check-equal? (plot-pict-plane-vector pp) |
| 54 | + #(0 0 1))))) |
| 55 | + |
| 56 | + (let* ([ps (plot3d-snip (surface3d (λ (x y) (+ x y)) 0 1 1 2))] |
| 57 | + [plotcoords #(1 1 1)] |
| 58 | + [coords (send ps plot->dc plotcoords)]) |
| 59 | + (list (test-suite "PR90: 3d/snip" (check-true (is-a? ps plot-metrics<%>))) |
| 60 | + (test-suite "PR90: 3d/snip get-plot-bounds" |
| 61 | + (check-equal? (send ps get-plot-bounds) |
| 62 | + #(#(0 1) #(1 2) #(1 3)))) |
| 63 | + (test-suite "PR90: 3d/snip plot->dc & dc->plot" |
| 64 | + (check-within (send ps plot->dc (send ps dc->plot #(200 200))) |
| 65 | + #(200 200) 1e-15)) |
| 66 | + (test-suite "PR90: 3d/snip plane-vector" |
| 67 | + (check-equal? (send ps plot->dc (send ps plane-vector)) |
| 68 | + (send ps plot->dc #(0 0 0)))) |
| 69 | + (test-suite "PR90: 3d/snip before resize" |
| 70 | + (check-equal? (send ps plot->dc plotcoords) coords)) |
| 71 | + (test-suite "PR90: 3d/snip after resize" |
| 72 | + (send ps resize 800 800) |
| 73 | + (sleep/yield .1) |
| 74 | + (check-within (send ps plot->dc (send ps dc->plot #(200 200))) |
| 75 | + #(200 200) 5e-14) |
| 76 | + (check-not-equal? (send ps plot->dc plotcoords) coords))))) |
| 77 | + )) |
| 78 | + |
| 79 | +(module+ test |
| 80 | + (require rackunit/text-ui) |
| 81 | + (run-tests pr90-test-suite)) |
0 commit comments