POV-Ray : Newsgroups : povray.advanced-users : Directly accessing array value in array of arrays (Part 2) Server Time
28 Mar 2024 08:46:49 EDT (-0400)
   Directly accessing array value in array of arrays (Part 2) (Message 1 to 6 of 6)  
From: Bald Eagle
Subject: Directly accessing array value in array of arrays (Part 2)
Date: 26 Aug 2018 19:25:00
Message: <web.5b83362ac09bb9a8458c7afe0@news.povray.org>
I tracked down my old thread, but no help.

http://news.povray.org/povray.advanced-users/thread/%3Cweb.58e6aa331b66056880403a200%40news.povray.org%3E/

I have a 2D array, and I want to have that array be a collection of other 2D
arrays.

Is that allowed?

How do I access, or more importantly assign, uninitialized "internal" 2D array
elements?

#declare Array1 = array [4][4];

#declare Array2 = array [4][4];

Partially fill Array 2 with some values.

#declare Array1 [2][3] = Array2;

So far so good - but now I need to get to the "array formerly known as Array2 ",
element [0][2] which is INSIDE of Array1 [2][3]

#declare Array1[2][3][0][2] = somevalue makes the POV-Ray parser cry.

I'm none to happy about it either.

Advice?  Solution(s)?


Post a reply to this message

From: jr
Subject: Re: Directly accessing array value in array of arrays (Part 2)
Date: 27 Aug 2018 04:45:00
Message: <web.5b83b8fba75a4bf71500b2fd0@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
>
> #declare Array1 = array [4][4];
>
> #declare Array2 = array [4][4];
>
> Partially fill Array 2 with some values.
>
> #declare Array1 [2][3] = Array2;
>
> So far so good - but now I need to get to the "array formerly known as Array2 ",
> element [0][2] which is INSIDE of Array1 [2][3]
>
> #declare Array1[2][3][0][2] = somevalue makes the POV-Ray parser cry.
>
> I'm none to happy about it either.
>
> Advice?  Solution(s)?


assign Array1[2][3] to a variable, then access that like the array.  given the
above and the four elements of Array2[1][?] set to some value, the following
works for me:

#declare TA = Array1[2][3];

#debug concat("TA 1 2", str(TA[1][2], 0, 0), "\n")

hth.


regards, jr.


Post a reply to this message

From: clipka
Subject: Re: Directly accessing array value in array of arrays (Part 2)
Date: 27 Aug 2018 05:56:48
Message: <5b83cae0$1@news.povray.org>
Am 27.08.2018 um 01:22 schrieb Bald Eagle:
> I tracked down my old thread, but no help.
> 
>
http://news.povray.org/povray.advanced-users/thread/%3Cweb.58e6aa331b66056880403a200%40news.povray.org%3E/
> 
> I have a 2D array, and I want to have that array be a collection of other 2D
> arrays.
> 
> Is that allowed?

Yes, absolutely - although I've heard rumors that /someone/ just
discovered a bug that may cause a crash instead of a parse error if
arrays of arrays are used and mistakes are made ;)

> How do I access, or more importantly assign, uninitialized "internal" 2D array
> elements?
> 
> #declare Array1 = array [4][4];
> 
> #declare Array2 = array [4][4];
> 
> Partially fill Array 2 with some values.
> 
> #declare Array1 [2][3] = Array2;

Perfectly fine there.

As a side note, it might be worth mentioning that `Array1[2][3]` now
holds a /copy/ of `Array2`, not a reference.

> So far so good - but now I need to get to the "array formerly known as Array2 ",
> element [0][2] which is INSIDE of Array1 [2][3]
> 
> #declare Array1[2][3][0][2] = somevalue makes the POV-Ray parser cry.

I doubt that's what you're actually seeing, because that exact construct
works perfectly fine here.


Post a reply to this message

From: jr
Subject: Re: Directly accessing array value in array of arrays (Part 2)
Date: 27 Aug 2018 06:35:00
Message: <web.5b83d31ea4088b311500b2fd0@news.povray.org>
hi,

clipka <ano### [at] anonymousorg> wrote:
> As a side note, it might be worth mentioning that `Array1[2][3]` now
> holds a /copy/ of `Array2`, not a reference.

prompted me to (quick) try arrays with different dimensions contained in Array1
and found I can access all values directly through Array1, irrespective of the
number of dims.  neat + convenient.  thank you.


regards, jr.


Post a reply to this message

From: jr
Subject: Re: Directly accessing array value in array of arrays (Part 2)
Date: 27 Aug 2018 07:25:00
Message: <web.5b83dee3a4088b311500b2fd0@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > As a side note, it might be worth mentioning that `Array1[2][3]` now
> > holds a /copy/ of `Array2`, not a reference.

I love that this works too:

<----- snip ----->
#version 3.8;

global_settings {assumed_gamma 1}

#declare Aa = array[1][1][1][1][2];

#declare Ab = array[2][2][2][2][2];
#declare Ab[0][0][0][0][1] = 255;

#declare Aa[0][0][0][0][1] = Ab;

#debug concat("0 0 0 0 1 - 0 0 0 0 1 : ",
        str(Aa[0][0][0][0][1][0][0][0][0][1],0,0),
        ".\n")
<----- snip ----->

very neat.  :-)


Post a reply to this message

From: clipka
Subject: Re: Directly accessing array value in array of arrays (Part 2)
Date: 27 Aug 2018 09:42:38
Message: <5b83ffce$1@news.povray.org>
Am 27.08.2018 um 13:22 schrieb jr:
> "jr" <cre### [at] gmailcom> wrote:
>> clipka <ano### [at] anonymousorg> wrote:
>>> As a side note, it might be worth mentioning that `Array1[2][3]` now
>>> holds a /copy/ of `Array2`, not a reference.
> 
> I love that this works too:
> 
> <----- snip ----->
> #version 3.8;
> 
> global_settings {assumed_gamma 1}
> 
> #declare Aa = array[1][1][1][1][2];
> 
> #declare Ab = array[2][2][2][2][2];
> #declare Ab[0][0][0][0][1] = 255;
> 
> #declare Aa[0][0][0][0][1] = Ab;
> 
> #debug concat("0 0 0 0 1 - 0 0 0 0 1 : ",
>         str(Aa[0][0][0][0][1][0][0][0][0][1],0,0),
>         ".\n")
> <----- snip ----->
> 
> very neat.  :-)

I /think/ you're overdoing it a bit ;)


Post a reply to this message

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