 ! pairs is <= min, and if the first is < min, then the second is
 ! > min. Otherwise the first one would be = min.
 : left-cut ( min pairs -- seq )
-    2dup first first < [
+    2dup first x < [
         [ dupd first2 y-at 2array ] keep rest-slice swap prefix
     ] [
         nip

    [ (line-vertices) gl-vertex-pointer GL_LINES 0 ] keep
    length glDrawArrays ;

! bounds: { { first-min first-max } { second-min second-max } }
: clip-data ( bounds data -- data' )
    dup empty? [ nip ] [
        dupd [ first ] dip clip-by-first
        dup empty? [ nip ] [
            [ second ] dip [ second-in-bounds? ] keep swap
            [ drop { } ] unless
        ] if
    ] if ;

! 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.
:: adjusted-tail-slice ( n elt plus-one? seq -- slice )
    n seq elt x '[ x _ = not ] find-last-from drop seq swap
    [ plus-one? [ 1 + ] unless tail-slice ] when* ;

! 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.
:: adjusted-head-slice ( n elt plus-one? seq -- slice )
    n seq elt x '[ x _ = not ] find-from drop seq swap
    [ plus-one? [ 1 + ] when short head-slice ] when* ;

! : data-rect ( data -- rect )
!    [ [ first x ] [ last x ] bi ] keep
!    [ y ] map minmax swapd
!    [ 2array ] bi@ <extent-rect> ;

: x-in-bounds? ( min,max pairs -- ? )
    {
        [ [ first ] dip last x > not ]
        [ [ second ] dip first x < not ]
    } 2&& ;

: y-in-bounds? ( min,max pairs -- ? )
    [ y ] map minmax 2array
    {
        [ [ first ] dip second > not ]
        [ [ second ] dip first < not ]
    } 2&& ;

! : xy-in-bounds? ( bounds pairs -- ? )
!    {
!        [ [ first ] dip x-in-bounds? ]
!        [ [ second ] dip y-in-bounds? ]
!    } 2&& ;

: calc-line-slope ( point1 point2 -- slope ) v- first2 swap / ;
