mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Improve handling of Path#arcTo() when the arguments demand an infinitely big circle, by either drawing a line or bailing out.
This commit is contained in:
parent
aa825302e4
commit
2c83eeb7de
1 changed files with 10 additions and 7 deletions
|
@ -1511,7 +1511,7 @@ var Path = this.Path = PathItem.extend({
|
|||
},
|
||||
|
||||
// PORT: New implementation back to Scriptographer
|
||||
arcTo: function(to, clockwise) {
|
||||
arcTo: function(to, clockwise /* | through, to */) {
|
||||
// Get the start point:
|
||||
var current = getCurrentSegment(this),
|
||||
from = current._point,
|
||||
|
@ -1538,12 +1538,15 @@ var Path = this.Path = PathItem.extend({
|
|||
side = line.getSide(through);
|
||||
if (!center) {
|
||||
// If the two lines are colinear, there cannot be an arc as the
|
||||
// circle is infinitely big and has no center point.
|
||||
// We're cheating by producing a center point that's just really
|
||||
// far away. While this is wrong, it graphically produces the
|
||||
// expected results...
|
||||
center = from.add(to).divide(2).add(to.subtract(from).rotate(
|
||||
-90 * (side || 1)).multiply(10e9));
|
||||
// circle is infinitely big and has no center point. If side is
|
||||
// 0, the connecting arc line of this huge circle is a line
|
||||
// between the two points, so we can use #lineTo instead.
|
||||
// Otherwise we bail out:
|
||||
if (!side)
|
||||
return this.lineTo(to);
|
||||
throw new Error(
|
||||
"Cannot put an arc through the given points: "
|
||||
+ Array.prototype.join.call(arguments));
|
||||
}
|
||||
var vector = from.subtract(center),
|
||||
radius = vector.getLength(),
|
||||
|
|
Loading…
Reference in a new issue