mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Define Shape#size and #radius.
This commit is contained in:
parent
2b236a3da8
commit
9311b38894
1 changed files with 36 additions and 0 deletions
|
@ -27,6 +27,42 @@ var Shape = Item.extend(/** @lends Shape# */{
|
|||
this._size = size;
|
||||
},
|
||||
|
||||
/**
|
||||
* The size of the shape.
|
||||
*
|
||||
* @type Size
|
||||
* @bean
|
||||
*/
|
||||
getSize: function() {
|
||||
var size = this._size;
|
||||
return new LinkedSize(size.width, size.height, this, 'setSize');
|
||||
},
|
||||
|
||||
setSize: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
if (!this._size.equals(size)) {
|
||||
this._size.set(size.width, size.height);
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The radius of the shape if it is a circle.
|
||||
*
|
||||
* @type Size
|
||||
* @bean
|
||||
*/
|
||||
getRadius: function() {
|
||||
var size = this._size;
|
||||
// Average half of width & height for radius...
|
||||
return (size.width + size.height) / 4;
|
||||
},
|
||||
|
||||
setRadius: function(radius) {
|
||||
var size = radius * 2;
|
||||
this.setSize(size, size);
|
||||
},
|
||||
|
||||
_draw: function(ctx, param) {
|
||||
var style = this._style,
|
||||
size = this._size,
|
||||
|
|
Loading…
Reference in a new issue