POV-Ray : Newsgroups : povray.general : Github repository with useful macros : Re: Github repository with useful macros Server Time
1 May 2024 18:20:36 EDT (-0400)
  Re: Github repository with useful macros  
From: William F Pokorny
Date: 21 May 2021 04:17:48
Message: <60a76cac$1@news.povray.org>
On 5/20/21 2:24 PM, Tor Olav Kristensen wrote:
> Try this:
> 
> #declare SomeVectors2D =
>      array[5] {
>          < 1,  5>,
>          <-2, -2>,
>          < 6,  3>,
>          < 0,  2>,
>          < 3, -1>
>      }
> ;
> #declare vMean2D = Mean(SomeVectors2D);

Ah, OK! I was thinking only in terms of sets of floats. Still arrays, 
but arrays of vectors.

---
With the introduction of mixed arrays in v3.8, I guess, so long as we 
are willing to work in terms of the largest defined vector and take the 
unspecified components of shorter vectors as being zero, things will 
work out.

There is an exposure if someone drops in a float in the wrong place. We 
get two different answers with a set up like the following where the 
Mean of the SomeVectorsA is OK if you take the float as being promoted 
to a 4 component vector, but that of SomeVectorsB is not because at the 
time of the addition the parser doesn't know the max vector size in the 
mixed array is four.

#declare SomeVectorsA =
     array mixed[5] {
         < 1,  5>,
         <-2, -2, 0, -1>,
         < 6,  3>,
         < 0,  2, 0, +2>,
         0.123
     }
#declare SomeVectorsB =
     array mixed[5] {
         0.123
         < 1,  5>,
         <-2, -2, 0, -1>,
         < 6,  3>,
         < 0,  2, 0, +2>,
     }
...
Mean <1.0246,1.6246,0.0246,0.2246,0.0000> SomeVectorsA
Mean <1.0246,1.6246,0.0000,0.2000,0.0000> SomeVectorsB

Would it be enough to recommend against mixed array usage? Or might we 
test for mixed arrays in some way and stop, though, I have no idea how 
to do such a thing at the moment.

Aside 1: If someone drops a non-numeric thing into a mixed array the 
parser appropriately generates an error.

Aside 2: If someone uses color the length always goes to the full five 
color component vector. It's possible with colors to mix lengths of 
vector specification - even in the traditional non-mixed array case.

     rgb 1,           // promoted to 1,1,1,0,0
     color 1,         // warning. promoted to 1,1,1,1,1
     rgb< 0,  2>,     // promoted to five components. Trailing 0s
     rgb< 3, -1, 1>   // Same
     rgb< 1, 2, 3, 4> // Warning and 4th component used. 5th 0.
     rgbf<1, 2, 3, 4> // 4th used, no warning. 5th 0.

Maybe behavior all just what it is - user beware?

Bill P.


Post a reply to this message

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