code: function calcLayerRect(iCanvas, layer) {
      var rect = transformRect(iCanvas, layer);
      rect = rectIntersect(rect, {x: 0, y: 0, width: iCanvas.width, height: iCanvas.height});
      return { x: Math.round(rect.x),
          y: Math.round(rect.y),
          width: Math.ceil(rect.width),
          height: Math.ceil(rect.height)};
  }
docs: Calculates the mimimal area that a transformed layer needs so that it can still be drawn on the canvas. Returns a rectangle.