From f69153844ba6ea3f5438bf2066fcc8930ff269fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 28 Apr 2011 13:04:12 +0100 Subject: [PATCH 1/3] Make #setContextStyles() a 'protected' function. --- src/path/CompoundPath.js | 2 +- src/path/Path.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 15d17f52..656e8311 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -58,7 +58,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ param.compound = true; for (var i = 0, l = this.children.length; i < l; i++) Item.draw(this.children[i], ctx, param); - firstChild.setContextStyles(ctx); + firstChild._setStyles(ctx); var fillColor = firstChild.getFillColor(), strokeColor = firstChild.getStrokeColor(); if (fillColor) { diff --git a/src/path/Path.js b/src/path/Path.js index dd7e5d10..e59e4511 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -385,7 +385,7 @@ var Path = this.Path = PathItem.extend({ var fillColor = this.getFillColor(), strokeColor = this.getStrokeColor(); if (!param.compound && (fillColor || strokeColor)) { - this.setContextStyles(ctx); + this._setStyles(ctx); ctx.save(); // If the path only defines a strokeColor or a fillColor, // draw it directly with the globalAlpha set, otherwise @@ -582,7 +582,7 @@ var Path = this.Path = PathItem.extend({ } }, - setContextStyles: function(ctx) { + _setStyles: function(ctx) { for (var i in styles) { var style = this[i](); if (style) From 0d697403b51959df6c28c35277e029a75af1f2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 28 Apr 2011 13:12:21 +0100 Subject: [PATCH 2/3] Clean up Path#curveTo() code. --- src/path/Path.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index e59e4511..fc639e1a 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -646,9 +646,9 @@ var Path = this.Path = PathItem.extend({ // and the cubic is A B C D, // B = E + 1/3 (A - E) // C = E + 1/3 (D - E) - var current = getCurrentSegment(this); + var current = getCurrentSegment(this)._point; this.cubicCurveTo( - handle.add(current._point.subtract(handle).multiply(1/3)), + handle.add(current.subtract(handle).multiply(1/3)), handle.add(to.subtract(handle).multiply(1/3)), to ); @@ -657,15 +657,13 @@ var Path = this.Path = PathItem.extend({ curveTo: function(through, to, parameter) { through = Point.read(arguments, 0, 1); to = Point.read(arguments, 1, 1); - var t = parameter; - if (t == null) - t = 0.5; - var current = getCurrentSegment(this)._point; - // handle = (through - (1 - t)^2 * current - t^2 * to) / - // (2 * (1 - t) * t) - var t1 = 1 - t, - handle = through.subtract(current.multiply(t1 * t1)).subtract( - to.multiply(t * t)).divide(2 * t * t1); + var t = Base.pick(parameter, 0.5), + t1 = 1 - t, + current = getCurrentSegment(this)._point, + // handle = (through - (1 - t)^2 * current - t^2 * to) / + // (2 * (1 - t) * t) + handle = through.subtract(current.multiply(t1 * t1)) + .subtract(to.multiply(t * t)).divide(2 * t * t1); if (handle.isNaN()) throw new Error( "Cannot put a curve through points with parameter=" + t); @@ -673,9 +671,9 @@ var Path = this.Path = PathItem.extend({ }, arcTo: function(to, clockwise) { - var through, to; // Get the start point: - var current = getCurrentSegment(this); + var current = getCurrentSegment(this), + through; if (arguments[1] && typeof arguments[1] != 'boolean') { through = Point.read(arguments, 0, 1); to = Point.read(arguments, 1, 1); From 115ef45464416a6a9922294f09b0e15ae196ed31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 28 Apr 2011 13:13:33 +0100 Subject: [PATCH 3/3] Remove unnecessary .0 since numbers are all the same in JavaScript. --- src/basic/Point.js | 2 +- src/path/Path.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/Point.js b/src/basic/Point.js index 10901f14..79ad441d 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -172,7 +172,7 @@ var Point = this.Point = Base.extend({ } } else { var scale = length / this.getLength(); - if (scale == 0.0) { + if (scale == 0) { // Calculate angle now, so it will be preserved even when // x and y are 0 this.getAngle(); diff --git a/src/path/Path.js b/src/path/Path.js index fc639e1a..97cff426 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -463,7 +463,7 @@ var Path = this.Path = PathItem.extend({ // Decomposition and forward substitution. for (var i = 1; i < n; i++) { tmp[i] = 1 / b; - b = (i < n - 1 ? 4.0 : 2.0) - tmp[i]; + b = (i < n - 1 ? 4 : 2) - tmp[i]; x[i] = (rhs[i] - x[i - 1]) / b; } // Back-substitution. @@ -718,7 +718,7 @@ var Path = this.Path = PathItem.extend({ diff -= Math.PI * 2; extent -= angle; - if (extent <= 0.0) + if (extent <= 0) extent += Math.PI * 2; if (diff < 0) extent = Math.PI * 2 - extent;