![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"[GDS|Entropy]" <gds### [at] hotmail com> wrote:
> Is this the best I can hope for? Is there some other way to detect the
> populated length of an array? dimension_size is *useless*. Might it be that
> I am forced to form the array within the loop which uses it? That would
> suck...not very OO...but then SDL isn't very OO to start with, ironically..
Prepared to give yourself a big slap on the head?
Try this (*ta-daaah*):
-------------------------
#ifdef (myArray[i]) ...
-------------------------
So a fail-safe code to loop through an array would look something like this:
#declare i=0;
#while (i < dimension_size(myArray,1))
#ifdef (myArray[i])
#debug concat("[", str(i,0,0), "]=", str(myArray[i],0,0), "\n")
#declare i=i+1;
#else
#debug concat("[", str(i,0,0), "] undefined\n")
#declare i=dimension_size(myArray,1); // force exiting of the loop
#end
#end
(unfortunately, POV doesn't have a break statement for loops (its #break
statement is only of use in #switch statements), nor does it "short-circuit"
its & operator so #while (i < dimension_size(myArray,1) & defined(myArray[i]))
will not work properly, hence the comparatively ugly way of terminating the
loop)
Or, if your list may contain "holes":
#declare i=0;
#while (i < dimension_size(myArray,1))
#ifdef (myArray[i])
#debug concat("[", str(i,0,0), "]=", str(myArray[i],0,0), "\n")
#else
#debug concat("[", str(i,0,0), "] undefined\n")
#end
#declare i=i+1;
#end
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"[GDS|Entropy]" <gds### [at] hotmail com> wrote in message
news:49a3abc7@news.povray.org...
> Because the array is declared outside of the macro which populates it, to
> facilitate its passing to other macros as a variable, so always returns
> whatever you defined its length to be, regardless if it has been populated
> with that many values.
>
> Pov doesn't support redimensioning, does it?
>
Just to make sure I understand you correctly: You define an array that is,
say 5000 elements long. You then call a macro to populate some elements of
that array, but there are gaps. You then need a second macro to loop through
the array, ignoring any unassigned elements?
If that's right, you just need to use #ifdef to see if an element of the
array has been assigned before you use it.
If by 'redimensioning' you mean just scrunching up the gaps, then you can do
that very simply in a loop using #ifdef on an array element. If it exists
move it to the current 'write' point in the array. Plus you can count the
actual number of elements uses as you go.
#local I = 0;
#declare NewSize = 0;
#while (I<dimension_size(MyArray,1))
#ifdef(MyArray[I])
#declare MyArray[NewSize] = MyArray[I];
#declare NewSize = NewSize+1;
#end
#local I=I+1;
#end
Untested code Warning! I didn't run this, so it may contain syntax errors
etc.
Regards,
Chris B.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thanks guys!
That #ifdef took care of the issue. I should have remembered that, its part
of C lol! :-D
Tim: I wasn't able to get your macro to work (though looking at it while I'm
typing, it looks like the c=c+1 should come after the c2=c2+1? Am I right?).
I'll play with it a bit later, but that is pretty close to the redim I was
referring to.
I hadn't even considered an array with holes, which is something I should
look out for, but I think in the context of this specific problem that
wasn't happening.
At least I have the solution for that too now. :-D
I appreciate everyones help!
ian
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"[GDS|Entropy]" <gds### [at] hotmail com> wrote:
> Thanks guys!
> That #ifdef took care of the issue. I should have remembered that, its part
> of C lol! :-D
Just an extra thought - couldn't you globally #declare your array size when you
populate it, then use this value in the second macro? Unless I've misunderstood
your first post...
Bill
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Tim Attwood wrote:
> #macro resize_array(ar)
> ...
> #declare ar = new_ar;
> #end
>
> resize_array(MyArray)
Interesting. I didn't know macro parameters got by-reference
semantics when an identifier was passed instead of an RVALUE.
I think I'd prefer to assign the value using #local, though,
to make it clear no global variable "ar" is involved.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
I had a version which did this, but I could only summon it once, as any
subsequent incarnations redefined the contents upon each call.
ian
"Bill Pragnell" <bil### [at] hotmail com> wrote in message
news:web.49a3d5fe78dc09ae6dd25f0b0@news.povray.org...
> "[GDS|Entropy]" <gds### [at] hotmail com> wrote:
>> Thanks guys!
>> That #ifdef took care of the issue. I should have remembered that, its
>> part
>> of C lol! :-D
>
> Just an extra thought - couldn't you globally #declare your array size
> when you
> populate it, then use this value in the second macro? Unless I've
> misunderstood
> your first post...
>
> Bill
>
>
>
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> "Bill Pragnell" <bil### [at] hotmail com> wrote in message
> > Just an extra thought - couldn't you globally #declare your array size
> > when you
> > populate it, then use this value in the second macro?
"[GDS|Entropy]" <gds### [at] hotmail com> wrote:
> I had a version which did this, but I could only summon it once, as any
> subsequent incarnations redefined the contents upon each call.
I'm not sure I understand the problem... based on the first paragraph of your
original post, if you keep track of the number of array elements in the first
macro and #declare an array_size variable (not #local), then this number will
be available for all subsequent code, just like the array, and you will know how
many elements to loop through. If you call the same macro again, it will simply
redefine this counter to reflect the new array contents... is this not what you
want to do?
I've got the vague feeling that I'm missing something, as this seems too easy a
solution compared with other replies! :-)
Bill
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"Bill Pragnell" <bil### [at] hotmail com> wrote:
> > > Just an extra thought - couldn't you globally #declare your array size
> > > when you populate it, then use this value in the second macro?
>
> "[GDS|Entropy]" <gds### [at] hotmail com> wrote:
> > I had a version which did this, but I could only summon it once, as any
> > subsequent incarnations redefined the contents upon each call.
>
> I'm not sure I understand the problem... based on the first paragraph of your
> original post, if you keep track of the number of array elements in the first
> macro and #declare an array_size variable (not #local), then this number will
> be available for all subsequent code, just like the array, and you will know how
> many elements to loop through. If you call the same macro again, it will simply
> redefine this counter to reflect the new array contents... is this not what you
> want to do?
>
> I've got the vague feeling that I'm missing something, as this seems too easy a
> solution compared with other replies! :-)
Souns to me that he wants to use the same pair of macros over and over again and
therefore a single "global variable" to hold the array size wouldn't be enough.
I think testing for #ifdef(myArray[i]) is quite an elegant solution for the
problem: You just need the array, nothing more. "Global thinking" may be easier
for a quick hack, but is usually not so elegant in the long run. It's often an
obstacle when you want to turn code into a re-usable macro.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"clipka" <nomail@nomail> wrote:
> I think testing for #ifdef(myArray[i]) is quite an elegant solution for the
> problem: You just need the array, nothing more. "Global thinking" may be easier
> for a quick hack, but is usually not so elegant in the long run. It's often an
> obstacle when you want to turn code into a re-usable macro.
Oh yes, I'm with you there. It's definitely a dirty trick, I'm just curious to
know why it mightn't work.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Well at this point there are no longer any issues with the multiple
summoning of arrays as defined in previous macros, as the following example
shows:
// randVectorMM Macro by [GDS|Entropy]
//------
#macro randVectorMM(Array,ctr,RsA,Min,Max,Method,Object)
#local vectorA = min_extent(Object);
#local vectorB = max_extent(Object);
#local i=0;
#while (i<ctr)
#switch (Method)
#case (0)
#declare Array[i] = <RRand(RsA, Min+vectorA.x, Max+vectorB.x),RRand(RsA,
Min+vectorA.y, Max+vectorB.y),RRand(RsA, Min+vectorA.z, Max+vectorB.z)>;
#break
#case (1)
#declare Array[i] = <sin(RRand(RsA, Min+vectorA.x,
Max+vectorB.x)),RRand(RsA, Min+vectorA.y, Max+vectorB.y),tan(RRand(RsA,
Min+vectorA.z, Max+vectorB.z))>;
#break
#case (2)
#declare Array[i] = <sin(RRand(RsA, Min+vectorA.x,
Max+vectorB.x)),atanh(RRand(RsA, Min+vectorA.y,
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
#break
#case (3)
#declare Array[i] = <asin(RRand(RsA, Min+vectorA.x,
Max+vectorB.x)),atanh(RRand(RsA, Min+vectorA.y,
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
#break
#case (4)
#declare Array[i] = <acosh(RRand(RsA, Min+vectorA.x,
Max+vectorB.x)),asinh(RRand(RsA, Min+vectorA.y,
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
#break
#case (5)
#declare Array[i] = <cos(i+RRand(RsA, Min+vectorA.x,
Max+vectorB.x)),i+RRand(RsA, Min+vectorA.y, Max+vectorB.y),sin(i+RRand(RsA,
Min+vectorA.z, Max+vectorB.z))>;
#break
#end
#set i=i+1;
#end
#end
//surrounding macro excised before and after the following snippet
#declare sRandVectArray = array [snowCounter];
randVectorMM(sRandVectArray,snowCounter,seed(3141592654),-sFudgeFactor,sFudgeFactor,sMethod,testObject)
//------
I could go so far as to define get/set macros for everything, but in this
case, I think that would be going a little far. :p
SDL gets easier and easier for me as I continue to learn tricks that make it
behave like other C based languages.
There was an example file by Jean-Charles Marteau regarding Object Oriented
POV code that I have, and can't seem to locate the download location for
that did a pretty good job of this.
I can post the zip to p.b.i if anyone is interested.
ian
"Bill Pragnell" <bil### [at] hotmail com> wrote in message
news:web.49a50c3678dc09ae6dd25f0b0@news.povray.org...
>> "Bill Pragnell" <bil### [at] hotmail com> wrote in message
>> > Just an extra thought - couldn't you globally #declare your array size
>> > when you
>> > populate it, then use this value in the second macro?
>
> "[GDS|Entropy]" <gds### [at] hotmail com> wrote:
>> I had a version which did this, but I could only summon it once, as any
>> subsequent incarnations redefined the contents upon each call.
>
> I'm not sure I understand the problem... based on the first paragraph of
> your
> original post, if you keep track of the number of array elements in the
> first
> macro and #declare an array_size variable (not #local), then this number
> will
> be available for all subsequent code, just like the array, and you will
> know how
> many elements to loop through. If you call the same macro again, it will
> simply
> redefine this counter to reflect the new array contents... is this not
> what you
> want to do?
>
> I've got the vague feeling that I'm missing something, as this seems too
> easy a
> solution compared with other replies! :-)
>
> Bill
>
>
>
>
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |