POV-Ray : Newsgroups : povray.advanced-users : Vector handling : Re: Vector handling Server Time
7 Jun 2025 18:48:21 EDT (-0400)
  Re: Vector handling  
From: Bald Eagle
Date: 4 Jun 2025 06:45:00
Message: <web.6840237b2f29ff11f9dae3025979125@news.povray.org>
Long time, no see, Mr. K   :)
I hope you are personally well, and professionally successful.

Now with
https://news.povray.org/povray.general/message/%3Cweb.682bc388985098ff1f9dae3025979125%40news.povray.org%3E/#%3Cweb.682
bc388985098ff1f9dae3025979125%40news.povray.org%3E

You don't need the whole #switch block below to handle individual vector sizes.

just
#declare SV = VectorDimTest (v0);
#debug concat("<", vstr(2, SV, ", ", 0, -1), ">")

>
> #macro PrintSCalarOrVector(Dim, SV)
>
>     #switch (Dim)
>         #case (1)
>             #debug str(SV, 0, -1)
>             #break
>         #case (2)
>             #debug concat("<", vstr(2, SV, ", ", 0, -1), ">")
>             #break
>         #case (3)
>             #debug concat("<", vstr(3, SV, ", ", 0, -1), ">")
>             #break
>         #case (4)
>             #debug concat("<", vstr(4, SV, ", ", 0, -1), ">")
>             #break
>         #case (5)
>             #debug concat("<", vstr(5, SV, ", ", 0, -1), ">")
>             #break
>         #else
>             #error "Not a valid vector dimension"
>     #end // switch
>
> #end // macro PrintSCalarOrVector


Also, when I stated that i couldn't change Vector.z, I meant by directly
addressing it, like you're doing below with array elements.
I can't say #declare Vector.z = NewValue.
And the awkwardness really kicks in when I'm trying to create a macro like
#macro PermuteVector (SV)

where I just want to make any size vector on the fly and have the result of the
macro be a vector of size SV.   Because it is NOT like working with arrays.

I started off by doing
#local V = array {<1, 0, 0, 0, 0>, <0, 1, 0, 0, 0>, <0, 0, 1, 0, 0>, <0, 0, 0,
1, 0>, <0, 0, 0, 0, 1>};
#local Vector = <0, 0, 0, 0, 0>;

to "address" the individual components (in)directly, but now I'm stuck not
knowing how to take <1, 2, 3, 0, 0> and convert it to <1, 2, 3>.

I would like a simple method to MAKE vectors of an arbitrary (allowed) size,
just like vstr () PRINTS vectors of an arbitrary size.
#declare MyVector = mstr (...)

This sort of hearkens back to the epic dot notation thread where I suggested
vec.n where n = 1...5 as a valid syntax (though that still wouldn't solve the
problem, given the inability to use those as an LValue)

Making a vector from array elements requires a lot of hands-on, fussy, one-off
coding for specially constructing each individual size of vector.  POV-Ray
should be better than that.

- BW

> #macro CreateScalarOrVector(ValueArray)
>
>     #local Dim = dimension_size(ValueArray, 1);
>     #switch (Dim)
>         #case (1)
>             #local SV =
>                 ValueArray[0]
>             ;
>             #break
>         #case (2)
>             #local SV =
>                 <
>                     ValueArray[0],
>                     ValueArray[1]
>                 >
>              ;
>             #break
>         #case (3)
>             #local SV =
>                 <
>                     ValueArray[0],
>                     ValueArray[1],
>                     ValueArray[2]
>                 >
>             ;
>             #break
>         #case (4)
>             #local SV =
>                 <
>                     ValueArray[0],
>                     ValueArray[1],
>                     ValueArray[2],
>                     ValueArray[3]
>                 >
>             ;
>             #break
>         #case (5)
>             #local SV =
>                 <
>                     ValueArray[0],
>                     ValueArray[1],
>                     ValueArray[2],
>                     ValueArray[3],
>                     ValueArray[4]
>                 >
>             ;
>             #break
>         #else
>             #error "Not a valid vector dimension"
>     #end // switch
>
>     SV
>
> #end // macro CreateScalarOrVector


Post a reply to this message

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