POV-Ray : Newsgroups : povray.beta-test : Reverse_Array Bug Server Time
30 Jul 2024 18:24:09 EDT (-0400)
  Reverse_Array Bug (Message 1 to 5 of 5)  
From: Martial
Subject: Reverse_Array Bug
Date: 29 Sep 2001 10:27:06
Message: <3bb5da3a@news.povray.org>
in array.inc
//--------------------------------------
#macro Reverse_Array(Array)
    #local J = 0;
    #local N = dimension_size(Array, 1);
    #while(J < floor(N/2))
        #local Temp = Array[J]
        #local Array[J] = Array[N-J]  //<-- subscipt out of range
        #local Array[N-J] = Temp  //<-- subscipt out of range
        #local J = J + 1;
    #end
#end

//-----REVISION-------------------------------- 

#macro Reverse_Array(Array)
    #local J = 0;
    #local N = dimension_size(Array, 1);
    #while(J < floor(N/2))
        #local Temp = Array[J]
        #local Array[J] = Array[N-J-1] //<---Correction--
        #local Array[N-J-1] = Temp //<-----Correction--
        #local J = J + 1;
    #end
#end
//--------------------------------------------------------
-- 
Martial
http://martial.rameaux.free.fr
http://www.cathemline.org


Post a reply to this message

From: Ron Parker
Subject: Re: Reverse_Array Bug
Date: 29 Sep 2001 22:23:09
Message: <slrn9rd0gg.7nr.ron.parker@fwi.com>
On Sat, 29 Sep 2001 16:24:20 +0200, Martial wrote:
>in array.inc
>//--------------------------------------
>#macro Reverse_Array(Array)
>    #local J = 0;

     #local N = dimension_size(Array, 1) - 1;  // <-- better correction

>    #while(J < floor(N/2))
>        #local Temp = Array[J]
>        #local Array[J] = Array[N-J] 
>        #local Array[N-J] = Temp 
>        #local J = J + 1;
>    #end
>#end


-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end 
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}


Post a reply to this message

From: Rune
Subject: Re: Reverse_Array Bug
Date: 30 Sep 2001 04:25:00
Message: <3bb6d6dc@news.povray.org>
"Ron Parker" wrote:
> #local N = dimension_size(Array, 1) - 1;  // <-- better correction

Nope, then you'd have to change this line too:

> >    #while(J < floor(N/2))

To this:

> >    #while(J < floor((N+1)/2))

Which doesn't seem any better to me.

Rune
--
3D images and anims, include files, tutorials and more:
Rune's World:    http://rsj.mobilixnet.dk (updated June 26)
POV-Ray Users:   http://rsj.mobilixnet.dk/povrayusers/
POV-Ray Webring: http://webring.povray.co.uk


Post a reply to this message

From: Ron Parker
Subject: Re: Reverse_Array Bug
Date: 30 Sep 2001 11:49:42
Message: <slrn9refoo.8rk.ron.parker@fwi.com>
On Sun, 30 Sep 2001 10:21:38 +0200, Rune wrote:
>"Ron Parker" wrote:
>> #local N = dimension_size(Array, 1) - 1;  // <-- better correction
>
>Nope, then you'd have to change this line too:
>
>> >    #while(J < floor(N/2))
>
>To this:

#while (J <= floor(N/2))

seems better.

--
#macro R(L P)sphere{L __}cylinder{L P __}#end#macro P(_1)union{R(z+_ z)R(-z _-z)
R(_-z*3_+z)torus{1__ clipped_by{plane{_ 0}}}translate z+_1}#end#macro S(_)9-(_1-
_)*(_1-_)#end#macro Z(_1 _ __)union{P(_)P(-_)R(y-z-1_)translate.1*_1-y*8pigment{
rgb<S(7)S(5)S(3)>}}#if(_1)Z(_1-__,_,__)#end#end Z(10x*-2,.2)camera{rotate x*90}


Post a reply to this message

From: Anders K 
Subject: Re: Reverse_Array Bug
Date: 30 Sep 2001 12:52:32
Message: <3bb74dd0@news.povray.org>
> #while (J <= floor(N/2))

Actually, I think
  #while (J < N/2)
is sufficient and even cleaner. If N is even, then the array has an odd
number of elements, and we don't need to swap the middle (N/2) element with
itself.

#macro Reverse_Array(Array)
    #local J = 0;
    #local N = dimension_size(Array, 1) - 1;
    #while(J < N/2)
        #local Temp = Array[J]
        #local Array[J] = Array[N-J]
        #local Array[N-J] = Temp
        #local J = J + 1;
    #end
#end

Anders


Post a reply to this message

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