growNode method

dynamic growNode(
  1. int width,
  2. int height
)

Implementation

growNode(int width, int height) {
  var canGrowDown = (width <= this.root['width']);
  var canGrowRight = (height <= this.root['height']);

  var shouldGrowRight = canGrowRight &&
      (this.root['height'] >=
          (this.root['width'] +
              width)); // attempt to keep square-ish by growing right when height is much greater than width
  var shouldGrowDown = canGrowDown &&
      (this.root['width'] >=
          (this.root['height'] +
              height)); // attempt to keep square-ish by growing down  when width  is much greater than height

  if (shouldGrowRight)
    return this.growRight(width, height);
  else if (shouldGrowDown)
    return this.growDown(width, height);
  else if (canGrowRight)
    return this.growRight(width, height);
  else if (canGrowDown)
    return this.growDown(width, height);
  else
    return null; // need to ensure sensible root starting size to avoid this happening
}