POV-Ray : Newsgroups : povray.general : Github repository with useful macros : Re: Github repository with useful macros Server Time
8 May 2024 08:47:56 EDT (-0400)
  Re: Github repository with useful macros  
From: Tor Olav Kristensen
Date: 22 May 2021 05:40:00
Message: <web.60a8cfb8985098ff8e52cc8789db30a9@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> >
> > I don't think that it is possible to investigate the number of components in a
> > vector without it being promoted automatically or having POV-Ray halt on an
> > error.
>
> It is possible to do certain tests.  For example, this macro tests to see
> whether or not v_Padding has a .t component.  This macro is ad hoc, but perhaps
> a more general macro can be written.  I have not found a way to distinguish
> between a scalar and a macro, though.
>
> ----------[BEGIN CODE]---------
> // Convert input to a 4-D vector.  If the input is a 2-D or 3-D vector, then
> // use the .y component for .t.
> #macro Caption__Get_padding (v_Padding)
>   #local caption_Promoted = <0, 0, 0, 0> + v_Padding;
>
>  // See whether .t exists:
>   #local caption_Test1 = v_Padding + 1;
>   #local caption_Test2 = v_Padding + 2;
>
>   < caption_Promoted.x,
>     caption_Promoted.y,
>     caption_Promoted.z,
>    // Test whether .t exists:
>     ( (<0, 0, 0, 0> + caption_Test1).t = (<0, 0, 0, 0> + caption_Test2).t?
>       caption_Promoted.y: caption_Promoted.t
>     )
>     // N.B.  Although a scalar tests incorrectly as having a .t component, it
>     // doesn't matter, because the returned 4-D vector is the same either way.
>   >
> #end
> -----------[END CODE]----------

Hi Ricky

It took me a while to figure out what is going on there.
You are exploiting the automatic vector promoting "feature".
That's clever sorcery !

Here's my take on it:


#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


--
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.