charts.lines: implement (drawable-chunks)
parent
8a87a8077e
commit
5a3ae9099d
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2016-2017 Alexander Ilin.
|
! Copyright (C) 2016-2017 Alexander Ilin.
|
||||||
|
|
||||||
USING: accessors arrays binary-search charts
|
USING: accessors arrays binary-search charts combinators
|
||||||
combinators.short-circuit fry kernel locals math math.order
|
combinators.short-circuit fry kernel locals make math math.order
|
||||||
math.statistics math.vectors opengl opengl.gl sequences
|
math.statistics math.vectors namespaces opengl opengl.gl
|
||||||
specialized-arrays.instances.alien.c-types.float
|
sequences specialized-arrays.instances.alien.c-types.float
|
||||||
splitting.monotonic ui.gadgets ui.render ;
|
splitting.monotonic ui.gadgets ui.render ;
|
||||||
IN: charts.lines
|
IN: charts.lines
|
||||||
|
|
||||||
|
@ -110,9 +110,6 @@ ALIAS: y second
|
||||||
: between<=> ( value min max -- <=> )
|
: between<=> ( value min max -- <=> )
|
||||||
3dup between? [ 3drop +eq+ ] [ nip > +gt+ +lt+ ? ] if ;
|
3dup between? [ 3drop +eq+ ] [ nip > +gt+ +lt+ ? ] if ;
|
||||||
|
|
||||||
! Drop chunks that are out of bounds, add extra points where needed.
|
|
||||||
: (drawable-chunks) ( chunks min max -- chunks )
|
|
||||||
'[ first second _ _ between? ] filter harvest ;
|
|
||||||
|
|
||||||
: calc-point-y ( slope y point -- xy ) over [ calc-x ] dip 2array ;
|
: calc-point-y ( slope y point -- xy ) over [ calc-x ] dip 2array ;
|
||||||
|
|
||||||
|
@ -160,6 +157,43 @@ ALIAS: y second
|
||||||
right rest-slice swap suffix
|
right rest-slice swap suffix
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: first-point ( chunks -- first-point ) first first ;
|
||||||
|
: last-point ( chunks -- last-point ) last last ;
|
||||||
|
|
||||||
|
SYMBOL: elt
|
||||||
|
|
||||||
|
: each2* ( seq quot: ( prev next -- next' ) -- )
|
||||||
|
[ unclip-slice elt ] dip '[
|
||||||
|
[ elt get swap @ elt set ] each
|
||||||
|
] with-variable ; inline
|
||||||
|
|
||||||
|
:: (make-pair) ( prev next min max -- next' )
|
||||||
|
prev next min max
|
||||||
|
prev next [ first y min max between<=> ] bi@ 2array
|
||||||
|
{
|
||||||
|
{ { +gt+ +eq+ } [ fix-right-chunk ] }
|
||||||
|
{ { +lt+ +eq+ } [ fix-right-chunk ] }
|
||||||
|
{ { +eq+ +gt+ } [ fix-left-chunk , next ] }
|
||||||
|
{ { +eq+ +lt+ } [ fix-left-chunk , next ] }
|
||||||
|
{ { +gt+ +lt+ } [ 2-point-chunk , next ] }
|
||||||
|
{ { +lt+ +gt+ } [ 2-point-chunk , next ] }
|
||||||
|
[ drop "same values - can't happen" throw ]
|
||||||
|
} case ;
|
||||||
|
|
||||||
|
! Drop chunks that are out of bounds, add extra points where needed.
|
||||||
|
:: (drawable-chunks) ( chunks min max -- chunks' )
|
||||||
|
chunks length {
|
||||||
|
{ 0 [ chunks ] }
|
||||||
|
{ 1 [
|
||||||
|
chunks dup first-point y min max between?
|
||||||
|
[ drop { } clone ] unless
|
||||||
|
]
|
||||||
|
}
|
||||||
|
[
|
||||||
|
drop [ chunks [ min max (make-pair) ] each2* ] { } make
|
||||||
|
]
|
||||||
|
} case ;
|
||||||
|
|
||||||
! Split data into chunks to be drawn within the [ymin,ymax] limits.
|
! Split data into chunks to be drawn within the [ymin,ymax] limits.
|
||||||
! Return the (empty?) sequence of chunks, possibly with some new
|
! Return the (empty?) sequence of chunks, possibly with some new
|
||||||
! points at ymin and ymax at the gap bounds.
|
! points at ymin and ymax at the gap bounds.
|
||||||
|
|
Loading…
Reference in New Issue