mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Changes to new #arcTo(): Rename sweep -> clockwise and change argument sequence, as clockwise is more often used than large.
This commit is contained in:
parent
4751fc6dc8
commit
42558fa057
2 changed files with 11 additions and 10 deletions
|
@ -2296,7 +2296,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
arcTo: function(/* to, clockwise | through, to
|
arcTo: function(/* to, clockwise | through, to
|
||||||
| to, radius, rotation, large, sweep */) {
|
| to, radius, rotation, clockwise, large */) {
|
||||||
// Get the start point:
|
// Get the start point:
|
||||||
var current = getCurrentSegment(this),
|
var current = getCurrentSegment(this),
|
||||||
from = current._point,
|
from = current._point,
|
||||||
|
@ -2319,7 +2319,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
through = to;
|
through = to;
|
||||||
to = Point.read(arguments);
|
to = Point.read(arguments);
|
||||||
} else {
|
} else {
|
||||||
// #3: arcTo(to, radius, rotation, large, sweep)
|
// #3: arcTo(to, radius, rotation, clockwise, large)
|
||||||
// Drawing arcs in SVG style:
|
// Drawing arcs in SVG style:
|
||||||
var radius = Size.read(arguments);
|
var radius = Size.read(arguments);
|
||||||
// If rx = 0 or ry = 0 then this arc is treated as a
|
// If rx = 0 or ry = 0 then this arc is treated as a
|
||||||
|
@ -2329,8 +2329,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
// See for an explanation of the following calculations:
|
// See for an explanation of the following calculations:
|
||||||
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
||||||
var rotation = Base.read(arguments),
|
var rotation = Base.read(arguments),
|
||||||
|
clockwise = !!Base.read(arguments),
|
||||||
large = !!Base.read(arguments),
|
large = !!Base.read(arguments),
|
||||||
sweep = !!Base.read(arguments),
|
|
||||||
middle = from.add(to).divide(2),
|
middle = from.add(to).divide(2),
|
||||||
pt = from.subtract(middle).rotate(-rotation),
|
pt = from.subtract(middle).rotate(-rotation),
|
||||||
x = pt.x,
|
x = pt.x,
|
||||||
|
@ -2361,7 +2361,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
center = new Point(rx * y / ry, -ry * x / rx)
|
center = new Point(rx * y / ry, -ry * x / rx)
|
||||||
// "...where the + sign is chosen if fA != fS,
|
// "...where the + sign is chosen if fA != fS,
|
||||||
// and the − sign is chosen if fA = fS."
|
// and the − sign is chosen if fA = fS."
|
||||||
.multiply((large == sweep ? -1 : 1) * Math.sqrt(factor))
|
.multiply((large === clockwise ? -1 : 1)
|
||||||
|
* Math.sqrt(factor))
|
||||||
.rotate(rotation).add(middle);
|
.rotate(rotation).add(middle);
|
||||||
// Now create a matrix that maps the unit circle to the ellipse,
|
// Now create a matrix that maps the unit circle to the ellipse,
|
||||||
// for easier construction below.
|
// for easier construction below.
|
||||||
|
@ -2371,11 +2372,11 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
// and calculcate start vector and extend from there.
|
// and calculcate start vector and extend from there.
|
||||||
vector = matrix._inverseTransform(from);
|
vector = matrix._inverseTransform(from);
|
||||||
extent = vector.getDirectedAngle(matrix._inverseTransform(to));
|
extent = vector.getDirectedAngle(matrix._inverseTransform(to));
|
||||||
// "...in other words, if sweep = 0 and extent is > 0, subtract
|
// "...if fS = 0 and extent is > 0, then subtract 360, whereas
|
||||||
// 360, whereas if sweep = 1 and extent < 0, then add 360."
|
// if fS = 1 and extend is < 0, then add 360."
|
||||||
if (!sweep && extent > 0)
|
if (!clockwise && extent > 0)
|
||||||
extent -= 360;
|
extent -= 360;
|
||||||
else if (sweep && extent < 0)
|
else if (clockwise && extent < 0)
|
||||||
extent += 360;
|
extent += 360;
|
||||||
}
|
}
|
||||||
if (through) {
|
if (through) {
|
||||||
|
@ -2413,7 +2414,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
// If the center is on the same side of the line (from, to)
|
// If the center is on the same side of the line (from, to)
|
||||||
// as the through point, we're extending bellow 180 degrees
|
// as the through point, we're extending bellow 180 degrees
|
||||||
// and need to adapt extent.
|
// and need to adapt extent.
|
||||||
extent -= 360 * (extent < 0 ? -1 : 1);
|
extent += extent < 0 ? 360 : -360;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ext = Math.abs(extent),
|
var ext = Math.abs(extent),
|
||||||
|
|
|
@ -286,7 +286,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
||||||
for (var j = 0; j < length; j += 7) {
|
for (var j = 0; j < length; j += 7) {
|
||||||
this.arcTo(current = getPoint(j + 5),
|
this.arcTo(current = getPoint(j + 5),
|
||||||
new Size(+coords[0], +coords[1]),
|
new Size(+coords[0], +coords[1]),
|
||||||
+coords[2], +coords[3], +coords[4]);
|
+coords[2], +coords[4], +coords[3]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
|
|
Loading…
Reference in a new issue