POV-Ray : Newsgroups : povray.beta-test : Reverse_Array Bug : Re: Reverse_Array Bug Server Time
4 Nov 2024 13:43:38 EST (-0500)
  Re: Reverse_Array Bug  
From: Anders K 
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.