Vuo  2.3.2
Classes | Functions | Variables
VuoMathExpressionParser.cc File Reference

Description

VuoMathExpressionParser implementation.

Definition in file VuoMathExpressionParser.cc.

Go to the source code of this file.

Classes

class  VuoMathExpressionErrorInternal
 C++ implementation of opaque C type VuoMathExpressionError. More...
 
class  VuoMathExpressionParserInternal
 C++ implementation of opaque C type VuoMathExpressionParser. More...
 

Functions

const char * VuoMathExpressionError_getMessage (VuoMathExpressionError error)
 Returns a description of the error. More...
 
VuoList_VuoInteger VuoMathExpressionError_getExpressionIndices (VuoMathExpressionError error)
 Returns a sorted list of the indices of the math expressions causing the error. More...
 
void VuoMathExpressionError_free (VuoMathExpressionError error)
 Destructor. More...
 
static double deg2rad (double degrees)
 Converts degrees to radians. More...
 
static double rad2deg (double radians)
 Converts radians to degrees. More...
 
static double muparser_rint (double x)
 As defined by muParserTemplateMagic.h. More...
 
static double fract (double x)
 As defined by https://www.opengl.org/sdk/docs/man/html/fract.xhtml. More...
 
static double clamp (double x, double minVal, double maxVal)
 As defined by https://www.opengl.org/sdk/docs/man/html/clamp.xhtml. More...
 
static double step (double edge, double x)
 As defined by https://www.opengl.org/sdk/docs/man/html/step.xhtml. More...
 
static double smoothstep (double edge0, double edge1, double x)
 As defined by https://www.opengl.org/sdk/docs/man/html/smoothstep.xhtml. More...
 
static double mix (double x, double y, double a)
 As defined by https://www.opengl.org/sdk/docs/man/html/mix.xhtml. More...
 
void VuoMathExpressionParser_defineStandardLibrary (void *p)
 Given a pointer to a mu::Parser instance, adds Vuo's standard operators, constants, and functions. More...
 
static vector< string > splitSingleExpressionOnAssignmentOperators (string expression)
 Returns the parts of expression separated by (and not including) the assignment operator ("="). More...
 
static void checkSyntaxOfSingleExpression (string expression, VuoMathExpressionError *error)
 Checks that expression contains a syntactically valid, single math expression with at most one assignment operator. More...
 
static void checkSyntaxOfMultipleExpressions (VuoList_VuoText expressions, VuoMathExpressionError *error)
 Checks that each single math expression in expressions satisfies checkSyntaxOfSingleExpression(). More...
 
static void parseVariablesFromSingleExpression (string expression, vector< string > &inputVariableNames, string &outputVariableName, VuoMathExpressionError *error)
 Parses the unique variable names from expression and puts them in inputVariableNames and outputVariableName. More...
 
static void parseVariablesFromMultipleExpressions (VuoList_VuoText expressions, vector< string > &inputVariableNames, vector< string > &outputVariableNames, VuoMathExpressionError *error)
 Parses the unique variable names from expressions and puts them in inputVariableNames and outputVariableNames. More...
 
void VuoMathExpressionParser_free (void *me)
 Destroys me, a VuoMathExpressionParser. More...
 
VuoMathExpressionParser VuoMathExpressionParser_makeFromSingleExpression (VuoText expression, VuoMathExpressionError *error)
 Parses expression (e.g. More...
 
VuoMathExpressionParser VuoMathExpressionParser_makeFromMultipleExpressions (VuoList_VuoText expressions, VuoMathExpressionError *error)
 Parses expressions (e.g. More...
 
VuoList_VuoText VuoMathExpressionParser_getInputVariables (VuoMathExpressionParser m)
 Returns the unique input variable names from the parsed expression(s), in alphabetical order. More...
 
VuoList_VuoText VuoMathExpressionParser_getOutputVariables (VuoMathExpressionParser m)
 Returns the output variable names from the parsed expression(s), in the order they appeared. More...
 
VuoDictionary_VuoText_VuoReal VuoMathExpressionParser_calculate (VuoMathExpressionParser m, VuoDictionary_VuoText_VuoReal inputValues)
 Evaluates the parsed expression(s). More...
 
VuoList_VuoReal VuoMathExpressionParser_calculateList (VuoMathExpressionParser m, VuoList_VuoReal xValues, VuoDictionary_VuoText_VuoReal constants)
 Evaluates the expression for each of xValues. More...
 
static double sinInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double cosInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double tanInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double asinInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double acosInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double atanInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double atan2InDegrees (double y, double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double sinhInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double coshInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double tanhInDegrees (double degrees)
 Trigonometric functions that take degrees instead of radians. More...
 
static double asinhInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double acoshInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double atanhInDegrees (double x)
 Trigonometric functions that take degrees instead of radians. More...
 
static double perlin2d (double x, double y)
 Gradient noise wrappers. More...
 
static double perlin3d (double x, double y, double z)
 Gradient noise wrappers. More...
 
static double perlin4d (double x, double y, double z, double w)
 Gradient noise wrappers. More...
 
static double simplex2d (double x, double y)
 Gradient noise wrappers. More...
 
static double simplex3d (double x, double y, double z)
 Gradient noise wrappers. More...
 
static double simplex4d (double x, double y, double z, double w)
 Gradient noise wrappers. More...
 

Variables

static const size_t MAX_VARIABLE_COUNT = 64
 Maximum number of variables that can be parsed by a VuoMathExpressionParser. More...
 

Function Documentation

◆ acoshInDegrees()

static double acoshInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 196 of file VuoMathExpressionParser.cc.

◆ acosInDegrees()

static double acosInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 189 of file VuoMathExpressionParser.cc.

◆ asinhInDegrees()

static double asinhInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 195 of file VuoMathExpressionParser.cc.

◆ asinInDegrees()

static double asinInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 188 of file VuoMathExpressionParser.cc.

◆ atan2InDegrees()

static double atan2InDegrees ( double  y,
double  x 
)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 191 of file VuoMathExpressionParser.cc.

◆ atanhInDegrees()

static double atanhInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 197 of file VuoMathExpressionParser.cc.

◆ atanInDegrees()

static double atanInDegrees ( double  x)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 190 of file VuoMathExpressionParser.cc.

◆ checkSyntaxOfMultipleExpressions()

static void checkSyntaxOfMultipleExpressions ( VuoList_VuoText  expressions,
VuoMathExpressionError error 
)
static

Checks that each single math expression in expressions satisfies checkSyntaxOfSingleExpression().

Definition at line 428 of file VuoMathExpressionParser.cc.

◆ checkSyntaxOfSingleExpression()

static void checkSyntaxOfSingleExpression ( string  expression,
VuoMathExpressionError error 
)
static

Checks that expression contains a syntactically valid, single math expression with at most one assignment operator.

Definition at line 398 of file VuoMathExpressionParser.cc.

◆ clamp()

static double clamp ( double  x,
double  minVal,
double  maxVal 
)
static

◆ coshInDegrees()

static double coshInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 193 of file VuoMathExpressionParser.cc.

◆ cosInDegrees()

static double cosInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 186 of file VuoMathExpressionParser.cc.

◆ deg2rad()

static double deg2rad ( double  degrees)
static

Converts degrees to radians.

Definition at line 119 of file VuoMathExpressionParser.cc.

◆ fract()

static double fract ( double  x)
static

◆ mix()

static double mix ( double  x,
double  y,
double  a 
)
static

◆ muparser_rint()

static double muparser_rint ( double  x)
static

As defined by muParserTemplateMagic.h.

Definition at line 135 of file VuoMathExpressionParser.cc.

◆ parseVariablesFromMultipleExpressions()

static void parseVariablesFromMultipleExpressions ( VuoList_VuoText  expressions,
vector< string > &  inputVariableNames,
vector< string > &  outputVariableNames,
VuoMathExpressionError error 
)
static

Parses the unique variable names from expressions and puts them in inputVariableNames and outputVariableNames.

Assumes that expressions satisfies checkSyntaxOfMultipleExpressions().

Definition at line 477 of file VuoMathExpressionParser.cc.

◆ parseVariablesFromSingleExpression()

static void parseVariablesFromSingleExpression ( string  expression,
vector< string > &  inputVariableNames,
string &  outputVariableName,
VuoMathExpressionError error 
)
static

Parses the unique variable names from expression and puts them in inputVariableNames and outputVariableName.

Assumes that expression satisfies checkSyntaxOfSingleExpression().

Definition at line 449 of file VuoMathExpressionParser.cc.

◆ perlin2d()

static double perlin2d ( double  x,
double  y 
)
static

Gradient noise wrappers.

Definition at line 204 of file VuoMathExpressionParser.cc.

◆ perlin3d()

static double perlin3d ( double  x,
double  y,
double  z 
)
static

Gradient noise wrappers.

Definition at line 205 of file VuoMathExpressionParser.cc.

◆ perlin4d()

static double perlin4d ( double  x,
double  y,
double  z,
double  w 
)
static

Gradient noise wrappers.

Definition at line 206 of file VuoMathExpressionParser.cc.

◆ rad2deg()

static double rad2deg ( double  radians)
static

Converts radians to degrees.

Definition at line 127 of file VuoMathExpressionParser.cc.

◆ simplex2d()

static double simplex2d ( double  x,
double  y 
)
static

Gradient noise wrappers.

Definition at line 207 of file VuoMathExpressionParser.cc.

◆ simplex3d()

static double simplex3d ( double  x,
double  y,
double  z 
)
static

Gradient noise wrappers.

Definition at line 208 of file VuoMathExpressionParser.cc.

◆ simplex4d()

static double simplex4d ( double  x,
double  y,
double  z,
double  w 
)
static

Gradient noise wrappers.

Definition at line 209 of file VuoMathExpressionParser.cc.

◆ sinhInDegrees()

static double sinhInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 192 of file VuoMathExpressionParser.cc.

◆ sinInDegrees()

static double sinInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 185 of file VuoMathExpressionParser.cc.

◆ smoothstep()

static double smoothstep ( double  edge0,
double  edge1,
double  x 
)
static

◆ splitSingleExpressionOnAssignmentOperators()

static vector<string> splitSingleExpressionOnAssignmentOperators ( string  expression)
static

Returns the parts of expression separated by (and not including) the assignment operator ("=").

Assumes that expression satisfies checkSyntaxOfSingleExpression().

Definition at line 367 of file VuoMathExpressionParser.cc.

◆ step()

static double step ( double  edge,
double  x 
)
static

◆ tanhInDegrees()

static double tanhInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 194 of file VuoMathExpressionParser.cc.

◆ tanInDegrees()

static double tanInDegrees ( double  degrees)
static

Trigonometric functions that take degrees instead of radians.

Definition at line 187 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionError_free()

void VuoMathExpressionError_free ( VuoMathExpressionError  error)

Destructor.

Definition at line 107 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionError_getExpressionIndices()

VuoList_VuoInteger VuoMathExpressionError_getExpressionIndices ( VuoMathExpressionError  error)

Returns a sorted list of the indices of the math expressions causing the error.

The indices refer to the VuoList_VuoText passed to VuoMathExpressionParser_makeFromMultipleExpressions().

Definition at line 93 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionError_getMessage()

const char* VuoMathExpressionError_getMessage ( VuoMathExpressionError  error)

Returns a description of the error.

The returned pointer is owned by error and should not be freed by the caller.

Definition at line 82 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_calculate()

VuoDictionary_VuoText_VuoReal VuoMathExpressionParser_calculate ( VuoMathExpressionParser  m,
VuoDictionary_VuoText_VuoReal  inputValues 
)

Evaluates the parsed expression(s).

The value of each input variable is set from inputValues (a mapping of variable names to values). Any variables not in inputValues are set to 0.

Returns a mapping of output variable names to values.

Definition at line 644 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_calculateList()

VuoList_VuoReal VuoMathExpressionParser_calculateList ( VuoMathExpressionParser  m,
VuoList_VuoReal  xValues,
VuoDictionary_VuoText_VuoReal  constants 
)

Evaluates the expression for each of xValues.

Definition at line 686 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_defineStandardLibrary()

void VuoMathExpressionParser_defineStandardLibrary ( void *  p)

Given a pointer to a mu::Parser instance, adds Vuo's standard operators, constants, and functions.

Definition at line 215 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_free()

void VuoMathExpressionParser_free ( void *  me)

Destroys me, a VuoMathExpressionParser.

Definition at line 543 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_getInputVariables()

VuoList_VuoText VuoMathExpressionParser_getInputVariables ( VuoMathExpressionParser  m)

Returns the unique input variable names from the parsed expression(s), in alphabetical order.

Definition at line 609 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_getOutputVariables()

VuoList_VuoText VuoMathExpressionParser_getOutputVariables ( VuoMathExpressionParser  m)

Returns the output variable names from the parsed expression(s), in the order they appeared.

For a non-assignment expression (e.g. "x + 1", as opposed to "y = x + 1"), a unique name is automatically assigned.

Definition at line 625 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_makeFromMultipleExpressions()

VuoMathExpressionParser VuoMathExpressionParser_makeFromMultipleExpressions ( VuoList_VuoText  expressions,
VuoMathExpressionError error 
)

Parses expressions (e.g.

["sum=n1+n2", "product=n1*n2", "n1-n2+5"]).

If parsing fails, returns null and sets error.

Definition at line 577 of file VuoMathExpressionParser.cc.

◆ VuoMathExpressionParser_makeFromSingleExpression()

VuoMathExpressionParser VuoMathExpressionParser_makeFromSingleExpression ( VuoText  expression,
VuoMathExpressionError error 
)

Parses expression (e.g.

"a + b" or "y = x + 1").

If parsing fails, returns null and sets error.

Definition at line 553 of file VuoMathExpressionParser.cc.

Variable Documentation

◆ MAX_VARIABLE_COUNT

const size_t MAX_VARIABLE_COUNT = 64
static

Maximum number of variables that can be parsed by a VuoMathExpressionParser.

Definition at line 114 of file VuoMathExpressionParser.cc.