From d079e179ac3ebedce1a245b8207de6e3bc0fb885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 25 Nov 2013 01:04:51 +0100 Subject: [PATCH] Fix Path#arcBy(to, boolean) --- src/path/Path.js | 28 ++++++++++++++++------------ src/path/PathItem.js | 40 ++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index fc74146e..e0846a71 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -2283,25 +2283,23 @@ var Path = PathItem.extend(/** @lends Path# */{ this.quadraticCurveTo(handle, to); }, - arcTo: function(to, clockwise /* | through, to */) { + arcTo: function(/* to, clockwise | through, to */) { // Get the start point: var current = getCurrentSegment(this), from = current._point, through, - point = Point.read(arguments), + to = Point.read(arguments), // Peek at next value to see if it's clockwise, // with true as default value. - next = Base.pick(Base.peek(arguments), true); - if (typeof next === 'boolean') { + clockwise = Base.pick(Base.peek(arguments), true); + if (typeof clockwise === 'boolean') { // arcTo(to, clockwise) - to = point; - clockwise = next; var middle = from.add(to).divide(2), through = middle.add(middle.subtract(from).rotate( clockwise ? -90 : 90)); } else { // arcTo(through, to) - through = point; + through = to; to = Point.read(arguments); } // Construct the two perpendicular middle lines to (from, through) @@ -2393,11 +2391,17 @@ var Path = PathItem.extend(/** @lends Path# */{ this.quadraticCurveTo(current.add(handle), current.add(to)); }, - arcBy: function(/* through, to */) { - var through = Point.read(arguments), - to = Point.read(arguments), - current = getCurrentSegment(this)._point; - this.arcTo(current.add(through), current.add(to)); + arcBy: function(/* to, clockwise | through, to */) { + var current = getCurrentSegment(this)._point, + point = current.add(Point.read(arguments)), + // Peek at next value to see if it's clockwise, with true as + // default value. + clockwise = Base.pick(Base.peek(arguments), true); + if (typeof clockwise === 'boolean') { + this.arcTo(point, clockwise); + } else { + this.arcTo(point, current.add(Point.read(arguments))); + } }, closePath: function() { diff --git a/src/path/PathItem.js b/src/path/PathItem.js index baefb329..17ade236 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -520,28 +520,36 @@ var PathItem = Item.extend(/** @lends PathItem# */{ * @param {Number} [parameter=0.5] */ - // DOCS: Document Path#cubicCurveBy() - /** - * @name PathItem#cubicCurveBy - * @function - * @param {Point} handle1 - * @param {Point} handle2 - * @param {Point} to - */ + // DOCS: Document Path#cubicCurveBy() + /** + * @name PathItem#cubicCurveBy + * @function + * @param {Point} handle1 + * @param {Point} handle2 + * @param {Point} to + */ - // DOCS: Document Path#quadraticCurveBy() - /** - * @name PathItem#quadraticCurveBy - * @function - * @param {Point} handle - * @param {Point} to - */ + // DOCS: Document Path#quadraticCurveBy() + /** + * @name PathItem#quadraticCurveBy + * @function + * @param {Point} handle + * @param {Point} to + */ - // DOCS: Document Path#arcBy() + // DOCS: Document Path#arcBy(through, to) /** * @name PathItem#arcBy * @function * @param {Point} through * @param {Point} to */ + + // DOCS: Document Path#arcBy(to, clockwise) + /** + * @name PathItem#arcBy + * @function + * @param {Point} to + * @param {Boolean} [clockwise=true] + */ });