Fix Path#arcTo() when from/to points are equal

Closes #1613
This commit is contained in:
sasensi 2018-11-23 11:04:45 +01:00 committed by Jürg Lehni
parent 4ba406bfe3
commit 3177c7ac46
3 changed files with 51 additions and 39 deletions

View file

@ -13,6 +13,7 @@
- Do not ignore `Group#clipItem.matrix` in `Group#internalBounds` (#1427).
- Correctly calculate bounds with nested empty items (#1467).
- Fix color change propagation on groups (#1152).
- Fix `Path#arcTo()` where `from` and `to` points are equal (#1613).
- SVG Export: Fix error when `Item#matrix` is not invertible (#1580).
- SVG Export: Include missing viewBox attribute (#1576).
- SVG Import: Use correct default values for gradients (#1632, #1661).

View file

@ -2467,9 +2467,10 @@ new function() { // PostScript-style drawing commands
// #2: arcTo(through, to)
through = to;
to = Point.read(arguments);
} else {
} else if (!from.equals(to)) {
// #3: arcTo(to, radius, rotation, clockwise, large)
// Drawing arcs in SVG style:
// Draw arc in SVG style, but only if `from` and `to` are not
// equal (#1613).
var radius = Size.read(arguments),
isZero = Numerical.isZero;
// If rx = 0 or ry = 0 then this arc is treated as a
@ -2565,11 +2566,12 @@ new function() { // PostScript-style drawing commands
extent += extent < 0 ? 360 : -360;
}
}
if (extent) {
var epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON,
ext = abs(extent),
// Calculate the amount of segments required to approximate over
// Calculate amount of segments required to approximate over
// `extend` degrees (extend / 90), but prevent ceil() from
// rounding up small imprecisions by subtracting epsilon first.
// rounding up small imprecisions by subtracting epsilon.
count = ext >= 360 ? 4 : Math.ceil((ext - epsilon) / 90),
inc = extent / count,
half = inc * Math.PI / 360,
@ -2606,6 +2608,7 @@ new function() { // PostScript-style drawing commands
}
// Add all segments at once at the end for higher performance
this._add(segments);
}
},
lineBy: function(/* to */) {

View file

@ -645,3 +645,11 @@ test('Path#arcTo(through, to) is on through point side (#1477)', function() {
path.arcTo(p2, p3);
equals(true, path.segments[1].point.x > p1.x);
});
test('Path#arcTo(to, radius, rotation, clockwise, large) when from and to are equal (#1613)', function(){
var point = new Point(10,10);
var path = new Path();
path.moveTo(point);
path.arcTo(point, new Size(10), 0, true, true);
expect(0);
});