mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 23:39:59 -05:00
Handle special case of infinitely big circle in Path#arcTo(), by cheating using an approximation of a really big circle.
This commit is contained in:
parent
5a601f39a4
commit
50bc64779f
1 changed files with 15 additions and 6 deletions
|
@ -1758,7 +1758,6 @@ var Path = this.Path = PathItem.extend({
|
||||||
step = middle.subtract(from);
|
step = middle.subtract(from);
|
||||||
through = middle[clockwise ? 'subtract' : 'add'](-step.y, step.x);
|
through = middle[clockwise ? 'subtract' : 'add'](-step.y, step.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the two perpendicular middle lines to (from, through)
|
// Construct the two perpendicular middle lines to (from, through)
|
||||||
// and (through, to), and intersect them to get the center
|
// and (through, to), and intersect them to get the center
|
||||||
var l1 = new Line(from.add(through).divide(2),
|
var l1 = new Line(from.add(through).divide(2),
|
||||||
|
@ -1766,14 +1765,24 @@ var Path = this.Path = PathItem.extend({
|
||||||
l2 = new Line(through.add(to).divide(2),
|
l2 = new Line(through.add(to).divide(2),
|
||||||
to.subtract(through).rotate(90)),
|
to.subtract(through).rotate(90)),
|
||||||
center = l1.intersect(l2),
|
center = l1.intersect(l2),
|
||||||
vector = from.subtract(center),
|
line = new Line(from, to, true),
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
var vector = from.subtract(center),
|
||||||
radius = vector.getLength(),
|
radius = vector.getLength(),
|
||||||
extent = vector.getDirectedAngle(to.subtract(center)),
|
extent = vector.getDirectedAngle(to.subtract(center));
|
||||||
line = new Line(from, to, true);
|
// If the center is on the same side of the line (from, to) as
|
||||||
// If the center is on the same side of the line (from, to) than
|
|
||||||
// the through point, we're extending bellow 180 degrees and need
|
// the through point, we're extending bellow 180 degrees and need
|
||||||
// to adapt extent.
|
// to adapt extent.
|
||||||
if (line.getSide(center) == line.getSide(through))
|
if (side == line.getSide(center))
|
||||||
extent -= 360 * (extent < 0 ? -1 : 1);
|
extent -= 360 * (extent < 0 ? -1 : 1);
|
||||||
var ext = Math.abs(extent),
|
var ext = Math.abs(extent),
|
||||||
count = ext >= 360 ? 4 : Math.ceil(ext / 90),
|
count = ext >= 360 ? 4 : Math.ceil(ext / 90),
|
||||||
|
|
Loading…
Reference in a new issue