Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1564
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!feed.xsnews.nl!border-1.ams.xsnews.nl!post-feeder-02.xsnews.nl!frontend-F09-15.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.postscript |
| Subject | Re: I like some feedback on my tetrafoil function |
| Organization | Decebal Computing |
| References | <87haf98sc1.fsf@Aspire.decebal.nl> <67f824cb-26ed-4370-b521-4848c329ab0a@googlegroups.com> |
| X-Face | "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E |
| X-Homepage | http://www.decebal.nl/ |
| Date | Fri, 02 Aug 2013 11:06:17 +0200 |
| Message-ID | <87y58k7986.fsf@Aspire.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
| Cancel-Lock | sha1:ttApF4COD3Ip9dtHqCk31nxG9Gg= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Lines | 165 |
| NNTP-Posting-Host | 77.171.42.144 |
| X-Trace | 1375434841 news.kpn.nl 2810 77.171.42.144@kpn/77.171.42.144:55696 |
| Xref | csiph.com comp.lang.postscript:1564 |
Show key headers only | View raw
Op vrijdag 2 aug 2013 05:40 CEST schreef luser:
>> I have a few questions about this.
>>
>> Is the manner I work with optional parameters the way to do it, or
>> are there better ways? (I think it the most likely I want to draw
>> the inner cross, and the least likely I want to draw the outer
>> box.)
>>
>
> I think the way you're doing it is as good as any, from the
> technical side. But from the programming side, you're encoding lots
> of power into the function, but you're not really abstracting away
> any of the details.
>
> I would tend to make a fully-general function, with all parameters
> required. And then make a few convenience functions that accept
> just a few necessary parameters. Optional parameters are just weird;
> no matter how you do it. (IMHO)
For the convenience functions I kept outerbox optional. But one
optional parameter is not to bad I think. I also made a filled
version:
% centerX centerY width outerBox innerCircle innerCross drawTetrafoil -
/drawTetrafoil {
gsave
newpath
drawTetrafoilRaw
stroke
grestore
} def
% centerX centerY width [outerBox] drawTetrafoilAll -
/drawTetrafoilAll {
dup type /booleantype ne {
false
} if
true true
drawTetrafoil
} def
% centerX centerY width [outerBox] drawTetrafoilCrossed -
/drawTetrafoilCrossed {
dup type /booleantype ne {
false
} if
false true
drawTetrafoil
} def
% centerX centerY width [outerBox] drawTetrafoilEmpty -
/drawTetrafoilEmpty {
dup type /booleantype ne {
false
} if
false false
drawTetrafoil
} def
% centerX centerY width [outerBox] drawTetrafoilFilled -
/drawTetrafoilFilled {
dup type /booleantype ne {
false
} if
false false
gsave
newpath
drawTetrafoilRaw
fill
grestore
} def
% centerX centerY width [outerBox] drawTetrafoilInnerCircle -
/drawTetrafoilInnerCircle {
dup type /booleantype ne {
false
} if
true false
drawTetrafoil
} def
% centerX centerY width outerBox innerCircle innerCross drawTetrafoilRaw -
/drawTetrafoilRaw {
10 dict begin
/innerCross exch def
/innerCircle exch def
/outerBox exch def
/width exch def
/centerY exch def
/centerX exch def
/circleRadius width 4 div def
centerX centerY translate
outerBox {
width -.5 mul dup
width dup
rectstroke
} if
innerCircle {
0 0 circleRadius 0 360 arc
stroke
} if
2 setlinejoin
4 {
innerCross {
0 0 moveto
0 circleRadius rlineto
} if
circleRadius neg circleRadius circleRadius 0 270 arc
90 rotate
} repeat
closepath
end
} def
>> Something is wrong in my function. If I call it with:
>>
>> 235 100 100 true true false drawTetrafoil
>>
>>
>>
>> The inner circle is correct at North, but in West, South and East
>> the
>>
>> inner ‘arms’ of the tetrafoil go through the inner circle. What is
>>
>> going wrong?
>>
>
> It's the mitered line join. Either use `setlinejoin` or
> `setmiterlimit`
>
> Adding
>
> 2 setlinejoin
>
> before the call, fixes the output.
Done.
>> I want to rotate the tetrafoil, but in such a way that it stays in
>> the
>>
>> outer box. What is the best way to get this done?
>>
>
> You can use `pathbbox` for this. It returns bounding-box coordinates
> for the current path in the current user space. Make sure to
> `flattenpath` first, to tighten-up against the curves (otherwise, it
> uses the outer control points from the curve segments, which you
> don't want here).
Maybe I understand you wrong, But I already know the bounding box (I
draw him). What I mean is the following: Now the first ‘leaf’ is in
the North-East corner. I want him for example also be at North. That
would be simple I think. I need to divide circleRadius by ‘2 sqrt’.
But what about the interleaving rotations?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I like some feedback on my tetrafoil function Cecil Westerhof <Cecil@decebal.nl> - 2013-08-01 15:15 +0200
Re: I like some feedback on my tetrafoil function luser- -droog <mijoryx@yahoo.com> - 2013-08-01 20:40 -0700
Re: I like some feedback on my tetrafoil function Cecil Westerhof <Cecil@decebal.nl> - 2013-08-02 11:06 +0200
Re: I like some feedback on my tetrafoil function luser- -droog <mijoryx@yahoo.com> - 2013-10-29 02:30 -0700
csiph-web