POV-Ray : Newsgroups : povray.programming : Array pointers : Re: Array pointers Server Time
4 Oct 2024 17:06:41 EDT (-0400)
  Re: Array pointers  
From: Warp
Date: 16 Jan 2003 20:14:43
Message: <3e275903@news.povray.org>
Reusser <reu### [at] chorusnet> wrote:
> What is the most efficient (or at least
> somewhat straightforward) way to pass any array[x][y][z] into the
> function where it can be referenced like array[a][b][c] or
> array[a+1][b][c]?

  This depends on whether x and y are compiler-time constants or not.
If they are compiler-time constants, let's say for example 5 and 8, then
you can define your function like:

void Function(type array[5][8][])
{
    array[1][2][3] = 4;
}

  However, if they are not constants then there's no way which would
be at the same time simple and efficient (mostly memory-wise, perhaps
a bit speed-wise as well).
  In this case you have to decide whether you want it to be efficient in
memory usage or if you want it to be simple.
  (In fact, it's simple only from the point of view of the function; it's
not that simple from the point of view of *creating* the array.)

  I suppose that what you want is efficiency. It's not that bad from the
point of view of the syntax.
  What you have to do is to use it simply as a 1-dimensional array and
give the dimensions as separate variables, like this:

void Function(type* array, unsigned x, unsigned y)
{
    array[x*y*1+y*2+3] = 4;
}

  The memory-wise less efficient way is to use an array of pointers to
arrays of pointers to arrays.

>    (Also, why does the line, double N = 1/3; give me .333...?  Is there
> a way to accomplish this without double N = pow(3,-1);?)

  You mean it *doesn't* give that, right?

  1 is an integer. 3 is an integer. 1/3 is thus an integer division. The
result of the integer division 1/3 is 0. As it should.
  You don't want integer division. You want floating point division.
1.0 is a floating point number, as well as 3.0. 1.0/3.0 is a floating
point division.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

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