I have 4 float masks on points. I'd like to make a wrangle with a dropdown menu to decide what operation to use for each mask (add, subtract, multiply or divide). Will I have to make a bunch of if statements or is there an easier way?
-Olivier
float combine_masks( float mask0, mask1; int op){ float out = mask0; if ( op == 0 ) out += mask1; if ( op == 1 ) out -= mask1; if ( op == 2 ) out *= mask1; if ( op == 3 ) out /= mask1; return out; }
tamteIf the number of loop iterations is high, you may get better performance by putting the conditional outside of multiple loops.
you can make a function that combines masks and use it in for loop for each mask or whatever you are doing
for (int i = 0; i < 10000, i++)
{
if ( op == 0 ) out += mask1;
else if ( op == 1 ) out -= mask1;
else if ( op == 2 ) out *= mask1;
else if ( op == 3 ) out /= mask1;
}
if (op == 0)
{
for (int i = 0; i < 10000, i++)
out += mask1;
}
else if (op == 1)
{
for (int i = 0; i < 10000, i++)
out -= mask1;
}
... etc
float combine_masks( float mask0, mask1; int op){
olivierthit defines a function [www.sidefx.com] so that you can use it later instead of typing the whole thing again, so later you can just do
@tamte : What is that line about? I've done vex for many years and never came across this before:
float combine_masks( float mask0, mask1; int op){
f@maskA = combine_masks( f@maskA, f@maskB, 0 ); // does f@maskA + f@maskB f@maskC = combine_masks( f@maskA, chf("scale") , 2 ); // does f@maskA * chf("scale") f@maskD = combine_masks( f@maskA, f@maskB, chi("opD") ); // does f@maskA <opD> f@maskB //...