1 ! Copyright (C) 2017 Alexander Ilin.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.ratios sequences tools.test
4 ui.gadgets.charts.lines ui.gadgets.charts.lines.private
5 ui.gadgets.charts.utils ;
7 { -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
8 [ { 5 0 } { 5 5 } calc-line-slope ] [ division-by-zero? ] must-fail-with
9 { 3 } [ -2/3 1 { 1 3 } calc-y ] unit-test
10 { 5 } [ -2/3 -2 { 1 3 } calc-y ] unit-test
11 { 3 } [ -2/3 1 { -2 5 } calc-y ] unit-test
12 { 5 } [ -2/3 -2 { -2 5 } calc-y ] unit-test
13 { 5 } [ -2 { 1 3 } { -2 5 } y-at ] unit-test
14 { 3 } [ 1 { 1 3 } { -2 5 } y-at ] unit-test
15 { 1 } [ 4 { -2 5 } { 1 3 } y-at ] unit-test
16 { 0.0 } [ 5.5 { -2 5 } { 1 3 } y-at ] unit-test
17 { 1 } [ -2/3 3 { 1 3 } calc-x ] unit-test
18 { -2 } [ -2/3 5 { 1 3 } calc-x ] unit-test
19 { 1 } [ -2/3 3 { -2 5 } calc-x ] unit-test
20 { -2 } [ -2/3 5 { -2 5 } calc-x ] unit-test
22 { 2 3 } [ { 1 2 3 } last2 ] unit-test
23 { 1 2 } [ { 1 2 } last2 ] unit-test
24 [ { 1 } last2 ] must-fail
25 [ { } last2 ] must-fail
27 ! 2-point-chunk upwards
31 { { -6 0 } { -5 -5 } } { { 5 5 } { 6 0 } }
35 ! 2-point-chunk downwards
39 { { -6 0 } { -5 5 } } { { 5 -5 } { 6 0 } }
43 ! 2-point-chunk: same x coord
45 { { -5 -3 } { -5 3 } }
47 { { -6 0 } { -5 -5 } } { { -5 5 } { 6 0 } }
51 ! fix-left-chunk: y coord = top limit
55 { { -6 0 } { -3 3 } } { { 5 5 } { 6 6 } }
59 ! fix-left-chunk: y coord = bottom limit
61 { { -6 0 } { -3 -3 } }
63 { { -6 0 } { -3 -3 } } { { 5 -5 } { 6 -6 } }
67 ! fix-left-chunk: going upwards
69 { { -6 0 } { 2 2 } { 3 3 } }
71 { { -6 0 } { 2 2 } } { { 5 5 } { 6 6 } }
75 ! fix-left-chunk: going downwards
77 { { -6 0 } { -2 -2 } { -1 -3 } }
79 { { -6 0 } { -2 -2 } } { { 0 -4 } { 6 -6 } }
83 ! TODO: add more tests for the recently discovered bugs in fix-left-chunk and fix-right-chunk
85 ! fix-right-chunk: y coord = top limit
89 { { -6 6 } { -3 4 } } { { 5 3 } { 6 0 } }
93 ! fix-right-chunk: y coord = bottom limit
97 { { -6 -6 } { -3 -4 } } { { 5 -3 } { 6 0 } }
101 ! fix-right-chunk: going upwards
103 { { -3 -3 } { -2 -2 } { 6 0 } }
105 { { -6 -6 } { -4 -4 } } { { -2 -2 } { 6 0 } }
109 ! fix-right-chunk: going downwards
111 { { -3 3 } { -2 2 } { 6 0 } }
113 { { -6 6 } { -4 4 } } { { -2 2 } { 6 0 } }
119 { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
121 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 0 5 }
122 drawable-chunks [ { } like ] map
127 { { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } }
129 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 6 }
130 drawable-chunks [ { } like ] map
133 ! only bottom element accepted
137 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -1 0 }
138 drawable-chunks [ { } like ] map
141 ! only top element accepted
145 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 5 10 }
146 drawable-chunks [ { } like ] map
149 ! top half of the elements accepted
151 { { { 1 2 } { 1 3 } { 2 5 } } }
153 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 2 10 }
154 drawable-chunks [ { } like ] map
157 ! bottom half of the elements accepted
159 { { { 0 0 } { 0 1 } { 1 2 } } }
161 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { -2 2 }
162 drawable-chunks [ { } like ] map
165 ! middle section of the elements accepted
167 { { { 0 1 } { 1 2 } { 1 3 } } }
169 { { 0 0 } { 0 1 } { 1 2 } { 1 3 } { 2 5 } } { 1 3 }
170 drawable-chunks [ { } like ] map
173 ! two sections, including first but not last
176 { { 0 0 } { 1 2 } { 2 3 } }
177 { { 5 3 } { 6 2 } { 7 0 } }
180 { { 0 0 } { 1 2 } { 2 3 } { 3 5 } { 4 5 } { 5 3 } { 6 2 } { 7 0 } { 8 -1 } { 9 -2 } } { 0 3 }
181 drawable-chunks [ { } like ] map
184 ! two sections, including last but not first
187 { { 2 0 } { 3 3 } { 4 3 } }
188 { { 7 3 } { 8 2 } { 9 0 } }
191 { { 0 -2 } { 1 -1 } { 2 0 } { 3 3 } { 4 3 } { 5 5 } { 6 9 } { 7 3 } { 8 2 } { 9 0 } } { 0 3 }
192 drawable-chunks [ { } like ] map
195 ! single-element sequences, same x coord
202 { { 0 -2 } { 0 0 } { 0 5 } { 0 3 } { 0 -1 } } { 0 3 }
203 drawable-chunks [ { } like ] map
206 ! single point sticks out to within the limits from below
209 { { 1 1 } { 2 2 } { 3 1 } }
212 { { 0 0 } { 2 2 } { 4 0 } } { 1 5 }
213 drawable-chunks [ { } like ] map
216 ! single point sticks out to within the limits from above
219 { { 1 3 } { 2 2 } { 3 3 } }
222 { { 0 4 } { 2 2 } { 4 4 } } { 1 3 }
223 drawable-chunks [ { } like ] map
227 { { { 0 300 } { 1 200 } { 2 150 } { 3 100 } { 4 0 } } }
229 { { { 0 0 } { 1 100 } { 2 150 } { 3 200 } { 4 300 } } }
230 { 0 300 } flip-y-axis
234 { 0 30 60 90 120 150 180 210 240 270 300 }
236 11 <iota> [ 10 + ] map [ 300 swap 20 10 scale ] map
240 [ { } { } clip-data ] unit-test
243 [ { { 0 1 } { 0 5 } } { } clip-data ] unit-test
245 ! Adjustment after search is required in both directions.
248 { 1 3 } { 1 4 } { 1 5 }
249 { 2 6 } { 3 7 } { 4 8 }
250 { 5 9 } { 5 10 } { 5 11 } { 5 12 }
256 { 1 3 } { 1 4 } { 1 5 }
257 { 2 6 } { 3 7 } { 4 8 }
258 { 5 9 } { 5 10 } { 5 11 } { 5 12 }
263 ! no points within the viewport, complete calculation
268 { { 0 0 } { 5 5 } } clip-data
271 ! no points within the viewport, complete calculation
276 { { 0 5 } { 5 0 } } clip-data
279 ! no points within the viewport, complete calculation
284 { { 0 3 } { 5 3 } } clip-data
287 ! all data are to the left of viewport
292 { { -1 0 } { 0 1 } { 0.5 1 } } clip-data
295 ! all data are to the right of viewport
300 { { 4.5 0 } { 5 1 } { 6 1 } } clip-data
303 ! just a little off the top
306 { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } }
310 ! TODO: add tests where after search there is no adjustment necessary, so that extra adjustment would take bad elements.