fit method

dynamic fit(
  1. List<OutputItem> blocks
)

Implementation

fit(List<OutputItem> blocks) {
  var len = blocks.length;
  var width = len > 0 ? blocks[0].width : 0;
  var height = len > 0 ? blocks[0].height : 0;
  this.root = {"x": 0, "y": 0, 'width': width, 'height': height};

  for (final block in blocks) {
    final node = this.findNode(this.root, block.width, block.height);
    if (node != null) {
      final fit = this.splitNode(node, block.width, block.height);
      block.x = fit['x'];
      block.y = fit['y'];
    } else {
      final fit = this.growNode(block.width, block.height);
      block.x = fit['x'];
      block.y = fit['y'];
    }
  }
}