Fix Path#arcBy(to, boolean)

This commit is contained in:
Jürg Lehni 2013-11-25 01:04:51 +01:00
parent 02f46b7ac2
commit d079e179ac
2 changed files with 40 additions and 28 deletions

View file

@ -2283,25 +2283,23 @@ var Path = PathItem.extend(/** @lends Path# */{
this.quadraticCurveTo(handle, to); this.quadraticCurveTo(handle, to);
}, },
arcTo: function(to, clockwise /* | through, to */) { arcTo: function(/* to, clockwise | through, to */) {
// Get the start point: // Get the start point:
var current = getCurrentSegment(this), var current = getCurrentSegment(this),
from = current._point, from = current._point,
through, through,
point = Point.read(arguments), to = Point.read(arguments),
// Peek at next value to see if it's clockwise, // Peek at next value to see if it's clockwise,
// with true as default value. // with true as default value.
next = Base.pick(Base.peek(arguments), true); clockwise = Base.pick(Base.peek(arguments), true);
if (typeof next === 'boolean') { if (typeof clockwise === 'boolean') {
// arcTo(to, clockwise) // arcTo(to, clockwise)
to = point;
clockwise = next;
var middle = from.add(to).divide(2), var middle = from.add(to).divide(2),
through = middle.add(middle.subtract(from).rotate( through = middle.add(middle.subtract(from).rotate(
clockwise ? -90 : 90)); clockwise ? -90 : 90));
} else { } else {
// arcTo(through, to) // arcTo(through, to)
through = point; through = to;
to = Point.read(arguments); to = Point.read(arguments);
} }
// Construct the two perpendicular middle lines to (from, through) // 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)); this.quadraticCurveTo(current.add(handle), current.add(to));
}, },
arcBy: function(/* through, to */) { arcBy: function(/* to, clockwise | through, to */) {
var through = Point.read(arguments), var current = getCurrentSegment(this)._point,
to = Point.read(arguments), point = current.add(Point.read(arguments)),
current = getCurrentSegment(this)._point; // Peek at next value to see if it's clockwise, with true as
this.arcTo(current.add(through), current.add(to)); // 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() { closePath: function() {

View file

@ -520,28 +520,36 @@ var PathItem = Item.extend(/** @lends PathItem# */{
* @param {Number} [parameter=0.5] * @param {Number} [parameter=0.5]
*/ */
// DOCS: Document Path#cubicCurveBy() // DOCS: Document Path#cubicCurveBy()
/** /**
* @name PathItem#cubicCurveBy * @name PathItem#cubicCurveBy
* @function * @function
* @param {Point} handle1 * @param {Point} handle1
* @param {Point} handle2 * @param {Point} handle2
* @param {Point} to * @param {Point} to
*/ */
// DOCS: Document Path#quadraticCurveBy() // DOCS: Document Path#quadraticCurveBy()
/** /**
* @name PathItem#quadraticCurveBy * @name PathItem#quadraticCurveBy
* @function * @function
* @param {Point} handle * @param {Point} handle
* @param {Point} to * @param {Point} to
*/ */
// DOCS: Document Path#arcBy() // DOCS: Document Path#arcBy(through, to)
/** /**
* @name PathItem#arcBy * @name PathItem#arcBy
* @function * @function
* @param {Point} through * @param {Point} through
* @param {Point} to * @param {Point} to
*/ */
// DOCS: Document Path#arcBy(to, clockwise)
/**
* @name PathItem#arcBy
* @function
* @param {Point} to
* @param {Boolean} [clockwise=true]
*/
}); });