POV-Ray : Newsgroups : povray.general : Github repository with useful macros Server Time
19 May 2025 17:14:56 EDT (-0400)
  Github repository with useful macros (Message 41 to 42 of 42)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: jr
Subject: Re: Github repository with useful macros
Date: 27 May 2021 02:30:00
Message: <web.60af3bbd985098ff79819d986cde94f1@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 22.05.2021 um 13:33 schrieb jr:
>
> > thinking that what your + CR's (ingenious) posts demonstrate is just how much an
> > 'istype()' like function is needed in SDL.  (I've a feeling it would not be too
> > difficult to implement, a developer's perspective would be good)
>
> "Pfffffffaaaaaaaaaaaaahahahahaha! BWAAAAHAHAHAHAHAHA!"
> (*manic laughter*)
> -- Anonymous developer.
>
> Keeping track of the type of things IN THE PARSER ITSELF is painful
> enough... add to that the trouble of coming up with a nice elegant
> syntax, questions such as whether this should work only on variables, or
> also literals or even complex expressions...
>
> ... oh, and then add to the mix that the parser doesn't go, "ah, let me
> evaluate and see what the result of this expression is", but rather "ah,
> I expect this particular type here; let me see how the following makes
> any sense under that presumption"...
> ...

and yet, WFP's current 'is_type()' is an excellent start on all that.  the thing
is that _any_ "introspection" support in SDL would be a step forward.


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Github repository with useful macros
Date: 17 May 2025 20:15:00
Message: <web.68292612985098ff1f9dae3025979125@news.povray.org>
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] TOBEREMOVEDgmailcom> 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)

<<< Previous 10 Messages Goto Initial 10 Messages

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