Sorry to have kept silent on this. I'm trying (slowly) to catch up with all my Perl email.
On Sun, Jun 17, 2012 at 6:21 PM, Tim Haines <[email protected]>wrote: > Hi, Chris. > > I have updated the two pnpolyfill functions as you listed below and the > documentation of all of the poly* routines to reflect the difference > between the pnpoly and the polyfill approach to determining set membership. > Before I submitted that patch, I wanted to take a stab at implementing > pnpoly in PP. Below is my first attempt. > Tim, your PP code looks good, but I have a couple of aesthetic nits. I wonder why you don't use loop %{ %} blocks? Doing so (and also denoting the code block with q{}) would lead to code like this: > pp_def('pnpoly_pp', > HandleBad => 1, > Pars => 'x(m,n); y(m,n); px(k); py(k); int [o] msk(m,n)', > Code => q{ > int a, b, i, j, c, nvert; > nvert = $SIZE(k); > > #define VERTX(q) $px(k=>q) > #define VERTY(q) $py(k=>q) > > loop (n) %{ > loop (m) %{ > c = 0; > for(i=0,j=nvert-1;i<nvert;j=i++) { > if( ((VERTY(i) > $x()) != (VERTY(j) > $y())) && > ($x() < (VERTX(j)-VERTX(i)) * > ($y()-VERTY(i)) / (VERTY(j)-VERTY(i)) + VERTX(i)) ) > c = !c; > } > $msk() = c; > %} > %} > > #undef VERTX(q) > #undef VERTY(q) > } > ); > The result should be functionally identical but more PDL-idiomatic. It also saves you a couple of #define statements. However, I quite like your use of the #define statements and may add a note about that in PDL::Book::PP. :-) Do you have a fork with this work on the web anywhere? I know, you're almost done, but if you want, you can easily fork the PDL project at github: https://github.com/PDLPorters/pdl. David -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
