VuoGenericValue1

Hi

Im kinda sorta wanting to have a tiny bit more info about the VuoGenericValue1 in the API documentation. It usually works great, and I can look up functions for the real case inputs mostly. Now I’ve encountered a function that leaves me longing for a bit more clarification though, the VuoGenericType1_scale.

As the scale factor is also in the native type when looking at how it works for the different types, does this translate to doing math with the generic values as well? I.e. if I multiply a VuoGenericValue1 with a real (2.3 for instance), will this automagically convert itself to a 2d/3d/4d point (2.3, 2.3…)?

Cheers!

When your generic node class is specialized to a data type, VuoGenericType1_scale is replaced by the function for that data type. For example, when you add a Scale List node to the canvas and choose Set Data Type > Real, the call to VuoGenericType1_scale in that node is replaced with VuoReal_scale (documentation).

It’s actually just a text replacement. Everywhere in the node class’s source code, the string VuoGenericType1 is replaced with VuoReal.

The available variations of the scale function are: VuoInteger_scale, VuoReal_scale, VuoPoint2d_scale, VuoPoint3d_scale, VuoPoint4d_scale. While there’s no entry for VuoGenericType1_scale in the API documentation since it’s not an actual function, there are entries for each of these variations.

Thanks! But what I think I mean is, if I scale a VuoGenericInput1 by a real, will the real convert itself to a 2d/3d/4d point as needed? Since the _scale funtion takes scale values in the same format as what they scale that is?

I.e.:
Vuo GenericType1 value;
VuoReal scale = 0.2;
VuoGenericType1_scale(value, (0.2, 0.2)) //for a 2d point?;

No, it won’t automatically convert.

If you want the data type’s “zero” value, you can do VuoGenericType1_makeFromJson(NULL). This returns 0; (0,0); (0,0,0); or (0,0,0,0) as needed.

For non-zero values, one way to do it is demonstrated in the vuo.math.multiply.list.2 node class’s source code. The nodeEvent function calls a (placeholder) function named VuoGenericType1_make1, which is intended to return the “one” value for the appropriate data type. The node class’s source code defines a version of the function for each numeric data type — VuoInteger_make1 that returns 1, VuoPoint2d_make1 that returns (1,1), etc. It’s long-winded but it works.

1 Like

Thank you! I ended up just doing separate nodes for it which also works better from a design point of view, but good to know! Maybe I’ll try it later on!

1 Like