Optimize Path#draw.

This commit is contained in:
Jonathan Puckey 2011-02-20 20:45:50 +01:00
parent cb40d3f6f4
commit f83309d6b7

View file

@ -354,31 +354,42 @@ Path = PathItem.extend({
draw: function(ctx, compound) { draw: function(ctx, compound) {
if (!this.visible) return; if (!this.visible) return;
if(!compound) if (!compound)
ctx.beginPath(); ctx.beginPath();
var cp1;
for (var i = 0, l = this._segments.length; i < l; i++) { var segments = this._segments;
var segment = this._segments[i]; var length = segments.length;
var point = segment.point; for (var i = 0; i < length; i++) {
var handleIn = segment.handleIn.add(point); var segment = segments[i];
var handleOut = segment.handleOut.add(point); var x = segment.point.x;
var y = segment.point.y;
var handleIn = segment.handleIn;
if (i == 0) { if (i == 0) {
ctx.moveTo(point.x, point.y); ctx.moveTo(x, y);
} else { } else {
ctx.bezierCurveTo(cp1.x, cp1.y, handleIn.x, handleIn.y, if (handleOut.isZero() && handleIn.isZero()) {
point.x, point.y); ctx.lineTo(x, y);
} else {
ctx.bezierCurveTo(
outX, outY,
handleIn.x + x, handleIn.y + y,
x, y
);
}
} }
cp1 = handleOut; var handleOut = segment.handleOut;
var outX = handleOut.x + x;
var outY = handleOut.y + y;
} }
if (this.closed && this._segments.length > 1) { if (this.closed && length > 1) {
var segment = this._segments[0]; var segment = segments[0];
var point = segment.point; var x = segment.point.x;
var handleIn = segment.handleIn.add(point); var y = segment.point.y;
ctx.bezierCurveTo(cp1.x, cp1.y, handleIn.x, handleIn.y, var handleIn = segment.handleIn;
point.x, point.y); ctx.bezierCurveTo(outX, outY, handleIn.x + x, handleIn.y + y, x, y);
ctx.closePath(); ctx.closePath();
} }
if(!compound) { if (!compound) {
this.setCtxStyles(ctx); this.setCtxStyles(ctx);
ctx.save(); ctx.save();
ctx.globalAlpha = this.opacity; ctx.globalAlpha = this.opacity;