MatrixNode constructor

MatrixNode({
  1. double arrayStretch = 1.0,
  2. bool hskipBeforeAndAfter = false,
  3. bool isSmall = false,
  4. List<MatrixColumnAlign> columnAligns = const [],
  5. List<MatrixSeparatorStyle> vLines = const [],
  6. List<Measurement> rowSpacings = const [],
  7. List<MatrixSeparatorStyle> hLines = const [],
  8. required List<List<EquationRowNode?>> body,
})

Factory constructor for MatrixNode that will sanitize inputs.

Implementation

factory MatrixNode({
  double arrayStretch = 1.0,
  bool hskipBeforeAndAfter = false,
  bool isSmall = false,
  List<MatrixColumnAlign> columnAligns = const [],
  List<MatrixSeparatorStyle> vLines = const [],
  List<Measurement> rowSpacings = const [],
  List<MatrixSeparatorStyle> hLines = const [],
  required List<List<EquationRowNode?>> body,
}) {
  final cols = max3(
    body.map((row) => row.length).maxOrNull ?? 0,
    columnAligns.length,
    vLines.length - 1,
  );
  final sanitizedColumnAligns =
      columnAligns.extendToByFill(cols, MatrixColumnAlign.center);
  final sanitizedVLines =
      vLines.extendToByFill(cols + 1, MatrixSeparatorStyle.none);

  final rows = max3(
    body.length,
    rowSpacings.length,
    hLines.length - 1,
  );

  final sanitizedBody = body
      .map((row) => row.extendToByFill(cols, null))
      .toList(growable: false)
      .extendToByFill(rows, List.filled(cols, null));
  final sanitizedRowSpacing =
      rowSpacings.extendToByFill(rows, Measurement.zero);
  final sanitizedHLines =
      hLines.extendToByFill(rows + 1, MatrixSeparatorStyle.none);

  return MatrixNode._(
    rows: rows,
    cols: cols,
    arrayStretch: arrayStretch,
    hskipBeforeAndAfter: hskipBeforeAndAfter,
    isSmall: isSmall,
    columnAligns: sanitizedColumnAligns,
    vLines: sanitizedVLines,
    rowSpacings: sanitizedRowSpacing,
    hLines: sanitizedHLines,
    body: sanitizedBody,
  );
}