charts.lines: use x and y instead of first and second
parent
4fda623f51
commit
b0ec86be44
|
@ -28,37 +28,37 @@ ALIAS: y second
|
||||||
! Return a slice of the seq with all elements equal to elt to the
|
! Return a slice of the seq with all elements equal to elt to the
|
||||||
! left of the index, plus one that's not equal, if requested.
|
! left of the index, plus one that's not equal, if requested.
|
||||||
:: adjusted-tail-slice ( n elt plus-one? seq -- slice )
|
:: adjusted-tail-slice ( n elt plus-one? seq -- slice )
|
||||||
n seq elt first '[ first _ = not ] find-last-from drop seq swap
|
n seq elt x '[ x _ = not ] find-last-from drop seq swap
|
||||||
[ plus-one? [ 1 + ] unless tail-slice ] when* ;
|
[ plus-one? [ 1 + ] unless tail-slice ] when* ;
|
||||||
|
|
||||||
! Return a slice of the seq with all elements equal to elt to the
|
! Return a slice of the seq with all elements equal to elt to the
|
||||||
! right of the index, plus one that's not equal, if requested.
|
! right of the index, plus one that's not equal, if requested.
|
||||||
:: adjusted-head-slice ( n elt plus-one? seq -- slice )
|
:: adjusted-head-slice ( n elt plus-one? seq -- slice )
|
||||||
n seq elt first '[ first _ = not ] find-from drop seq swap
|
n seq elt x '[ x _ = not ] find-from drop seq swap
|
||||||
[ plus-one? [ 1 + ] when short head-slice ] when* ;
|
[ plus-one? [ 1 + ] when short head-slice ] when* ;
|
||||||
|
|
||||||
! : data-rect ( data -- rect )
|
! : data-rect ( data -- rect )
|
||||||
! [ [ first first ] [ last first ] bi ] keep
|
! [ [ first x ] [ last x ] bi ] keep
|
||||||
! [ second ] map minmax swapd
|
! [ y ] map minmax swapd
|
||||||
! 2array [ 2array ] dip <extent-rect> ;
|
! [ 2array ] bi@ <extent-rect> ;
|
||||||
|
|
||||||
: first-in-bounds? ( min,max pairs -- ? )
|
: x-in-bounds? ( min,max pairs -- ? )
|
||||||
{
|
{
|
||||||
[ [ first ] dip last first > not ]
|
[ [ first ] dip last x > not ]
|
||||||
[ [ second ] dip first first < not ]
|
[ [ second ] dip first x < not ]
|
||||||
} 2&& ;
|
} 2&& ;
|
||||||
|
|
||||||
: second-in-bounds? ( min,max pairs -- ? )
|
: y-in-bounds? ( min,max pairs -- ? )
|
||||||
[ second ] map minmax 2array
|
[ y ] map minmax 2array
|
||||||
{
|
{
|
||||||
[ [ first ] dip second > not ]
|
[ [ first ] dip second > not ]
|
||||||
[ [ second ] dip first < not ]
|
[ [ second ] dip first < not ]
|
||||||
} 2&& ;
|
} 2&& ;
|
||||||
|
|
||||||
! : pairs-in-bounds? ( bounds pairs -- ? )
|
! : xy-in-bounds? ( bounds pairs -- ? )
|
||||||
! {
|
! {
|
||||||
! [ [ first ] dip first-in-bounds? ]
|
! [ [ first ] dip x-in-bounds? ]
|
||||||
! [ [ second ] dip second-in-bounds? ]
|
! [ [ second ] dip y-in-bounds? ]
|
||||||
! } 2&& ;
|
! } 2&& ;
|
||||||
|
|
||||||
: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
|
: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
|
||||||
|
@ -71,7 +71,7 @@ ALIAS: y second
|
||||||
! pairs is <= min, and if the first is < min, then the second is
|
! pairs is <= min, and if the first is < min, then the second is
|
||||||
! > min. Otherwise the first one would be = min.
|
! > min. Otherwise the first one would be = min.
|
||||||
: left-cut ( min pairs -- seq )
|
: left-cut ( min pairs -- seq )
|
||||||
2dup first first < [
|
2dup first x < [
|
||||||
[ dupd first2 y-at 2array ] keep rest-slice swap prefix
|
[ dupd first2 y-at 2array ] keep rest-slice swap prefix
|
||||||
] [
|
] [
|
||||||
nip
|
nip
|
||||||
|
@ -81,7 +81,7 @@ ALIAS: y second
|
||||||
! pairs is >= max, and if the last is > max, then the second to
|
! pairs is >= max, and if the last is > max, then the second to
|
||||||
! last is < max. Otherwise the last one would be = max.
|
! last is < max. Otherwise the last one would be = max.
|
||||||
: right-cut ( max pairs -- seq )
|
: right-cut ( max pairs -- seq )
|
||||||
2dup last first < [
|
2dup last x < [
|
||||||
[ dupd last2 y-at 2array ] keep but-last-slice swap suffix
|
[ dupd last2 y-at 2array ] keep but-last-slice swap suffix
|
||||||
] [
|
] [
|
||||||
nip
|
nip
|
||||||
|
@ -92,8 +92,8 @@ ALIAS: y second
|
||||||
: min-max-cut ( min,max pairs -- seq )
|
: min-max-cut ( min,max pairs -- seq )
|
||||||
[ first2 ] dip right-cut left-cut ;
|
[ first2 ] dip right-cut left-cut ;
|
||||||
|
|
||||||
: clip-by-first ( min,max pairs -- pairs' )
|
: clip-by-x ( min,max pairs -- pairs' )
|
||||||
2dup first-in-bounds? [
|
2dup x-in-bounds? [
|
||||||
[ dup first ] dip [ search-first? not ] keep
|
[ dup first ] dip [ search-first? not ] keep
|
||||||
adjusted-tail-slice
|
adjusted-tail-slice
|
||||||
[ dup second ] dip [ search-first? not ] keep
|
[ dup second ] dip [ search-first? not ] keep
|
||||||
|
@ -195,7 +195,7 @@ ALIAS: y second
|
||||||
! points at ymin and ymax at the gap bounds.
|
! points at ymin and ymax at the gap bounds.
|
||||||
: drawable-chunks ( data ymin,ymax -- chunks )
|
: drawable-chunks ( data ymin,ymax -- chunks )
|
||||||
first2 [
|
first2 [
|
||||||
'[ [ second _ _ between<=> ] bi@ = ]
|
'[ [ y _ _ between<=> ] bi@ = ]
|
||||||
monotonic-split-slice
|
monotonic-split-slice
|
||||||
] 2keep (drawable-chunks) ;
|
] 2keep (drawable-chunks) ;
|
||||||
|
|
||||||
|
@ -228,12 +228,12 @@ PRIVATE>
|
||||||
[ (line-vertices) gl-vertex-pointer GL_LINES 0 ] keep
|
[ (line-vertices) gl-vertex-pointer GL_LINES 0 ] keep
|
||||||
length glDrawArrays ;
|
length glDrawArrays ;
|
||||||
|
|
||||||
! bounds: { { first-min first-max } { second-min second-max } }
|
! bounds: { { xmin xmax } { ymin ymax } }
|
||||||
: clip-data ( bounds data -- data' )
|
: clip-data ( bounds data -- data' )
|
||||||
dup empty? [ nip ] [
|
dup empty? [ nip ] [
|
||||||
dupd [ first ] dip clip-by-first
|
dupd [ first ] dip clip-by-x
|
||||||
dup empty? [ nip ] [
|
dup empty? [ nip ] [
|
||||||
[ second ] dip [ second-in-bounds? ] keep swap
|
[ second ] dip [ y-in-bounds? ] keep swap
|
||||||
[ drop { } ] unless
|
[ drop { } ] unless
|
||||||
] if
|
] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
Loading…
Reference in New Issue