 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In light of the fact that I was able to solve the scalar / vector typing
problem, I wanted to do a test of the macro with a full complement of vectors
that are composed of all permutations of negative, zero, and positive values, so
that I can test anything that might trigger some edge case and cause the macro
to fail and misidentify an argument.
To do that, I wrote a macro to generate all of the permutations for any given
vector size, however it quickly became apparent that actually outputting vectors
of any given size is a challenge.
There's no way to really assign a value to the individual vector component
Vector.z, so I'm coming up against an interesting limitation of SDL. It's not a
trivial task to take an array of values and convert it to a vector.
Nor can I (that I know) diminish the size of a vector from 5 to 3.
(Can we have 1-component vectors?)
I don't want to use ParseString () to generate 4,000 vectors.
I also don't want to individually verify every test case, so I'll probably make
the output of the macro a scalar/vector plus the type (1, 2, 3, 4, 5) and have
the identification macro compare, and sum any errors.
Can anyone suggest a robust method for composing vectors of sizes 2 through 5
with a single, general purpose macro?
Thanks
- BE
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> In light of the fact that I was able to solve the scalar / vector typing
> problem, I wanted to do a test of the macro with a full complement of vectors
> that are composed of all permutations of negative, zero, and positive values, so
> that I can test anything that might trigger some edge case and cause the macro
> to fail and misidentify an argument.
>
> To do that, I wrote a macro to generate all of the permutations for any given
> vector size, however it quickly became apparent that actually outputting vectors
> of any given size is a challenge.
>
> There's no way to really assign a value to the individual vector component
> Vector.z, so I'm coming up against an interesting limitation of SDL. It's not a
> trivial task to take an array of values and convert it to a vector.
> Nor can I (that I know) diminish the size of a vector from 5 to 3.
>
> (Can we have 1-component vectors?)
>
> I don't want to use ParseString () to generate 4,000 vectors.
> I also don't want to individually verify every test case, so I'll probably make
> the output of the macro a scalar/vector plus the type (1, 2, 3, 4, 5) and have
> the identification macro compare, and sum any errors.
>
> Can anyone suggest a robust method for composing vectors of sizes 2 through 5
> with a single, general purpose macro?
Hi Bill
Could this be something to work with?
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.7;
global_settings { assumed_gamma 1.0 }
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#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
#debug "\n"
PrintSCalarOrVector(1, 1.0)
#debug "\n"
PrintSCalarOrVector(2, <2.0, 3.0>)
#debug "\n"
PrintSCalarOrVector(3, <3.0, 4.0, 5.0>)
#debug "\n"
PrintSCalarOrVector(4, <4.0, 5.0, 6.0, 7.0>)
#debug "\n"
PrintSCalarOrVector(5, <5.0, 6.0, 7.0, 8.0, 9.0>)
#debug "\n"
#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
#debug "\n"
#declare VS =
CreateScalarOrVector(
array[1] { 1.0 }
)
;
PrintSCalarOrVector(1, VS)
#debug "\n"
#declare VS =
CreateScalarOrVector(
array[2] { 2.0, 3.0 }
)
;
PrintSCalarOrVector(2, VS)
#debug "\n"
#declare VS =
CreateScalarOrVector(
array[3] { 3.0, 4.0, 5.0 }
)
;
PrintSCalarOrVector(3, VS)
#debug "\n"
#declare VS =
CreateScalarOrVector(
array[4] { 4.0, 5.0, 6.0, 7.0 }
)
;
PrintSCalarOrVector(4, VS)
#debug "\n"
#declare VS =
CreateScalarOrVector(
array[5] { 5.0, 6.0, 7.0, 8.0, 9.0 }
)
;
PrintSCalarOrVector(5, VS)
#debug "\n"
#debug "\n"
#error "No error, just finished"
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
>...
> There's no way to really assign a value to the individual vector component
> Vector.z, ...
I'm not sure if I understand what you mean.
I just tried this - and it seems to work like I expected.
#declare v2D = <2, 3>;
#declare NewV = -33;
#declare v2D = <v2D.u, NewV>;
PrintSCalarOrVector(2, v2D)
#debug "\n"
#declare v2D = v2D*u + NewV*v;
PrintSCalarOrVector(2, v2D)
#debug "\n"
#declare v2D = v2D*<1, 0> + <0, NewV>;
PrintSCalarOrVector(2, v2D)
#debug "\n"
#declare v3D = <3, 4, 5>;
#declare NewZ = -55;
#declare v3D = <v3D.x, v3D.y, NewZ>;
PrintSCalarOrVector(3, v3D)
#debug "\n"
#declare v3D = v3D*(x + y) + NewZ*z;
PrintSCalarOrVector(3, v3D)
#debug "\n"
#declare v3D = v3D*<1, 1, 0> + <0, 0, NewZ>;
PrintSCalarOrVector(3, v3D)
#debug "\n"
#declare v4D = <4, 5, 6, 7>;
#declare NewT = -77;
#declare v4D = <v4D.x, v4D.y, v4D.z, NewT>;
PrintSCalarOrVector(4, v4D)
#debug "\n"
#declare v4D = v4D*(x + y + z) + NewT*t;
PrintSCalarOrVector(4, v4D)
#debug "\n"
#declare v4D = v4D*<1, 1, 1, 0> + <0, 0, 0, NewT>;
PrintSCalarOrVector(4, v4D)
#debug "\n"
#declare v5D = <5, 6, 7, 8, 9>;
#declare NewTransmit = -99;
#declare v5D = <v5D.red, v5D.green, v5D.blue, v5D.filter, NewTransmit>;
PrintSCalarOrVector(5, v5D)
#debug "\n"
#declare v5D = v5D*<1, 1, 1, 1, 0> + <0, 0, 0, 0, NewTransmit>;
PrintSCalarOrVector(5, v5D)
#debug "\n"
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
OK, there was nary a drop of coffee in my veins, my eyes were blurry, and I was
fielding questions about an interstate flight while trying to process this.
After re-reading after Second Coffee, I can probably use a #for loop to plug the
appropriate number of array elements into a vector to get what I want.
Will try that after I get home 8h from now ... <eyeroll>
Anyway, try the type-identifying macro and see what you think.
Sorry for the confusion.
- BW
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Ugggggggh.
I got the vector-creating to work, plugged that into the permutation macro, and
got everything written to a file.
Got an error in my scalar part of the #if block, which led me to believe that
there was a misidentification.
So I made a few modifications, and this is what I presently have:
3904 vectors written to TestedValues.txt.
3204 identified correctly.
700 misidentified.
So there is some combination of values that sabotage my algorithm (which is
exactly why I wanted to test 3904 vectors).
I will modify to output the offending vectors to a separate file, and then get
on with seeing if there's a way to "win".
- BW
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |