From 1bacbc32e9ab25443e7fa07374fcb8684491df4d Mon Sep 17 00:00:00 2001 From: hkrish Date: Sun, 29 Dec 2013 13:03:39 +0100 Subject: [PATCH] Link previous & next curves while returning monotone curves --- src/path/Path.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/path/Path.js b/src/path/Path.js index 63fecfd9..41747448 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1718,6 +1718,7 @@ var Path = PathItem.extend(/** @lends Path# */{ */ _getMonotoneCurves: function() { var monoCurves = this._monotoneCurves, + lastCurve, // TODO: replace instances with constants ( /*#=*/ ?) INCREASING = 1, DECREASING = -1, @@ -1733,7 +1734,13 @@ var Path = PathItem.extend(/** @lends Path# */{ } else if (y0 > y1) { dir = DECREASING; } + // Add a reference to subsequent curves v.push(dir); + if (lastCurve) { + v[9] = lastCurve; + lastCurve[10] = v; + } + lastCurve = v; monoCurves.push(v); } // Handle bezier curves. We need to chop them into smaller curves @@ -1785,7 +1792,11 @@ var Path = PathItem.extend(/** @lends Path# */{ } for (i = 0, li = curves.length; i < li; i++) { crv = curves[i]; + // Filter out curves of zero length vals = crv.getValues(); + if (Curve.getLength(vals) === 0) + continue; + // Handle linear and cubic curves seperately if (crv.isLinear()) { insertValues(vals); } else { @@ -1799,6 +1810,10 @@ var Path = PathItem.extend(/** @lends Path# */{ } } } + // Link, first and last curves + lastCurve = monoCurves[monoCurves.length - 1]; + monoCurves[0][9] = lastCurve; + lastCurve.push(monoCurves[0]); } return monoCurves; },