|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hello!
I would like to create a function (used inthe definition of an isosurface) which
itself consists of a sum of functions. The number of summands in this sum
function should be declarable.
How this can be done for merges, intersections or differences via min() and
max(), respectively, was pointed out in a very old thread here:
http://news.povray.org/povray.newusers/thread/%3C3d69631b@news.povray.org%3E/
and is demonstrated in iso_cgs.inc as mentioned in that thread.
However, this seems not to work with sum().
If I do
#declare f_test = array [2]{
function (x) { (x)*1 },
function (x) { (x)*2 }};
#declare f_summe = function(x) {sum(i,0,1,f_test[i](x))};
I get a "Parse Error: Expected 'numeric expression', undeclared identifier 'i'
found instead". Is there any workaround to do the job?
Additonally, I would like to mention that it is not possible to use
dimension_size(f_test,1)-1
as final value expression of the sum, like in
#declare f_summe = function(x)
{sum(i,0,dimension_size(f_test,1)-1,f_test[i](x))};
yielding a "Parse Error: Expected 'operand', array identifier found instead. Is
this a bug, feature or am I doing something wrong?
Anyway, I can work around this, but not the non-working sum above.
Help is greatly appreciated!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Norman <nomail@nomail> wrote:
> #declare f_test = array [2]{
> function (x) { (x)*1 },
> function (x) { (x)*2 }};
> #declare f_summe = function(x) {sum(i,0,1,f_test[i](x))};
It has been a long time since I dealt with user-defined functions,
but I seem to remember that SDL arrays are not supported in them.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Am 18.02.2013 15:37, schrieb Norman:
> If I do
>
>
> #declare f_test = array [2]{
> function (x) { (x)*1 },
> function (x) { (x)*2 }};
>
> #declare f_summe = function(x) {sum(i,0,1,f_test[i](x))};
>
>
> I get a "Parse Error: Expected 'numeric expression', undeclared identifier 'i'
> found instead". Is there any workaround to do the job?
Yup:
#declare f_summe = function(x) {
#for(i,0,1)
+ f_test[i](x)
#end
}
> Additonally, I would like to mention that it is not possible to use
> dimension_size(f_test,1)-1
> as final value expression of the sum, like in
>
> #declare f_summe = function(x)
> {sum(i,0,dimension_size(f_test,1)-1,f_test[i](x))};
>
> yielding a "Parse Error: Expected 'operand', array identifier found instead. Is
> this a bug, feature or am I doing something wrong?
Neither of the three - it's simply a limitation in what you can use
within a function and what not. Those limitations are necessary because
functions need to be (potentially) evaluated at run time. These
limitations include (but are not limited to):
- Functions can't access SDL variables. What actually happens when you
place an SDL variable in a function is that the SDL variable is
evaluated /immediately/; e.g.:
#declare a = 1;
#declare f = function(x) { a * x }
#declare a = 2;
#debug concat(str(f(1),0,-1),"\n")
will yield "1", not "2".
- Functions can only deal with scalar expressions. No vectors, no
arrays, no nothing.
> Anyway, I can work around this, but not the non-working sum above.
Note that the workaround for the sum() problem works fine with
dimension_size.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|