Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2791 > unrolled thread
| Started by | Peter Billam <peter@www.pjb.com.au> |
|---|---|
| First post | 2016-08-25 09:42 +0000 |
| Last post | 2016-08-27 10:32 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.postscript
How can I test for an open subpath ? Peter Billam <peter@www.pjb.com.au> - 2016-08-25 09:42 +0000
Re: How can I test for an open subpath ? Carlos <angus@quovadis.com.ar> - 2016-08-25 16:49 +0200
Re: How can I test for an open subpath ? Peter Billam <peter@www.pjb.com.au> - 2016-08-27 04:28 +0000
Re: How can I test for an open subpath ? jdaw1 <jdawiseman@gmail.com> - 2016-08-27 10:32 -0700
| From | Peter Billam <peter@www.pjb.com.au> |
|---|---|
| Date | 2016-08-25 09:42 +0000 |
| Subject | How can I test for an open subpath ? |
| Message-ID | <slrnnrtfc1.51t.peter@box8.pjb.com.au> |
I find it easy enough to test for existence of a current path, eg:
{ currentpoint } stopped { ... % no
} { pop pop ... % yes
} ifelse
(and there may be better ways)
but I'd like to start a procedure with a lineto if there's
a currently open subpath, and with a moveto if there isn't.
Is there a neat way of doing this ?
I can't just use currentpoint because it remains defined
after a closepath; likewise:
{ gsave lineto grestore } stopped { x0 y0 moveto % no
} { x0 y0 lineto % yes
} ifelse
messes up for (I think) similar reasons ... There must be
some neater way than overwriting newpath and closepath ...
Do I have to do forsenics inside pathforall ?
Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
[toc] | [next] | [standalone]
| From | Carlos <angus@quovadis.com.ar> |
|---|---|
| Date | 2016-08-25 16:49 +0200 |
| Message-ID | <npn0i9$fq5$1@dont-email.me> |
| In reply to | #2791 |
On 25/08/2016 11:42, Peter Billam wrote:
> I find it easy enough to test for existence of a current path, eg:
> { currentpoint } stopped { ... % no
> } { pop pop ... % yes
> } ifelse
> (and there may be better ways)
>
> but I'd like to start a procedure with a lineto if there's
> a currently open subpath, and with a moveto if there isn't.
> Is there a neat way of doing this ?
> I can't just use currentpoint because it remains defined
> after a closepath; likewise:
> { gsave lineto grestore } stopped { x0 y0 moveto % no
> } { x0 y0 lineto % yes
> } ifelse
> messes up for (I think) similar reasons ... There must be
> some neater way than overwriting newpath and closepath ...
> Do I have to do forsenics inside pathforall ?
>
> Peter
>
It's actually quite simple using pathforall, since one of the procs it
takes is called specifically on closepath.
/isclosed {
false
{ pop pop false exch pop }
{ pop pop false exch pop }
{ pop pop pop pop pop pop false exch pop }
{ true exch pop } pathforall
} def
HTH
--
[toc] | [prev] | [next] | [standalone]
| From | Peter Billam <peter@www.pjb.com.au> |
|---|---|
| Date | 2016-08-27 04:28 +0000 |
| Message-ID | <slrnns25ml.38i.peter@box8.pjb.com.au> |
| In reply to | #2792 |
On 2016-08-25, Carlos <angus@quovadis.com.ar> wrote:
> On 25/08/2016 11:42, Peter Billam wrote:
>> but I'd like to start a procedure with a lineto if there's
>> a currently open subpath, and with a moveto if there isn't.
>> Is there a neat way of doing this ?
>> Do I have to do forsenics inside pathforall ?
> It's actually quite simple using pathforall, since one of
> the procs it takes is called specifically on closepath.
> /isclosed {
> false
> { pop pop false exch pop }
> { pop pop false exch pop }
> { pop pop pop pop pop pop false exch pop }
> { true exch pop } pathforall
> } def
Yes, that's neat. For my use-case I changed the inital false to
true, so that with no current path it would return the same as
after a subpath has been closed, and then I took the liberty
of inverting all the booleans and renaming it is_open_subpath
/is_open_subpath { % Carlos comp.lang.postscript 20160826 inverted
false % except I treat no-currentpath the same as no-open-subpath
{ pop pop true exch pop }
{ pop pop true exch pop }
{ pop pop pop pop pop pop true exch pop }
{ false exch pop } pathforall
} bind def
in which form it appears in
http://www.pjb.com.au/comp/line_drawing.html#points2curve
http://www.pjb.com.au/comp/free/line_drawing.ps.txt
https://github.com/peterbillam/postscriptlib/blob/master/line_drawing.ps
and seems to work well :-) It seems sad to loop through the entire
path just in order to read the last item, but it's only once per
invocation. I'll roll it into other path-segment-constructor procs :-)
Thanks !
Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
[toc] | [prev] | [next] | [standalone]
| From | jdaw1 <jdawiseman@gmail.com> |
|---|---|
| Date | 2016-08-27 10:32 -0700 |
| Message-ID | <2b6512d4-8899-4d9a-9603-ab346a5eea6c@googlegroups.com> |
| In reply to | #2792 |
On Thursday, 25 August 2016 15:49:46 UTC+1, Carlos wrote:
> /isclosed {
> false
> { pop pop false exch pop }
> { pop pop false exch pop }
> { pop pop pop pop pop pop false exch pop }
> { true exch pop } pathforall
> } def
Slight improvement: replace every “false exch pop” with “pop false”, and “true exch pop” with “pop true”.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web