/*
 * Paper.js
 *
 * This file is part of Paper.js, a JavaScript Vector Graphics Library,
 * based on Scriptographer.org and designed to be largely API compatible.
 * http://paperjs.org/
 * http://scriptographer.org/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
 * http://lehni.org/ & http://jonathanpuckey.com/
 *
 * All rights reserved.
 */

var CompoundPath = this.CompoundPath = PathItem.extend({
	initialize: function(paths) {
		this.base();
		this._children = [];
		if (paths) {
			for (var i = 0, l = paths.length; i < l; i++) {
				var path = paths[i];
				// All paths except for the top one (last one in list) are
				// set to clockwise orientation when creating a compound path,
				// so that they appear as holes, but only if their orientation
				// was not already specified before (= _clockwise is defined).
				if (path._clockwise === undefined)
					path.setClockwise(i < l - 1);
				this.appendTop(path);
			}
		}
	},

	/**
	 * If this is a compound path with only one path inside,
	 * the path is moved outside and the compound path is erased.
	 * Otherwise, the compound path is returned unmodified.
	 *
	 * @return the simplified compound path.
	 */
	simplify: function() {
		if (this._children.length == 1) {
			var child = this._children[0];
			child.moveAbove(this);
			this.remove();
			return child;
		}
		return this;
	},

	smooth: function() {
		for (var i = 0, l = this._children.length; i < l; i++)
			this._children[i].smooth();
	},

	draw: function(ctx, param) {
		var firstChild = this._children[0];
		ctx.beginPath();
		param.compound = true;
		for (var i = 0, l = this._children.length; i < l; i++)
			Item.draw(this._children[i], ctx, param);
		firstChild._setStyles(ctx);
		var fillColor = firstChild.getFillColor(),
			strokeColor = firstChild.getStrokeColor();
		if (fillColor) {
			ctx.fillStyle = fillColor.getCanvasStyle(ctx);
			ctx.fill();
		}
		if (strokeColor) {
			ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
			ctx.stroke();
		}
		param.compound = false;
	}
}, new function() { // Injection scope for PostScript-like drawing functions
	function getCurrentPath(that) {
		if (that._children.length) {
			return that._children[that._children.length - 1];
		} else {
			throw new Error('Use a moveTo() command first');
		}
	}

	var fields = {
		moveTo: function() {
			var path = new Path();
			this.appendTop(path);
			path.moveTo.apply(path, arguments);
		},

		moveBy: function() {
			var point = arguments.length ? Point.read(arguments) : new Point(),
				path = getCurrentPath(this),
				current = path.segments[path.segments.length - 1]._point;
			this.moveTo(current.add(point));
		},

		closePath: function() {
			getCurrentPath(this).setClosed(true);
		}
	};

	// Redirect all other drawing commands to the current path
	Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo',
			'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) {
		fields[key] = function() {
			var path = getCurrentPath(this);
			path[key].apply(path, arguments);
		};
	});

	return fields;
});

@@ -551,22 +551,245 @@
 ;%0A%09%09
-if 
+// Do not reassign to paths, since arguments would get modified, which%0A%09%09// we potentially use as array, depending on what is passed.%0A%09%09var items = !paths %7C%7C !Array.isArray
 (paths)
- %7B
 %0A%09
+%09%09%09%7C%7C typeof paths%5B0%5D !== 'object' ? arguments : paths;%0A
 %09%09fo
@@ -806,20 +806,20 @@
  0, l = 
-path
+item
 s.length
@@ -834,17 +834,16 @@
  i++) %7B%0A
-%09
 %09%09%09var p
@@ -852,19 +852,18 @@
 h = 
-path
+item
 s%5Bi%5D;%0A
-%09
 %09%09%09/
@@ -923,22 +923,21 @@
  are
-%0A%09%09%09%09//
  set to
+%0A%09%09%09//
  clo
@@ -985,23 +985,16 @@
 nd path,
-%0A%09%09%09%09//
  so that
@@ -998,16 +998,22 @@
 hat they
+%0A%09%09%09//
  appear 
@@ -1055,15 +1055,8 @@
 tion
-%0A%09%09%09%09//
  was
@@ -1067,16 +1067,22 @@
  already
+%0A%09%09%09//
  specifi
@@ -1121,17 +1121,16 @@
 ed).%0A%09%09%09
-%09
 if (path
@@ -1156,17 +1156,16 @@
 efined)%0A
-%09
 %09%09%09%09path
@@ -1193,17 +1193,16 @@
  1);%0A%09%09%09
-%09
 this.app
@@ -1219,13 +1219,8 @@
 h);%0A
-%09%09%09%7D%0A
 %09%09%7D%0A

Allow passing of Paths to CompoundPath constructor as arguments, without an array object.