operator - method

  1. @override
Expression operator -(
  1. EquationMember m
)
override

Creates a Expression by subtracting the argument from this member. Both members may need to be hoisted to expressions themselves before this can occur.

For example: right - left can be used as an Expression equivalent of the width property.

Implementation

@override
Expression operator -(EquationMember m) {
  if (m is ConstantMember) {
    return Expression(List<Term>.from(terms), constant - m.value);
  }

  if (m is Param) {
    return Expression(
      List<Term>.from(terms)..add(Term(m.variable, -1)),
      constant,
    );
  }

  if (m is Term) {
    return Expression(
      List<Term>.from(terms)..add(Term(m.variable, -m.coefficient)),
      constant,
    );
  }

  if (m is Expression) {
    final copiedTerms = List<Term>.from(terms);
    for (final t in m.terms) {
      copiedTerms.add(Term(t.variable, -t.coefficient));
    }
    return Expression(copiedTerms, constant - m.constant);
  }
  throw Exception();
}