POV-Ray : Newsgroups : povray.general : Vector identifiers/axis values in a float function : Re: Vector identifiers/axis values in a float function Server Time
26 Jun 2024 06:26:32 EDT (-0400)
  Re: Vector identifiers/axis values in a float function  
From: clipka
Date: 3 Dec 2016 10:33:31
Message: <5842e5cb@news.povray.org>
Am 03.12.2016 um 12:47 schrieb [GDS|Entropy]:

> In a macro when I have a parameter of type vector and pass its value as
> such, I get an error:
> 
> abs(x - Position.x)
> 
> But if I do this it works:
> 
> #local positionX = Position.x;
> abs(x - positionX)

I very much doubt that the latter works.

As William already pointed out, the problem isn't so much the use of
`Position`, or even `Position.x`, but the very first term of the
expression inside `abs()`: The lone `x`.

When standing on its own (as opposed to `Something.x`) outside of a
function definition, `x` is a constant evaluating to `<1,0,0>`. Thus,
the expression

    abs(x - Position.x)

is equivalent to

    abs(<1,0,0> - Position.x)

which, thanks to scalar-to-vector promotion, is in turn equivalent to

    abs(<1,0,0> - <Position.x,0,0>)

which in turn is equivalent to

    abs(<1-Position.x,0,0>)

The location given for the error message may be misleading, but POV-Ray
does not know that the expression inside the `abs()` will evaluate to a
vector until it has indeed completely parsed the expression.


Post a reply to this message

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