Skip to content

Commit

Permalink
Fixed angle calculation with zero length curve control point.
Browse files Browse the repository at this point in the history
Fixes #477
  • Loading branch information
GreLI committed Jan 6, 2016
1 parent 0d91a04 commit 1b0051a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions plugins/convertPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function filters(path, params) {
suffix = stringify([nextLonghand]);
}
if (isConvex(nextData) && isArc(nextData, relCircle)) {
angle += findArcAngle(nextData);
angle += findRelArcAngle(nextData, relCircle);
if (angle - 2 * Math.PI > 1e-3) break; // more than 360°
if (angle > Math.PI) arc.data[3] = 1;
arcCurves.push(next);
Expand Down Expand Up @@ -928,7 +928,27 @@ function findArcAngle(curve) {
y2 = curve[3] - curve[5];

return Math.PI - Math.acos(
(x1 * x2 + y1 * y2 ) /
(x1 * x2 + y1 * y2) /
Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2))
);
}

/**
* Finds angle of a curve fitting the given arc.
* @param {Array} curve
* @param {Object} relCircle
* @return {Number} angle
*/

function findRelArcAngle(curve, relCircle) {
var x1 = relCircle.center[0],
y1 = relCircle.center[1],
x2 = curve[4] - relCircle.center[0],
y2 = curve[5] - relCircle.center[1];

return Math.PI - Math.acos(
(x1 * x2 + y1 * y2) /
Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2))
);
}
Expand Down
2 changes: 2 additions & 0 deletions test/plugins/convertPathData.14.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b0051a

Please sign in to comment.