Prevent Path#getStrokeBounds() from accidentally modifying segments.

Closes #1102
This commit is contained in:
Jürg Lehni 2016-07-13 18:43:15 +02:00
parent 8a45c5dff9
commit 6ca3bb1c63

View file

@ -2703,22 +2703,19 @@ statics: {
_addBevelJoin: function(segment, join, radius, miterLimit, matrix, _addBevelJoin: function(segment, join, radius, miterLimit, matrix,
strokeMatrix, addPoint, isArea) { strokeMatrix, addPoint, isArea) {
// Handles both 'bevel' and 'miter' joins, as they share a lot of code. // Handles both 'bevel' and 'miter' joins, as they share a lot of code,
// using different matrices to transform segment points and stroke
// vectors to support Style#strokeScaling.
var curve2 = segment.getCurve(), var curve2 = segment.getCurve(),
curve1 = curve2.getPrevious(), curve1 = curve2.getPrevious(),
point = curve2.getPointAtTime(0), point = curve2.getPoint1().transform(matrix),
normal1 = curve1.getNormalAtTime(1), normal1 = curve1.getNormalAtTime(1).multiply(radius)
normal2 = curve2.getNormalAtTime(0), .transform(strokeMatrix),
step = normal1.getDirectedAngle(normal2) < 0 ? -radius : radius; normal2 = curve2.getNormalAtTime(0).multiply(radius)
normal1.setLength(step); .transform(strokeMatrix);
normal2.setLength(step); if (normal1.getDirectedAngle(normal2) < 0) {
// use different matrices to transform segment points and stroke vectors normal1 = normal1.negate();
// to support Style#strokeScaling. normal2 = normal2.negate();
if (matrix)
matrix._transformPoint(point, point);
if (strokeMatrix) {
strokeMatrix._transformPoint(normal1, normal1);
strokeMatrix._transformPoint(normal2, normal2);
} }
if (isArea) { if (isArea) {
addPoint(point); addPoint(point);
@ -2748,16 +2745,13 @@ statics: {
_addSquareCap: function(segment, cap, radius, matrix, strokeMatrix, _addSquareCap: function(segment, cap, radius, matrix, strokeMatrix,
addPoint, isArea) { addPoint, isArea) {
// Handles both 'square' and 'butt' caps, as they share a lot of code. // Handles both 'square' and 'butt' caps, as they share a lot of code.
// Calculate the corner points of butt and square caps // Calculate the corner points of butt and square caps, using different
var point = segment._point, // matrices to transform segment points and stroke vectors to support
// Style#strokeScaling.
var point = segment._point.transform(matrix),
loc = segment.getLocation(), loc = segment.getLocation(),
normal = loc.getNormal().multiply(radius); // normal is normalized // NOTE: normal is normalized, so multiply instead of normalize.
// use different matrices to transform segment points and stroke vectors normal = loc.getNormal().multiply(radius).transform(strokeMatrix);
// to support Style#strokeScaling.
if (matrix)
matrix._transformPoint(point, point);
if (strokeMatrix)
strokeMatrix._transformPoint(normal, normal);
if (isArea) { if (isArea) {
addPoint(point.subtract(normal)); addPoint(point.subtract(normal));
addPoint(point.add(normal)); addPoint(point.add(normal));