|
 |
I had occasion to revisit this, as I wanted to determine the "size" of a vector,
because having separate macros to compare vectors is ridiculous.
The way that POV-Ray promotes vectors and does scalar+vector addition seemed to
frustrate things. But since the parser "knows" things about the values that
we're using, I was wondering if I could use some of that occult knowledge and
somehow distinguish between scalar and vector values.
trying to write efficient code led me to discover that you can write rgb 3
but if I: store 3 in an array and then try to write rgb Array[0]
or try rgbf, rgbt, or rgbft 3
I get: "Parse Error: Attempted to redfine float identifier as colour
identifier."
But we CAN write rgb 3, which gets promoted to <3, 3, 3, 0, 0>
Whereas actual vectors just get padded with zeros, unless it's a 5D vector.
So we can check if rgb v0 has x=y=z, and also check if
the transmit value of rgb v0 = v0 + <0, 0, 0, 0, 0>
Because if v0 is non-zero, then the former will be 0, and the latter will be v0.
Perhaps there is more that we can do in the same vein.
Developmental scene is attached.
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmail com> wrote:
> #macro VectorDimTest(v0)
>
> #local vZ3D = <0, 0, 0>;
> #local vZ4D = <0, 0, 0, 0>;
> #local vZ5D = <0, 0, 0, 0, 0>;
> #local v1 = v0 + 1;
> #local v2 = v0 + 2;
> #local D2 = ((vZ3D + v1).z = (vZ3D + v2).z);
> #local D3 = ((vZ4D + v1).t = (vZ4D + v2).t);
> #local D4 = ((vZ5D + v1).transmit = (vZ5D + v2).transmit);
>
> #if (D2)
> #debug "2D"
> #else
> #if (D3)
> #debug "3D"
> #else
> #if (D4)
> #debug "4D"
> #else
> #debug "5D or scalar"
> #end // if
> #end // if
> #end // if
>
> #end // VectorDimTest
//#declare Vector = array mixed {pi, <1, 2>, <1, 2, 3>, <1, 2, 3, 4>, <1, 2, 3,
4, 5>}
//#declare Vector = array mixed {rgb pi, rgb <1, 2>, rgb <1, 2, 3>, rgb<1, 2, 3,
4>, rgb <1, 2, 3, 4, 5>}
#declare Vector = array mixed {
rgb pi, rgb pi + 1, rgb pi + 2,
rgb <1, 2>, rgb <1, 2>+1, rgb <1, 2>+2,
rgb <1, 2, 3>, rgb <1, 2, 3>+1, rgb <1, 2, 3>+2,
rgb<1, 2, 3, 4>, rgb<1, 2, 3, 4>+1, rgb<1, 2, 3, 4>+2,
rgb <1, 2, 3, 4, 5>, rgb <1, 2, 3, 4, 5>+1, rgb <1, 2, 3, 4, 5>+2
}
//#declare Vector = array mixed {<0, 0>+1, <0, 0>+2, <0, 0, 0>+1, <0, 0, 0>+2,
<0, 0, 0, 0>+1, <0, 0, 0, 0>+2, <0, 0, 0, 0, 0>+1, <0, 0, 0, 0, 0>+2}
#declare VN = dimension_size (Vector, 1)-1;
#for (V, 0, VN)
//#debug concat ("Vector = <", vstr(1+ceil((V+1)/2), Vector [V], ", ", 0, 0),
"> ")
#debug concat ("Vector = <", vstr(5, Vector [V], ", ", 0, 0), "> ")
VectorDimTest(Vector [V])
#debug "\n"
#if (mod(V+1,3)=0)
#debug "\n"
#end
#end
#debug "\n"
#debug "\n"
#debug "\n"
Post a reply to this message
Attachments:
Download 'vectoroperations.pov.txt' (3 KB)
|
 |