Skip to content

Commit ff8c4cd

Browse files
committed
Fix Path#strokeBounds for open paths
Closes #1817
1 parent fefea31 commit ff8c4cd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/path/Curve.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,11 @@ statics: /** @lends Curve */{
867867
if (v1 < v0 != v1 < v3 && v2 < v0 != v2 < v3) {
868868
// If the values of a curve are sorted, the extrema are simply
869869
// the start and end point.
870-
add(v0, padding);
871-
add(v3, padding);
870+
// Only add strokeWidth to bounds for points which lie within 0
871+
// < t < 1. The corner cases for cap and join are handled in
872+
// getStrokeBounds()
873+
add(v0, 0);
874+
add(v3, 0);
872875
} else {
873876
// Calculate derivative of our bezier polynomial, divided by 3.
874877
// Doing so allows for simpler calculations of a, b, c and leads
@@ -882,9 +885,7 @@ statics: /** @lends Curve */{
882885
// with radii in getStrokeBounds()
883886
tMin = /*#=*/Numerical.CURVETIME_EPSILON,
884887
tMax = 1 - tMin;
885-
// Only add strokeWidth to bounds for points which lie within 0
886-
// < t < 1 The corner cases for cap and join are handled in
887-
// getStrokeBounds()
888+
// See above for an explanation of padding = 0 here:
888889
add(v3, 0);
889890
for (var i = 0; i < count; i++) {
890891
var t = roots[i],

test/tests/Item_Bounds.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,21 @@ test('group.internalBounds with child and child.applyMatrix = false (#1250)', fu
790790
'group.internalBounds after scaling item1');
791791
});
792792

793-
test('#1561 item._globalMatrix on item after empty symbol', function(){
793+
test('item._globalMatrix on item after empty symbol (#1561)', function() {
794794
var symbol = new SymbolItem(new Path());
795795
symbol.opacity = 0.5;
796796
symbol.skew(10);
797797
var item = new Path.Circle(new Point(0,0), 10);
798798
view.update();
799799
equals(item._globalMatrix, new Matrix());
800800
});
801+
802+
test('path.strokeBounds of open, circular arc (#1817)', function() {
803+
var circle = new Path({
804+
pathData: 'M8,16c0,-4.4 3.6,-8 8,-8c4.4,0 8,3.6 8,8',
805+
strokeWidth: 8,
806+
strokeColor: 'red'
807+
});
808+
equals(circle.strokeBounds, new Rectangle(4, 4, 24, 12),
809+
'circle.strokeBounds');
810+
});

0 commit comments

Comments
 (0)