applyExpressionOperator function

List<double> applyExpressionOperator(
  1. String op,
  2. List<double> a,
  3. List<double> b
)

A binary operator on two values, with GLSL's broadcasting: a one-component value beside a wider one is spread across it.

Shared, through package:flutter3d_foundation/internal.dart, because every reader that evaluates — the closure compiler, the material language's software stage — computes the same operators, and a second implementation of "what does vec3 * float mean" is exactly the drift this language exists to remove. A comparison or a logical operator answers one for true and nought for false.

Implementation

List<double> applyExpressionOperator(
  String op,
  List<double> a,
  List<double> b,
) {
  final width = a.length > b.length ? a.length : b.length;
  double at(List<double> value, int i) =>
      value.length == 1 ? value[0] : value[i];
  return <double>[
    for (var i = 0; i < width; i++)
      expressionOperatorAt(op, at(a, i), at(b, i)),
  ];
}