createRectGetterMatrixFromLines static method

List<List<RectGetter>> createRectGetterMatrixFromLines({
  1. bool reverseX = false,
  2. bool reverseY = false,
  3. bool equalIgnoreCompare(
    1. NamedLine more,
    2. NamedLine less
    )?,
  4. required List<NamedLine> vLines,
  5. required List<NamedLine> hLines,
})

Implementation

static List<List<RectGetter>> createRectGetterMatrixFromLines({bool reverseX = false, bool reverseY = false,
                // bool looseEqualIgnored = false, double xMinFactor = 0.00001, double yMinFactor = 0.00001,
                bool Function(NamedLine more, NamedLine less)? equalIgnoreCompare,
                required List<NamedLine> vLines, required List<NamedLine> hLines}){
  assert(vLines.length >= 2 && hLines.length >= 2);
  List<List<RectGetter>> retColumns = [];
  for(var yGetterIndex = 0; yGetterIndex < hLines.length - 1; yGetterIndex++){
    var yLessGetter = reverseY ? hLines[yGetterIndex + 1] : hLines[yGetterIndex];
    var yMoreGetter = reverseY ? hLines[yGetterIndex] : hLines[yGetterIndex + 1];
    if(equalIgnoreCompare?.call(yMoreGetter, yLessGetter) ?? false) continue;
    // if(!looseEqualIgnored && yMoreGetter.percent - yLessGetter.percent < yMinFactor || yMoreGetter.looseEqual(yLessGetter)) continue;
    List<RectGetter> newRow = [];
    for(var xGetterIndex =0; xGetterIndex < vLines.length - 1; xGetterIndex++){
      var xLessGetter = reverseX ? vLines[xGetterIndex + 1] : vLines[xGetterIndex];
      var xMoreGetter = reverseX ? vLines[xGetterIndex] : vLines[xGetterIndex + 1];
      if(equalIgnoreCompare?.call(xMoreGetter, xLessGetter) ?? false) continue;
      // if(!looseEqualIgnored && xMoreGetter.percent - xLessGetter.percent < xMinFactor || xMoreGetter.looseEqual(xLessGetter)) continue;
      newRow.add((Size size)=>Rect.fromPoints(
        Offset(xLessGetter.computeWidth(size), yLessGetter.computeHeight(size)),
        Offset(xMoreGetter.computeWidth(size), yMoreGetter.computeHeight(size))
      ));
    }
    retColumns.add(newRow);
  }
  return retColumns;
}