Skip to content

Commit

Permalink
Fixestocachepolygon (#3490)
Browse files Browse the repository at this point in the history
* fixes polygon and other subclasses
* fixed polygon fill
  • Loading branch information
asturur authored Dec 3, 2016
1 parent 6074660 commit 81609a8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/shapes/circle.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push(
'radius'
);

/**
* Circle class
* @class fabric.Circle
Expand Down Expand Up @@ -47,6 +52,8 @@
*/
endAngle: pi * 2,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Object} [options] Options object
Expand Down
8 changes: 8 additions & 0 deletions src/shapes/ellipse.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push(
'rx',
'ry'
);

/**
* Ellipse class
* @class fabric.Ellipse
Expand Down Expand Up @@ -41,6 +47,8 @@
*/
ry: 0,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Object} [options] Options object
Expand Down
10 changes: 10 additions & 0 deletions src/shapes/line.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push(
'x1',
'x2',
'y1',
'y2'
);

/**
* Line class
* @class fabric.Line
Expand Down Expand Up @@ -55,6 +63,8 @@
*/
y2: 0,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Array} [points] Array of points
Expand Down
5 changes: 5 additions & 0 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push('path');

/**
* Path class
* @class fabric.Path
Expand Down Expand Up @@ -66,6 +69,8 @@
*/
minY: 0,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Array|String} path Path data (sequence of coordinates and corresponding "command" tokens)
Expand Down
15 changes: 10 additions & 5 deletions src/shapes/polygon.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push('points');

/**
* Polygon class
* @class fabric.Polygon
Expand Down Expand Up @@ -49,6 +52,8 @@
*/
minY: 0,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Array} points Array of points
Expand Down Expand Up @@ -151,20 +156,20 @@
* @param {Boolean} noTransform
*/
commonRender: function(ctx, noTransform) {
var point, len = this.points.length;
var point, len = this.points.length,
x = noTransform ? 0 : this.pathOffset.x,
y = noTransform ? 0 : this.pathOffset.y;

if (!len || isNaN(this.points[len - 1].y)) {
// do not draw if no points or odd points
// NaN comes from parseFloat of a empty string in parser
return false;
}

noTransform || ctx.translate(-this.pathOffset.x, -this.pathOffset.y);
ctx.beginPath();
ctx.moveTo(this.points[0].x, this.points[0].y);
ctx.moveTo(this.points[0].x - x, this.points[0].y - y);
for (var i = 0; i < len; i++) {
point = this.points[i];
ctx.lineTo(point.x, point.y);
ctx.lineTo(point.x - x, point.y - y);
}
return true;
},
Expand Down
5 changes: 5 additions & 0 deletions src/shapes/polyline.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
return;
}

var cacheProperties = fabric.Object.prototype.cacheProperties.concat();
cacheProperties.push('points');

/**
* Polyline class
* @class fabric.Polyline
Expand Down Expand Up @@ -45,6 +48,8 @@
*/
minY: 0,

cacheProperties: cacheProperties,

/**
* Constructor
* @param {Array} points Array of points (where each point is an object with x and y)
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/rect.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

var stateProperties = fabric.Object.prototype.stateProperties.concat();
stateProperties.push('rx', 'ry', 'x', 'y');
stateProperties.push('rx', 'ry');

/**
* Rectangle class
Expand Down

0 comments on commit 81609a8

Please sign in to comment.