Path 代理,可以在buildPath
中用于替代ctx
, 会保存每个path操作的命令到pathCommands属性中
可以用于 isInsidePath 判断以及获取boundingRect
Example
var SomeShape = function() {
this._pathProxy = new PathProxy();
...
}
SomeShape.prototype.buildPath = function(ctx, style) {
this._pathProxy.begin(ctx);
.moveTo(style.x, style.y);
.lineTo(style.x1, style.y1);
...
.closePath();
},
SomeShape.prototype.getRect = function(style) {
if (!style._rect) {
// 这里必须要在 buildPath 之后才能调用
style._rect = this._pathProxy.fastBoundingRect();
}
return this.style._rect;
},
SomeShape.prototype.isCover = function(x, y) {
var rect = this.getRect(this.style);
if (x >= rect.x
&& x <= (rect.x + rect.width)
&& y >= rect.y
&& y <= (rect.y + rect.height)
) {
return area.isInsidePath(
this._pathProxy.pathCommands, 0, 'fill', x, y
);
}
}