• Smoothing over 'moveto' vs 'lineto'

    From luser droog@21:1/5 to All on Mon Jan 24 09:19:20 2022
    In simple drawing programs I keep running into the very minor
    problem that you have to call 'moveto' on the first point but
    then 'lineto' on all the other points to put a line segment into
    the path. It is very minor. But it keeps on happening.

    This last time around I had my points all nicely packed into
    an array of array. Lovely. And that led to this function which
    I haven't found the right name for:

    /fx,mapgxs { % a f g . [a0 f] [a1 g .. aN g]
    3 1 roll exch dup first % g f a a0
    3 -1 roll [ 3 1 roll exec ] % g a [a0 f]
    3 1 roll rest exch map % [a0 f] [a1 g .. aN g]
    } def
    /first{ 0 get } def
    /rest{ 1 1 index length 1 sub getinterval } def
    /map { 1 index xcheck 3 1 roll [ 3 1 roll forall ] exch {cvx} if } def

    Which you call like this:

    /draw { % [[x0 y0]..[xN yN]] . -
    {aload pop moveto} {aload pop lineto} fx,mapgxs pop pop
    closepath
    } def


    Looking over some old code just now I found a completely
    different approach to the same problem, by redefining the
    thing to call. The `currentpoint stroke moveto` is just to "animate"
    the drawing.

    /newline { /line {moveto /line {lineto currentpoint stroke moveto} store} store } def

    Which you could use like this (remove the "currentpoint stroke moveto"
    above for closepath to work):

    /draw {
    newline {aload pop line} forall
    closepath
    } def

    Are there other solutions? Is this a problem for anyone else?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luser droog@21:1/5 to luser droog on Mon Jan 24 09:58:57 2022
    On Monday, January 24, 2022 at 11:19:21 AM UTC-6, luser droog wrote:
    In simple drawing programs I keep running into the very minor
    problem that you have to call 'moveto' on the first point but
    then 'lineto' on all the other points to put a line segment into
    the path. It is very minor. But it keeps on happening.

    This last time around I had my points all nicely packed into
    an array of array. Lovely. And that led to this function which
    I haven't found the right name for:

    /fx,mapgxs { % a f g . [a0 f] [a1 g .. aN g]
    3 1 roll exch dup first % g f a a0
    3 -1 roll [ 3 1 roll exec ] % g a [a0 f]
    3 1 roll rest exch map % [a0 f] [a1 g .. aN g]
    } def
    /first{ 0 get } def
    /rest{ 1 1 index length 1 sub getinterval } def
    /map { 1 index xcheck 3 1 roll [ 3 1 roll forall ] exch {cvx} if } def

    Which you call like this:

    /draw { % [[x0 y0]..[xN yN]] . -
    {aload pop moveto} {aload pop lineto} fx,mapgxs pop pop
    closepath
    } def


    Looking over some old code just now I found a completely
    different approach to the same problem, by redefining the
    thing to call. The `currentpoint stroke moveto` is just to "animate"
    the drawing.

    /newline { /line {moveto /line {lineto currentpoint stroke moveto} store} store } def

    Which you could use like this (remove the "currentpoint stroke moveto"
    above for closepath to work):

    /draw {
    newline {aload pop line} forall
    closepath
    } def

    Are there other solutions? Is this a problem for anyone else?

    Oh. I forgot about this other way. Perhaps this should be called the "Oopsie!" technique.

    /line { {currentpoint pop pop}stopped{moveto}{lineto} ifelse } def

    or just:

    /line { {lineto}stopped{moveto}if } def

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)