I'm writing a test application to understand the new UDF features like parameters and return types and while things are better there's certainly some room for improvement, or maybe I just don't know Untyped Objects? I wrote the below code to take a color value in HSL and convert it into an RGB color which is fine if I just want to return a Color for use in a Fill property etc. but I would definitely prefer to return the R, G and B values separately. Is there any way to do this? I can't find much documentation on the changes to UDF, I presume the variables are passed to the function by value and not by reference. Maybe there's some way of returning 3 values as an Untyped Object that I could then call Set(uo, hsl2RGB(230, 0.46, 0.22)); Then cast back to a number like Set(Red, Value(uo.R))?
Chroma(L:Number, S:Number):Number = (1.0 - Abs(2.0 * L - 1.0)) * S;
XComp(C:Number, H:Number):Number = C * (1.0 - Abs(Mod(H / 60.0, 2.0) - 1.0));
ML(L:Number, C:Number):Number = L - (C / 2);
hsl2RGB(H:Number, S:Number, L:Number):Color =
With( {chroma: Chroma(L, S)},
With({c: (chroma + ML(L, chroma)) * 255,
x: (XComp(chroma, H) + ML(L, chroma)) * 255 },
Switch(RoundUp(H / 60.0, 0),
1, RGBA( c, x, ML(L, chroma) * 255, 1 ),
2, RGBA( x, c, ML(L, chroma) * 255, 1 ),
3, RGBA( ML(L, chroma) * 255, c, x, 1 ),
4, RGBA( ML(L, chroma) * 255, x, c, 1 ),
5, RGBA( x, ML(L, chroma) * 255, c, 1 ),
RGBA( c, ML(L, chroma) * 255, x, 1)
)
)
);