Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jürg Lehni 2011-04-28 13:23:27 +01:00
commit 037adc074d
2 changed files with 19 additions and 23 deletions

View file

@ -396,10 +396,7 @@ var Point = this.Point = Base.extend({
* print(roundPoint); // { x: 10.0, y: 11.0 }
* </code>
*/
round: function() {
return Point.create(Math.round(this.x), Math.round(this.y));
},
/**
* 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
@ -412,10 +409,7 @@ var Point = this.Point = Base.extend({
* print(ceilPoint); // { x: 11.0, y: 11.0 }
* </code>
*/
ceil: function() {
return Point.create(Math.ceil(this.x), Math.ceil(this.y));
},
/**
* 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
@ -428,10 +422,7 @@ var Point = this.Point = Base.extend({
* print(floorPoint); // { x: 10.0, y: 10.0 }
* </code>
*/
floor: function() {
return Point.create(Math.floor(this.x), Math.floor(this.y));
},
/**
* Returns a new point with the absolute values of the specified {@link #x}
* and {@link #y} values. The object itself is not modified!
@ -443,10 +434,7 @@ var Point = this.Point = Base.extend({
* print(absPoint); // { x: 5.0, y: 10.0 }
* </code>
*/
abs: function() {
return Point.create(Math.abs(this.x), Math.abs(this.y));
},
/**
* {@grouptitle Vectorial Math Functions}
*
@ -571,6 +559,13 @@ var Point = this.Point = Base.extend({
return Point.create(Math.random(), Math.random());
}
}
}, new function() { // Scope for injecting intersect, unite and include.
return Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
var op = Math[name];
this[name] = function() {
return Point.create(op(this.x), op(this.y));
};
}, {});
});
/**

View file

@ -209,23 +209,24 @@ var Rectangle = this.Rectangle = Base.extend({
}
}, new function() { // Scope for injecting intersect, unite and include.
return Base.each({
// 1st = intersect, 2nd = isPoint
intersect: [true, false],
unite: [false, false],
include: [false, true]
}, function(values, name) {
var intersect = values[0],
isPoint = values[1],
math1 = Math[intersect ? 'max' : 'min'],
math2 = Math[intersect ? 'min' : 'max'];
op1 = Math[intersect ? 'max' : 'min'],
op2 = Math[intersect ? 'min' : 'max'];
this[name] = function() {
var object = (isPoint ? Point : Rectangle).read(arguments),
x1 = math1(this.x, object.x),
y1 = math1(this.y, object.y),
x2 = math2(this.x + this.width,
x1 = op1(this.x, object.x),
y1 = op1(this.y, object.y),
x2 = op2(this.x + this.width,
object.x + (isPoint ? 0 : object.width)),
y2 = math2(this.y + this.height,
y2 = op2(this.y + this.height,
object.y + (isPoint ? 0 : object.height));
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
};
}, {});
}, new function() {