POV-Ray : Newsgroups : povray.general : Github repository with useful macros : Re: Github repository with useful macros Server Time
4 May 2024 15:09:20 EDT (-0400)
  Re: Github repository with useful macros  
From: Tor Olav Kristensen
Date: 22 May 2021 18:15:00
Message: <web.60a98210985098ffdd9d48c789db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>
> > I'm fuzzily thinking that maybe
> > there's a way to disambiguate a 5D vector and a scalar by adding and/or
> > multiplying with vectors containing different signs and testing the result?
> >
> > My brain is also giving me the impression that binary math and things like (I
> > said _like_) bitmasks and xor might offer inspiration for a solution.
>
> I got most of the way there by finally realizing that a scalar added to a 5D
> vector adds the scalar to ALL of the vector components, whereas with a vector
> added to a 5D vector, automatic vector expansion pads the smaller vector with
> zeros, and then the corresponding components are added to each other.
>
> The really tricky part I've mostly ironed out is differentiating scalar 0 and
> the all-zero-vectors.
>
> I had some real trouble getting it work for the 5D zero vector, but I made a
> hack that seems to work. (See Vdiscrim calculation and D1 logic)
> Maybe to be robust, there needs to be a walk up to 5D and then back down
> again...
>
>
> It's a little messy and complex, because I wrote it by feel and flashes of
> inspiration rather than pure rigor, but it seems to work for most cases I've
> plugged in.
>
> Now, you know what to do:  Take it and Break it.

I followed your multiplication suggestion - and ended up with this, which after
some initial tests seems to work:


#macro VectorDim(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 v3 = (v0 + 1)*<1, 1>;
    #local v4 = (v0*<1, 1>) + 1;
    #local D2 = ((vZ3D + v1).z = (vZ3D + v2).z);
    #local D3 = ((vZ4D + v1).t = (vZ4D + v2).t);
    #local D4 = ((vZ5D + v1).transmit = (vZ5D + v2).transmit);
    #local D5 = ((vZ3D + v3).z != (vZ3D + v4).z);

    #if (D2)
        #debug "2D"
    #else
        #if (D3)
            #debug "3D"
        #else
            #if (D4)
                #debug "4D"
            #else
                #if (D5)
                    #debug "5D"
                #else
                    #debug "Scalar"
                #end // if
            #end // if
        #end // if
    #end // if

#end // VectorDim


#macro AltVectorDim(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 v3 = (v0 + 1)*<1, 1>;
    #local v4 = (v0*<1, 1>) + 1;
    #local D3 = ((vZ3D + v3).z != (vZ3D + v4).z);
    #local D4 = ((vZ4D + v3).t != (vZ4D + v4).t);
    #local D5 = ((vZ5D + v3).transmit != (vZ5D + v4).transmit);

    #if (D5)
        #debug "5D"
    #else
        #if (D4)
            #debug "4D"
        #else
            #if (D3)
                #debug "3D"
            #else
                #if (D2)
                    #debug "2D"
                #else
                    #debug "Scalar"
                #end // if
            #end // if
        #end // if
    #end // if

#end // AltVectorDim


I'll have a look at the code you have made so far to see if we are on the same
track.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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