33#include <NDEVR/String.h>
34#include <NDEVR/Dictionary.h>
43 template<
class t_type>
71 for (
uint04 i = 0; i < locations.size(); i++)
83 for (
uint04 i = 0; i < locations.size(); i++)
94 static t_type
solve(t_type left,
const char op, t_type right)
98 case '+':
return left + right;
99 case '-':
return left - right;
100 case '/':
return left / right;
101 case '*':
return left * right;
102 case '^':
return std::pow(left, right);
103 case '%':
return std::fmod(left, right);
104 case 's':
return std::sin(right);
105 case 'c':
return std::cos(right);
106 case 't':
return std::tan(right);
107 case 'q':
return std::sqrt(right);
108 case '\0':
return right;
109 default:
return Constant<t_type>::Invalid;
122 return Constant<t_type>::Invalid;
130 void add(
char operation, t_type value)
156 default:
return Constant<t_type>::Invalid;
182 part.
value = Constant<t_type>::Invalid;
198 return Constant<t_type>::Invalid;
207 case '^': start = std::pow(start,
m_equation_stack[current_index].value);
break;
208 case '%': start = std::fmod(start,
m_equation_stack[current_index].value);
break;
218 return Constant<t_type>::Invalid;
221 case 's': inner_solve =
sin(inner_solve);
break;
222 case 'c': inner_solve =
cos(inner_solve);
break;
223 case 't': inner_solve =
tan(inner_solve);
break;
224 case 'q': inner_solve =
sqrt(inner_solve);
break;
227 start =
solve(start, lead_operation, inner_solve);
229 case ')':
return start;
230 default: lib_assert(
false,
"unknown operator");
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
Dictionary< String, Buffer< uint04 > > m_variable_locations
Maps variable names to their indices within the equation stack.
t_type solve(t_type start, uint04 ¤t_index) const
Recursively solves the equation stack starting from the given index, accumulating onto a starting val...
void add(char operation, t_type value)
Appends a numeric equation part to the equation stack.
void setVariable(const StringView &var, t_type value)
Sets the value of a named variable and updates all locations in the equation stack that reference it.
void addOrderOfOps(char operation, t_type value)
Adds an equation part at a position determined by order-of-operations priority.
Buffer< EquationPart > m_equation_stack
The ordered stack of equation parts representing the formula.
static uint04 getOrderPriority(const char op)
Returns the order-of-operations priority for the given operator.
void refreshVariables()
Refreshes all variable locations in the equation stack using the currently stored variable values.
static t_type solve(t_type left, const char op, t_type right)
Solves a single binary or unary operation given a left operand, operator, and right operand.
Dictionary< String, t_type > m_variables
Maps variable names to their current numeric values.
t_type solve() const
Solves the entire equation by evaluating the equation stack from the beginning.
Equation()
Default constructor.
void add(char operation, const String &value)
Appends a variable-referencing equation part to the equation stack.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
t_type sqrt(const t_type &value)
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Performs optimized sine operation on the given angle using pre-computed lookup table for optimal spee...
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type tan(const Angle< t_type > &angle)
Performs optimized tangent operation on the given angle using pre-computed lookup table for optimal s...
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Performs optimized cosine operation on the given angle using pre-computed lookup table for optimal sp...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Represents a single element in the equation stack, consisting of an operator and a value.
t_type value
The numeric value or encoded sub-expression parameter for this part.
char operation
The operator character (e.g., '+', '-', '*', '/', '^', '', 's', 'c', 't', 'q', '(',...