POV-Ray : Newsgroups : povray.general : a really dumb mistake Server Time
29 Apr 2024 09:10:13 EDT (-0400)
  a really dumb mistake (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From: Sven Littkowski
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 22:14:32
Message: <59828708$1@news.povray.org>
On 02.08.2017 13:35, Kenneth wrote:
> While working on my 'city buildings' scene code, I made a really simple a
nd dumb
> mistake, in a #while loop.
> 
> Consider this simplified example:
> 
> // taken from "math.inc"
> #declare even = function(x) {select(mod(x, 2), 0, 1, 0)}
> 
> #declare MY_VALUE = 10;
> 
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33; // CHANGES the value
> #else
> #end
> #debug concat("\n","My value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
> 
> 
> EXPECTED results:  I assumed MY_VALUE would *alternate* between the new v
alue of
> 33 and the old value. Wrong, of course.
> 
> ACTUAL results: After the first while-loop iteration, MY_VALUE changes to
 33--
> and remains at the new value. Because, once it's changed, there's nothing
 to
> change it back to 10! It's so obvious now.
> 
> But I spent several *days* trying to track down this subtle mistake(!!)--

> because, my code was so complex that I was looking for an equally complex
 reason
> for the 'unexpected' results, having nothing to do with the #while loop a
t all
> :-/  Like, perhaps the even() function wasn't working correctly! And half
 a
> dozen other reasons.
> 
> No matter how smart you *think* you are, there will always be something t
o come
> along and humble you.
> 
> But all is well now...  :-P
> 
> ---------------------------------
> (The proper way to do it):
> #declare MY_VALUE = 10;
> 
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33;
> #else
> #declare MY_VALUE = 10;
> #end
> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
> 
> 
> 
I know there someone, who uses POV-Ray since 1989 or so. And for two
weeks, this poor little fellow wondered, why his renders did not show
any expected bumps on the surface of an item. This poor little fellow
even managed to keep the POV-Ray community heavily occupied for these
two weeks with his strange problem. Over 60 postings were meade.

Finally, it turned out, that this little poor fellow forgot to chage his
QUALITY settings above 6.

I was that guy...    :-D

We all fail, at times, while at other times, POV-Ray makes us big and
making us doing great things.

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: omniverse
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 22:40:01
Message: <web.59828cc1d9dfcaae9c5d6c810@news.povray.org>
Sven Littkowski <I### [at] SvenLittkowskiname> wrote:
> On 02.08.2017 13:35, Kenneth wrote:
> >
> > No matter how smart you *think* you are, there will always be something t
> o come
> > along and humble you.
>
> We all fail, at times, while at other times, POV-Ray makes us big and
> making us doing great things.

I'm mostly humbled by POV-Ray. Just about everything is a challenge, or struggle
depending on how humbled I get!

Good going on the city macro Kenneth. And the space balloon Sven (I will
remember that mistake a very long time!).


Post a reply to this message

From: clipka
Subject: Re: a really dumb mistake
Date: 21 Aug 2017 12:01:06
Message: <599b03c2$1@news.povray.org>
Am 02.08.2017 um 21:07 schrieb Bald Eagle:
> "Kenneth" <kdw### [at] gmailcom> wrote:
> 
>> ---------------------------------
>> (The proper way to do it):
>> #declare MY_VALUE = 10;
>>
>> #declare C = 1;
>> #while(C < 20)
>> #if(even(C))
>> #declare MY_VALUE = 33;
>> #else
>> #declare MY_VALUE = 10;
>> #end
>> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>> #declare C = C + 1;
>> #end
> 
> (The more efficient way to do it):
> 
> 
>  #declare C = 1;
>  #while(C < 20)
>  #declare MY_VALUE = 10;
>     #if(even(C))
>        #declare MY_VALUE = 33;
>     #end
>  #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>  #declare C = C + 1;
>  #end

Challenge accepted ;)

#declare MY_VALUE = 10;
#for(C,1,19)
  #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
  #declare MY_VALUE = 43-MY_VALUE;
#end


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 21 Aug 2017 12:20:01
Message: <web.599b07cbd9dfcaaec437ac910@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Challenge accepted ;)
>
> #declare MY_VALUE = 10;
> #for(C,1,19)
>   #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>   #declare MY_VALUE = 43-MY_VALUE;
> #end

I will have to check this out to see what it does - it looks fiendishly clever.
(someone's hogging my workbench at the moment)

(BTW - we love it when you show off.  ;) )

.... and things like this virtually scream for another POV-Ray short-code contest
..... :O


Post a reply to this message

From: Kenneth
Subject: Re: a really dumb mistake
Date: 25 Aug 2017 13:40:05
Message: <web.59a06050d9dfcaae883fb31c0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> clipka <ano### [at] anonymousorg> wrote:
>
> > Challenge accepted ;)
> >
> > #declare MY_VALUE = 10;
> > #for(C,1,19)
> >   #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> >   #declare MY_VALUE = 43-MY_VALUE;
> > #end
>
> I will have to check this out to see what it does...
>

Same here! At first appearance, it doesn't seem like it would work at all. But
it DOES work! Yes, devilishly clever.

Hmm, let's see...

1) MY_VALUE starts at 10
2) 1st #debug = 10
3) MY_VALUE changes to (43 - 10) = 33
4) 2nd #debug = 33
5) MY_VALUE changes to (43 - 33) = 10
6) 3rd #debug = 10
7) MY_VALUE changes to (43 - 10) = 33
8) 4th #debug = 33

....ETC...

Magical!


Post a reply to this message

From: Kenneth
Subject: Re: a really dumb mistake
Date: 25 Aug 2017 13:50:06
Message: <web.59a0629fd9dfcaae883fb31c0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

>
> Magical!
>

In the 16th century, the Inquisition would have burned Clipka at the stake, as a
warning to other such Necromancers :-P


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 25 Aug 2017 15:10:00
Message: <web.59a07598d9dfcaaec437ac910@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> In the 16th century, the Inquisition would have burned Clipka at the stake, as a
> warning to other such Necromancers :-P

21st.   Other than that, you're probably right.
Orwell just had the date wrong.

https://campus.aynrand.org/works/1943/01/01/the-soul-of-an-individualist/page1

https://duanegraham.files.wordpress.com/2012/07/s-e-cupp-rand-quote.jpg


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 11 Sep 2017 10:40:01
Message: <web.59b69f36d9dfcaaec437ac910@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Challenge accepted ;)
>
> #declare MY_VALUE = 10;
> #for(C,1,19)
>   #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>   #declare MY_VALUE = 43-MY_VALUE;
> #end

So, I looked further into this, since it was so elegant,
and I came across this discussion, and further suggested improvement:


from:
https://stackoverflow.com/questions/18941019/simplest-way-to-toggle-a-integer-variable-between-two-values
( ^= operator is the XOR operator)


"Another way is to toggle an index between 0 and 1 and index an array with that:

int main() {
    int const values[] = {0x55, 0xaa};
    int selector = 0;

    selector ^= 1;                // toggle index
    int value = values[selector]; // select value
}

This is also future-resistant. If in the future OP wants to round-robin between
3, 4, or N values, just add to the array and change selector ^= 1 to selector =
(selector+1)%N."

------

I'm unfamiliar with the bitwise operators in POV-Ray, so interpreting the docs
is a bit unclear to me.
"bitwise_xor(A,B,...)
Bitwise XOR of two or more float values considered as integers."

This would make a sweet little macro for people to use in lots of future scene
files - so good, it should be in one of the standard include files.

I might try to code it up tonight, unless someone beats me to it   ;)


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 11 Sep 2017 13:50:05
Message: <web.59b6cc01d9dfcaaec437ac910@news.povray.org>
> I might try to code it up tonight, unless someone beats me to it   ;)

or over lunch  :D

Like so:

#macro CycleValues (_Array, _Counter)
 // Round-robin cycle through N values
 // Bill Walker September 2017
 #local N = dimension_size (_Array, 1);
 #local selector = mod (_Counter, N);
 // selector will range from 0 to N-1
 // Return the value in _Array corresponding to _Counter
 _Array [selector]
#end // end macro CycleValues


#declare RoundRobin = array [4] {2, 5, 9, 13};
#for (i, 0, 10)
 #declare Value = CycleValues (RoundRobin, i);
 #debug concat ("Array value for i=", str(i, 2, 0), " is ", str(Value, 3, 0),
"\n")
#end // end for i


Post a reply to this message

From: clipka
Subject: Re: a really dumb mistake
Date: 11 Sep 2017 17:18:00
Message: <59b6fd88$1@news.povray.org>
Am 11.09.2017 um 19:46 schrieb Bald Eagle:
> 
>> I might try to code it up tonight, unless someone beats me to it   ;)
> 
> or over lunch  :D
> 
> Like so:
> 
> #macro CycleValues (_Array, _Counter)
>  // Round-robin cycle through N values
>  // Bill Walker September 2017
>  #local N = dimension_size (_Array, 1);
>  #local selector = mod (_Counter, N);
>  // selector will range from 0 to N-1
>  // Return the value in _Array corresponding to _Counter
>  _Array [selector]
> #end // end macro CycleValues
> 
> 
> #declare RoundRobin = array [4] {2, 5, 9, 13};
> #for (i, 0, 10)
>  #declare Value = CycleValues (RoundRobin, i);
>  #debug concat ("Array value for i=", str(i, 2, 0), " is ", str(Value, 3, 0),
> "\n")
> #end // end for i

Invoking a macro in a loop? Can't imagine this to be of any use in terms
of efficiency ;)


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.