mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-14 00:39:57 -04:00
Clean up math function injection in Point and Size.
This commit is contained in:
parent
3a1fa3171b
commit
5e7209a7bb
2 changed files with 134 additions and 137 deletions
|
@ -776,6 +776,65 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @return {Boolean} {@true the point is selected}
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@grouptitle Math Functions}
|
||||
*
|
||||
* Returns a new point with rounded {@link #x} and {@link #y} values. The
|
||||
* object itself is not modified!
|
||||
*
|
||||
* @name Point#round
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var roundPoint = point.round();
|
||||
* console.log(roundPoint); // {x: 10, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the nearest greater non-fractional values to the
|
||||
* specified {@link #x} and {@link #y} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Point#ceil
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var ceilPoint = point.ceil();
|
||||
* console.log(ceilPoint); // {x: 11, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the nearest smaller non-fractional values to the
|
||||
* specified {@link #x} and {@link #y} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Point#floor
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var floorPoint = point.floor();
|
||||
* console.log(floorPoint); // {x: 10, y: 10}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the absolute values of the specified {@link #x}
|
||||
* and {@link #y} values. The object itself is not modified!
|
||||
*
|
||||
* @name Point#abs
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(-5, 10);
|
||||
* var absPoint = point.abs();
|
||||
* console.log(absPoint); // {x: 5, y: 10}
|
||||
*/
|
||||
statics: /** @lends Point */{
|
||||
/**
|
||||
* Returns a new point object with the smallest {@link #x} and
|
||||
|
@ -843,74 +902,13 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
return new Point(Math.random(), Math.random());
|
||||
}
|
||||
}
|
||||
}, new function() { // Scope for injecting round, ceil, floor, abs:
|
||||
/**
|
||||
* {@grouptitle Math Functions}
|
||||
*
|
||||
* Returns a new point with rounded {@link #x} and {@link #y} values. The
|
||||
* object itself is not modified!
|
||||
*
|
||||
* @name Point#round
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var roundPoint = point.round();
|
||||
* console.log(roundPoint); // {x: 10, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the nearest greater non-fractional values to the
|
||||
* specified {@link #x} and {@link #y} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Point#ceil
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var ceilPoint = point.ceil();
|
||||
* console.log(ceilPoint); // {x: 11, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the nearest smaller non-fractional values to the
|
||||
* specified {@link #x} and {@link #y} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Point#floor
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(10.2, 10.9);
|
||||
* var floorPoint = point.floor();
|
||||
* console.log(floorPoint); // {x: 10, y: 10}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new point with the absolute values of the specified {@link #x}
|
||||
* and {@link #y} values. The object itself is not modified!
|
||||
*
|
||||
* @name Point#abs
|
||||
* @function
|
||||
* @return {Point}
|
||||
*
|
||||
* @example
|
||||
* var point = new Point(-5, 10);
|
||||
* var absPoint = point.abs();
|
||||
* console.log(absPoint); // {x: 5, y: 10}
|
||||
*/
|
||||
|
||||
return Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
||||
var op = Math[name];
|
||||
this[name] = function() {
|
||||
return new Point(op(this.x), op(this.y));
|
||||
};
|
||||
}, {});
|
||||
});
|
||||
}, Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
||||
// Inject round, ceil, floor, abs:
|
||||
var op = Math[name];
|
||||
this[name] = function() {
|
||||
return new Point(op(this.x), op(this.y));
|
||||
};
|
||||
}, {}));
|
||||
|
||||
/**
|
||||
* @name LinkedPoint
|
||||
|
|
|
@ -380,6 +380,67 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
return isNaN(this.width) || isNaN(this.height);
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Math Functions}
|
||||
*
|
||||
* Returns a new size with rounded {@link #width} and {@link #height}
|
||||
* values. The object itself is not modified!
|
||||
*
|
||||
* @name Size#round
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var roundSize = size.round();
|
||||
* console.log(roundSize); // {x: 10, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the nearest greater non-fractional values to the
|
||||
* specified {@link #width} and {@link #height} values. The object itself is
|
||||
* not modified!
|
||||
*
|
||||
* @name Size#ceil
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var ceilSize = size.ceil();
|
||||
* console.log(ceilSize); // {x: 11, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the nearest smaller non-fractional values to the
|
||||
* specified {@link #width} and {@link #height} values. The object itself is
|
||||
* not modified!
|
||||
*
|
||||
* @name Size#floor
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var floorSize = size.floor();
|
||||
* console.log(floorSize); // {x: 10, y: 10}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the absolute values of the specified
|
||||
* {@link #width} and {@link #height} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Size#abs
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(-5, 10);
|
||||
* var absSize = size.abs();
|
||||
* console.log(absSize); // {x: 5, y: 10}
|
||||
*/
|
||||
|
||||
statics: /** @lends Size */{
|
||||
/**
|
||||
* Returns a new size object with the smallest {@link #width} and
|
||||
|
@ -439,75 +500,13 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
return new Size(Math.random(), Math.random());
|
||||
}
|
||||
}
|
||||
}, new function() { // Scope for injecting round, ceil, floor, abs:
|
||||
|
||||
/**
|
||||
* {@grouptitle Math Functions}
|
||||
*
|
||||
* Returns a new size with rounded {@link #width} and {@link #height} values.
|
||||
* The object itself is not modified!
|
||||
*
|
||||
* @name Size#round
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var roundSize = size.round();
|
||||
* console.log(roundSize); // {x: 10, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the nearest greater non-fractional values to the
|
||||
* specified {@link #width} and {@link #height} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Size#ceil
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var ceilSize = size.ceil();
|
||||
* console.log(ceilSize); // {x: 11, y: 11}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the nearest smaller non-fractional values to the
|
||||
* specified {@link #width} and {@link #height} values. The object itself is not
|
||||
* modified!
|
||||
*
|
||||
* @name Size#floor
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(10.2, 10.9);
|
||||
* var floorSize = size.floor();
|
||||
* console.log(floorSize); // {x: 10, y: 10}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new size with the absolute values of the specified {@link #width}
|
||||
* and {@link #height} values. The object itself is not modified!
|
||||
*
|
||||
* @name Size#abs
|
||||
* @function
|
||||
* @return {Size}
|
||||
*
|
||||
* @example
|
||||
* var size = new Size(-5, 10);
|
||||
* var absSize = size.abs();
|
||||
* console.log(absSize); // {x: 5, y: 10}
|
||||
*/
|
||||
|
||||
return Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
||||
var op = Math[name];
|
||||
this[name] = function() {
|
||||
return new Size(op(this.width), op(this.height));
|
||||
};
|
||||
}, {});
|
||||
});
|
||||
}, Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
||||
// Inject round, ceil, floor, abs:
|
||||
var op = Math[name];
|
||||
this[name] = function() {
|
||||
return new Size(op(this.width), op(this.height));
|
||||
};
|
||||
}, {}));
|
||||
|
||||
/**
|
||||
* @name LinkedSize
|
||||
|
|
Loading…
Reference in a new issue