POV-Ray : Newsgroups : povray.general : Algorithm issues: what is better? Server Time
17 Nov 2024 11:10:45 EST (-0500)
  Algorithm issues: what is better? (Message 1 to 5 of 5)  
From: Tim Nikias v2 0
Subject: Algorithm issues: what is better?
Date: 24 Mar 2003 16:15:04
Message: <3e7f7558@news.povray.org>
I've set a macro to move across an array. Since it
has to derive where to begin calculating, it must always
begin with the first element, but then may jump across
certain sections, and end before it reaches the end of
the array.
Problem is: it would always calculate the first element
this way, which might not be wanted.
In order to solve this, I've decided the following:
since the x and y part of the vector saved in the array
defines where to jump next in the 2D-Array, I just add
the dimension-size of the x-dimension to the movement-
value of x. Thus, I have means of checking if the array
would (theoretically) exceed its size, and using mod()
I can easily revert the process.

But what would be better implementation-wise:
Checking with #if, if the value of x is too large, and
apply mod() if needed (can only happen on the initial
element, so I could combine the #if with checking if
the macro is to access the first element), or by applying
mod anyway? At this point, the macro doesn't decide
anything, it just needs to derive which point it has to
jump to next.

I'd think applying mod() every time would be better than
always calculating an #if statement, and applying the
mod() if needed, but perhaps someone has better insight?

If anyone doesn't understand what I'm doing, perhaps this
suffices:
Is it better to apply mod() in every step, or use an #if in every
step in order to know if mod() should be applied? What is less
costly parsing-wise?

--
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights
Email: Tim### [at] gmxde


Post a reply to this message

From: Slime
Subject: Re: Algorithm issues: what is better?
Date: 24 Mar 2003 16:41:31
Message: <3e7f7b8b$1@news.povray.org>
> Is it better to apply mod() in every step, or use an #if in every
> step in order to know if mod() should be applied? What is less
> costly parsing-wise?

It probably depends on the complexity of the if() condition, the complexity
of the mod()-related function, and and probability of the if() condition
being true.

if the if() condition is less complex than the mod()-related function, and
the probability of the if() condition being true is low, then use the if().

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Algorithm issues: what is better?
Date: 24 Mar 2003 16:52:55
Message: <3e7f7e37$1@news.povray.org>
Thanks for the reply.
Well, then it seems applying mod() directly is better:

#local _D=_DatSet[_X][_Z];
#declare _X=_X+mod(_D.u,dimension_size(_DatSet,1));
#declare _Z=_Z+_D.v;

vs

#if (_DatSet[_X][_Z].u>=dimension_size(_DatSet,1))
 #local
_D=_DatSet[_X][_Z]*v+mod(_DatSet[_X][_Z].u,dimension_size(_DatSet,1))*u;
#else
 #local _D=_DatSet[_X][_Z];
#end
#declare _X=_X+_D.u;
#declare _Z=_Z+_D.v;


I know, some stuff could be simplified (like getting the dimension_size
into its own variable instead of calling it several times), but the always
applied mod() looks cleaner. Is it more work to process the mod() in this
case, or the #if? Or, in this case, is it just not worth mentioning? I'm not
so sure if POV is faster at boolean logic or if the mod() is faster, and if
the amount of processing required for the #if statement in itself is
actually
more complex than just the mod()...

--
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights
Email: Tim### [at] gmxde

"Slime" wrote:

> > Is it better to apply mod() in every step, or use an #if in every
> > step in order to know if mod() should be applied? What is less
> > costly parsing-wise?
>
> It probably depends on the complexity of the if() condition, the
complexity
> of the mod()-related function, and and probability of the if() condition
> being true.
>
> if the if() condition is less complex than the mod()-related function, and
> the probability of the if() condition being true is low, then use the
if().
>
>  - Slime
> [ http://www.slimeland.com/ ]
>
>


Post a reply to this message

From: Slime
Subject: Re: Algorithm issues: what is better?
Date: 24 Mar 2003 17:41:31
Message: <3e7f899b@news.povray.org>
Eh, just use the mod(). Honestly, I doubt the difference will be noticeable.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Algorithm issues: what is better?
Date: 24 Mar 2003 17:52:38
Message: <3e7f8c36@news.povray.org>
In this case, you're right. But since this might pop up more often
during the coding, I wanted to make sure. And it will make a difference
if the array involved is VERY large and A LOT of algorithms have to
pass it over and over again...

Thanks for the help!

Tim

--
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights
Email: Tim### [at] gmxde
"Slime" commented:

> Eh, just use the mod(). Honestly, I doubt the difference will be
noticeable.
>
>  - Slime
> [ http://www.slimeland.com/ ]
>
>


Post a reply to this message

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