POV-Ray : Newsgroups : povray.general : Github repository with useful macros : Re: Github repository with useful macros Server Time
25 Apr 2024 19:44:44 EDT (-0400)
  Re: Github repository with useful macros  
From: Cousin Ricky
Date: 22 May 2021 00:10:00
Message: <web.60a88326985098ff60e0cc3d949c357d@news.povray.org>
"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]----------


Post a reply to this message

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