1+ #lang typed/racket/base
2+
3+ ;; Untyped interface / contract
4+ (module untyped racket/base
5+ (require racket/class
6+ racket/contract
7+ racket/match
8+ racket/draw)
9+
10+ (provide plot-metrics<%>
11+ plot-metrics-object/c)
12+
13+ (define plot-metrics<%> (interface ()
14+ get-plot-bounds
15+ dc->plot
16+ plot->dc
17+ plane-vector
18+ get-plot-metrics-functions))
19+
20+ (define plot-metrics-object/c
21+ (object/c [get-plot-bounds (->m (-> (vectorof (vector/c real? real?))))]
22+ [plot->dc (->m (vectorof real?) (vectorof real?))]
23+ [dc->plot (->m (vectorof real?) (vectorof real?))]
24+ [plane-vector (->m (vectorof real?))]
25+ [get-plot-metrics-functions (->m (values (-> (vectorof (vector/c real? real?)))
26+ (-> (vectorof real?) (vectorof real?))
27+ (-> (vectorof real?) (vectorof real?))
28+ (-> (vectorof real?))))]))
29+ )
30+
31+ ;; Typed Types / mixin / structures
32+ (require typed/pict
33+ typed/racket/class
34+ racket/match)
35+
36+ (provide plot-metrics-mixin Plot-Metrics-Functions Plot-Metrics<%> plot-metrics%
37+ (struct-out plot-pict) Plot-Pict pict->pp)
38+
39+ (define-type Metrics-Object (Object [get-plot-metrics-functions (-> Plot-Metrics-Functions)]))
40+ (define-type Plot-Metrics-Functions (List (-> (Vectorof (Vectorof Real)))
41+ (-> (Vectorof Real) (Vectorof Real))
42+ (-> (Vectorof Real) (Vectorof Real))
43+ (-> (Vectorof Real))))
44+ (define-type Plot-Metrics<%>
45+ (Class
46+ [get-plot-bounds (-> (Vectorof (Vectorof Real)))]
47+ [plot->dc (-> (Vectorof Real) (Vectorof Real))]
48+ [dc->plot (-> (Vectorof Real) (Vectorof Real))]
49+ [plane-vector (-> (Vectorof Real))]
50+ [get-plot-metrics-functions (-> Plot-Metrics-Functions)]))
51+
52+ (: plot-metrics-mixin (All (A #:row ) (-> (Class #:row-var A)
53+ (Class [init [->metrics-object (-> Metrics-Object)]]
54+ #:row-var A
55+ #:implements Plot-Metrics<%>))))
56+ (define (plot-metrics-mixin %)
57+ (class %
58+ (init ->metrics-object)
59+ (define (load) : Void
60+ (match-define (list new-bounds new-->dc new-->plot new-plane)
61+ (send (->metrics-object) get-plot-metrics-functions))
62+ (set! bounds new-bounds)
63+ (set! ->dc new-->dc)
64+ (set! ->plot new-->plot)
65+ (set! plane new-plane)
66+ (set! getall (λ () (list bounds ->dc ->plot plane)))
67+ (set! load void))
68+
69+ (define (bounds) : (Vectorof (Vectorof Real)) (load)(bounds))
70+ (define (plane) : (Vectorof Real) (load)(plane))
71+ (define (getall) : Plot-Metrics-Functions (load)(list bounds ->dc ->plot plane))
72+ (define (->dc [v : (Vectorof Real)]) : (Vectorof Real) (load)(->dc v))
73+ (define (->plot [v : (Vectorof Real)]) : (Vectorof Real) (load)(->plot v))
74+
75+ (super-make-object )
76+ (define/public (get-plot-bounds) (bounds))
77+ (define/public (dc->plot coords) (->plot coords))
78+ (define/public (plot->dc coords) (->dc coords))
79+ (define/public (plane-vector) (plane))
80+ (define/public (get-plot-metrics-functions) (getall))))
81+
82+ (define plot-metrics% (plot-metrics-mixin object%))
83+
84+
85+ (struct plot-pict pict ([bounds : (Vectorof (Vectorof Real))]
86+ [plot->dc : (-> (Vectorof Real) (Vectorof Real))]
87+ [dc->plot : (-> (Vectorof Real) (Vectorof Real))]
88+ [plane-vector : (Vectorof Real)]))
89+ (define-type Plot-Pict plot-pict)
90+ (define (pict->pp [P : pict]
91+ [metrics-object : Metrics-Object]) : plot-pict
92+ (match-define (list bounds ->dc ->plot plane)
93+ (send metrics-object get-plot-metrics-functions))
94+
95+ (plot-pict (pict-draw P) (pict-width P) (pict-height P) (pict-ascent P)
96+ (pict-descent P) (pict-children P) (pict-panbox P) (pict-last P)
97+ (bounds) ->dc ->plot (plane)))
0 commit comments