🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #8937

Re: Postscript idiot needed help (and got it)

#8937
From: Ned Batchelder
Date: Fri, 09 Feb 1990 21:40
60 lines
2856 bytes
I recommend reading the Green Book, not to be indoctrinated into one
particular method of writing procedures, but to get exposed to other
ideas on the matter.

Here's another way to do it:

	% rin rout x y `donut' --

	/donut {
		gsave
		translate
		0 setgray
		0 0 3 -1 roll 0 360 arc fill
		1 setgray
		0 0 3 -1 roll 0 360 arc fill
		grestore
	} bind def

Here, we use the x and y to translate the origin so that the pad is
centered at 0,0. This reduces the amount of stack manipulation. I can't
say whether it is more efficient this way, but I wouldn't be surprised.
Notice that I also rearranged the arguments to reduce stack manipulations.

If you look on page 75 of the Red Book (at least my edition), there is a
figure explaining the non-zero winding rule that gives an idea:

	% rin rout x y `donut' --

	/donut {
		gsave
		translate
		0 0 3 -1 roll 0 360 arc
		0 0 3 -1 roll 0 360 arcn
		fill
		grestore
	} bind def

This avoids all of the setgray's, and makes a real donut, in that things
will show through the "hole". It also does only one "fill", which will
will help on the speed.

A point about "local" variables: They're not local. If your program gets
more complex, with procedures invoking other procedures, and each saves
arguments in variables, you may find yourself having to worry about name
clashes. All of the variables get stored in the same dictionary (unless
you use a separate dict for each proc, another headache). This is also a
huge hassle if you want to write recursive procedures, as you then need
a separate dictionary for each invocation of the same procedure.

And finally, if you use variables in your procedure, and bind the
procedure, you can get into a lot of trouble when being included into
other PostScript. Another topic for a longer posting.

I recommend that you learn how to write procedures so that they need a
minimum of stack manipulation, and then avoid the variables. Your code
will be shorter and faster.

Ned Batchelder, Digital Equipment Corp., BatchelderN@Hannah.enet.DEC.com
Disclaimer: all of the code in this posting was typed off the top of my head,
but the ideas are valid.
Technical Details
Message-ID: <8260@shlump.nac.dec.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!decuac!shlump.nac.dec.com!hannah.enet.dec.com!batcheldern
References: <4017@hydra.Helsinki.FI> <17807@rpp386.cactus.org> <9002040147.AA16999@en.ecn.purdue.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!decuac!shlump.nac.dec.com!hannah.enet.dec.com!batcheldern
From: batcheldern@hannah.enet.dec.com (Ned Batchelder)
Newsgroups: comp.lang.postscript
Subject: Re: Postscript idiot needed help (and got it)
Message-ID: <8260@shlump.nac.dec.com>
Date: 9 Feb 90 21:40:12 GMT
References: <4017@hydra.Helsinki.FI> <17807@rpp386.cactus.org> <9002040147.AA16999@en.ecn.purdue.edu>
Sender: newsdaemon@shlump.nac.dec.com
Reply-To: batcheldern@hannah.enet.dec.com
Organization: Digital Equipment Corporation
Lines: 60