Can one put a proc inside an array? This, obviously, does not work.
var arr : array[1, float]
arr[0] = (proc(x:float):float=(x*2.0))
Run
But if it can be done, does it solve my "problem"?
To get a bit more understanding of Nim I'm converting a curve interpolation
library written for POV-Ray.
<http://news.povray.org/povray.binaries.scene-files/attachment/%3CXnsAD34A6FC6BEB5seed7%40news.povray.org%3E/curve.inc.txt>
In POV-Ray I had to put all info regarding the curve in an array, there where
no dictionaries at the time. Two curve definition examples:
//CatmullRom curve
#declare _CIdef[_ci_catmul] = array[3]{
array[3]{4, 1, 2}, //dimseg, step, end
array[1]{2}, //div
array[4]{ //matrix
array[4]{-1, 3,-3, 1},
array[4]{ 2,-5, 4,-1},
array[3]{-1, 0, 1},
array[2]{ 0, 2}
}
};
#macro CIcatmul(CIarr)
_CIinit(CIarr, _ci_catmul, _CIdef[_ci_catmul])
#end
//Simple Cubic End point Slope Control
#declare _CIdef[_ci_simple3_esc] = array[3]{
array[3]{2, 1, 1}, //dimseg, step, end
array[1]{1}, //div
array[4]{ //matrix
array[2]{
function(ESC){2-(2*ESC)},
function(ESC){(2*ESC)-2}
},
array[2]{
function(ESC){(3*ESC)-3},
function(ESC){3-(3*ESC)}
},
array[2]{
function(ESC){-ESC},
function(ESC){ESC}
},
array[1]{
function(ESC){1}
}
}
};
#macro CIsimple3ESC(CIarr, ESC)
#local Type = _ci_simple3_esc;
#local Def = _CIoneVar(Type, ESC) //calculates the matrix values
_CIinit(CIarr, Type, Def)
#end
Run
The first part of a curve definition can go into an object, but I'm struggling
with the matrix part. Not only can it contain functions (procs), also the
amount of entries varies and the length of the entries vary.
type
Matrix = object
matrix: ....
Curve = object
#curve_type: string
dim_seg: int
step: int
end_at: int
divisor: float
matrix: Matrix
Run
A nudge in the right direction would be welcome.