operator * method

Varset operator *(
  1. Varset other
)

The cross operator.

Crossing assigns varsets to different dimensions (Usually x and y) in order.

Implementation

Varset operator *(Varset other) {
  // It creates a term:
  //
  // - [form], cartisian products left and right.
  // - [nested], if only one has, uses that one; if both has, throws an error.
  // - [nesters], the same as [nested].

  final AlgForm formRst = [];
  // Cartisien production of two froms, which is also a form.
  for (var a in form) {
    for (var b in other.form) {
      formRst.add([...a, ...b]);
    }
  }

  AlgForm? nestedRst;
  List<AlgForm> nestersRst = [];
  if (nested == null) {
    nestedRst = other.nested;
    nestersRst = other.nesters;
  } else {
    // nested != null.

    if (other.nested == null) {
      nestedRst = nested;
      nestersRst = nesters;
    } else {
      throw ArgumentError('Two nested operands can not cross');
    }
  }

  return Varset._create(
    formRst,
    nestedRst,
    nestersRst,
  );
}