-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathprep-vectors.lisp
More file actions
147 lines (131 loc) · 5.3 KB
/
prep-vectors.lisp
File metadata and controls
147 lines (131 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;; prep-vectors.lisp - Preprocess data vectors into PlotView pixel-space vectors
;;
;; DM/RAL 02/24
;; ---------------------------------------------------------------
(in-package :plotter)
;; Precompute a pixel-space list of PlotView (x,y) coords suitable for
;; use by GP:DRAW-POLYGON.
;;
;; This transforms data points from data space to pixel space within
;; the PlotView. That mapping does not change when the frame shrinks
;; or grows, because that scaling occurs afterward during rendering.
;;
;; Doing this offloads a huge amount of work from the CAPI Main
;; thread. All it needs to do is blast through the list of prepped
;; coords and perform graphics state transforms along the way. That
;; would happen in any event.
;;
(defun prep-vectors (plt xvector yvector
&key
plot-style
symbol-for-legend
plot-joined
&allow-other-keys)
(let+ ((line-style (line-style plot-style))
(symbol-style (and (not symbol-for-legend)
(symbol-style plot-style)))
(nel (if xvector
(min (length-of xvector) (length-of yvector))
(length-of yvector)))
(xlog (plotter-xlog plt))
(xlogfn (logfn xlog))
(ylog (plotter-ylog plt))
(ylogfn (logfn ylog))
(xs (let ((scanner (make-scanner (or xvector
nel))
))
(if xlog
(make-transformer scanner xlogfn)
scanner)))
(ys (let ((scanner (make-scanner yvector)))
(if ylog
(make-transformer scanner ylogfn)
scanner)))
(pairs (make-pair-scanner xs ys))
(xform (plotter-xform plt))
(xfpairs (make-gpxform-pairs xform pairs))
(:mvb (x0 y0) (gp:transform-point xform 0 0)))
(flet ((line-pairs ()
(let* ((xfpairs (case plot-joined
((:spline)
(make-gpxform-pairs xform
(make-pairs-for-spline pairs)))
(otherwise
xfpairs))
))
(collect-pairs xfpairs))
))
;; Mirror the decision logic used by the renderer, PW-PLOT-PREPPED.
(cond (symbol-style
(case (plot-symbol symbol-style)
(:vbars
(if (bar-width symbol-style)
(let* ((wd (get-x-width plt (bar-width symbol-style)))
(off (if (bar-offset symbol-style)
(get-x-width plt (bar-offset symbol-style))
0)
))
(vbar-rects xfpairs wd off y0))
;; else
(histo-vbars-pairs xfpairs y0)
))
(:hbars
(if (bar-width symbol-style)
(let* ((wd (get-y-width plt (bar-width symbol-style)))
(off (if (bar-offset symbol-style)
(get-y-width plt (bar-offset symbol-style))
0)
))
(hbar-rects xfpairs wd off x0))
;; else
(histo-hbars-pairs xfpairs x0)
))
(:sampled-data
(values (line-pairs)
(get-symbol-plotfn (display-pane-of plt) (symbol-style plot-style))
))
(otherwise
(values (line-pairs)
(get-symbol-plotfn (display-pane-of plt) symbol-style)
))))
(line-style
(case (line-type line-style)
(:stepped
(stairstep-pairs xfpairs))
(:histo
(histo-pairs xfpairs))
(otherwise
(line-pairs))
))
))
))
;; -------------------------------------------------------------
;; Used by
;; :SYMBOL :SAMPLED-DATA
;; :SYMBOL <sym>
(defun do-with-pts (lst fn)
(um:nlet iter ((lst lst))
(unless (endp lst)
(let+ (( (x y . rest) lst))
(funcall fn x y)
(go-iter rest))
)))
(defmacro with-pts ((lst x y) &body body)
`(do-with-pts ,lst (lambda (,x ,y)
,@body)))
;; ------------------------------------------------------
;; Used by
;; :SYMBOL :VBARS
;; :SYMBOL :HBARS
;;
;; when the bars have user selected :BAR-WIDTH and :BAR-OFFSET.
(defun do-with-rects (lst fn)
(um:nlet iter ((lst lst))
(unless (endp lst)
(let+ (( (x y w h . rest) lst))
(funcall fn x y w h)
(go-iter rest)))
))
(defmacro with-rects ((lst x y w h) &body body)
`(do-with-rects ,lst (lambda (,x ,y ,w ,h)
,@body)))