Implement Shape#toPath(), analogue to Path#toShape().

This way is much simpler though.
This commit is contained in:
Jürg Lehni 2013-10-16 23:44:50 +02:00
parent 51cf1cfec6
commit 9956a6ff51
2 changed files with 20 additions and 0 deletions

View file

@ -13,6 +13,8 @@
});
var shape = path.toShape();
shape.position += [200, 0];
var path = shape.toPath();
path.position += [200, 0];
var path = new Path.Ellipse({
center: [100, 200],
@ -24,6 +26,8 @@
path.rotate(20);
var shape = path.toShape();
shape.position += [200, 0];
var path = shape.toPath();
path.position += [200, 0];
var path = new Path.Rectangle({
center: [100, 300],
@ -35,6 +39,8 @@
path.rotate(-20);
var shape = path.toShape();
shape.position += [200, 0];
var path = shape.toPath();
path.position += [200, 0];
var path = new Path.Rectangle({
center: [100, 400],
@ -47,6 +53,8 @@
path.rotate(20);
var shape = path.toShape();
shape.position += [200, 0];
var path = shape.toPath();
path.position += [200, 0];
</script>
</head>
<body>

View file

@ -118,6 +118,18 @@ var Shape = Item.extend(/** @lends Shape# */{
return false;
},
// DOCS: #toPath()
toPath: function() {
var path = new Path[Base.capitalize(this._shape)]({
center: new Point(),
size: this._size,
radius: this._radius
});
path.transform(this._matrix);
path.setStyle(this._style);
return path;
},
_draw: function(ctx, param) {
var style = this._style,
fillColor = style.getFillColor(),