POV-Ray : Newsgroups : povray.general : Macro return value on failure : Re: Macro return value on failure Server Time
18 Apr 2024 21:54:45 EDT (-0400)
  Re: Macro return value on failure  
From: clipka
Date: 21 Jul 2018 22:45:38
Message: <5b53efd2$1@news.povray.org>
Am 22.07.2018 um 03:57 schrieb Mike Horvath:
> I have two macros that calculate the intersection of two lines and
> return a 2D vector <x,y>.
...

> Normally this works okay, but it is possible for the macro to fail if
> the lines are coinciding. But, how can I signal a failure? I tried
> passing the result to a conditional statement, but POVRay then complains
> that it needs a float value but got a color value. There also is no
> "null" or "undefined" value in POVRay SDL. I would appreciate some tips,
> thanks.

You could return a 3D vector, using the 3rd dimension for a status value.

If you are using POV-Ray v3.8.0, you could also use:

    #macro Line_Intersection(...)
        ...
        #if (D != 0)
            ...
            #local Out_Value = <out_x,out_y>;
            #local Out_Ok = true;
        #else
            #local Out_Value = <0,0>;
            #local Out_Ok = false;
        #end
        (Out_Value, Out_Ok)
    #end
    ...
    #declare (R, R_Ok) = Line_Intersection(...);
    #if (R_ok)
        ...
    #else
        ...
    #end


(As an unrelated side note, it is highly recommended to /not/ use
all-lowercase variable names; such names might be used as new keywords
in future versions without special notice.)


Post a reply to this message

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