Merge remote branch 'origin/master'

This commit is contained in:
Jonathan Puckey 2011-03-07 18:39:25 +01:00
commit 6b5ce7c18c
4 changed files with 50 additions and 35 deletions

View file

@ -246,20 +246,20 @@ var Rectangle = this.Rectangle = Base.extend({
// by checking the first character for [R]ight or [L]eft; // by checking the first character for [R]ight or [L]eft;
var xFirst = /^[RL]/.test(key); var xFirst = /^[RL]/.test(key);
// Rename Center to CenterX or CenterY: // Rename Center to CenterX or CenterY:
if (index >= 4) parts[1] += xFirst ? 'Y' : 'X'; if (index >= 4)
var xIndex = xFirst ? 0 : 1, parts[1] += xFirst ? 'Y' : 'X';
yIndex = xFirst ? 1 : 0, var x = parts[xFirst ? 0 : 1],
getX = 'get' + parts[xIndex], y = parts[xFirst ? 1 : 0],
getY = 'get' + parts[yIndex], getX = 'get' + x,
setX = 'set' + parts[xIndex], getY = 'get' + y,
setY = 'set' + parts[yIndex]; setX = 'set' + x,
setY = 'set' + y;
this['get' + key] = function() { this['get' + key] = function() {
return Point.create(this[getX](), this[getY]()); return Point.create(this[getX](), this[getY]());
}; };
this['set' + key] = function(value) { this['set' + key] = function(value) {
var pt = Point.read(arguments); var pt = Point.read(arguments);
return this[setX](pt.x) // Note: chaining here! return this[setX](pt.x)[setY](pt.y); // Note: chaining here!
[setY](pt.y);
}; };
}, { beans: true }); }, { beans: true });
}); });

View file

@ -29,9 +29,8 @@ var Color = this.Color = Base.extend({
}, },
setAlpha: function(alpha) { setAlpha: function(alpha) {
if (alpha < 0) this._alpha = 0; this._alpha = Math.min(Math.max(alpha, 0), 1);
else if (alpha > 1) this._alpha = 1; this._alpha = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
else this._alpha = alpha;
this._cssString = null; this._cssString = null;
}, },
@ -49,9 +48,14 @@ var Color = this.Color = Base.extend({
} }
}, new function() { }, new function() {
function colorToHsb(color) { function colorToHsb(color) {
var r = color.getRed(), g = color.getGreen(), b = color.getBlue(), var r = color.getRed(),
max = Math.max(r, g, b), min = Math.min(r, g, b), g = color.getGreen(),
delta = max - min, hue, saturation = (max != 0) ? delta / max : 0, b = color.getBlue(),
max = Math.max(r, g, b)
min = Math.min(r, g, b),
delta = max - min,
hue,
saturation = (max != 0) ? delta / max : 0,
brightness = max; brightness = max;
if (saturation == 0) { if (saturation == 0) {
hue = 0; hue = 0;
@ -59,19 +63,24 @@ var Color = this.Color = Base.extend({
var rr = (max - r) / delta, var rr = (max - r) / delta,
gr = (max - g) / delta, gr = (max - g) / delta,
br = (max - b) / delta; br = (max - b) / delta;
if (r == max) hue = br - gr; hue = r == max
else if (g == max) hue = 2 + rr - br; ? br - gr
else hue = 4 + gr - rr; : g == max
? 2 + rr - br
: 4 + gr - rr;
hue /= 6; hue /= 6;
if (hue < 0) hue++; if (hue < 0)
hue++;
} }
return [hue * 360, saturation, brightness ]; return [hue * 360, saturation, brightness];
} }
function hsbToRgb(hue, saturation, brightness) { function hsbToRgb(hue, saturation, brightness) {
if(hue < 0) hue += 360; if (hue < 0)
hue += 360;
hue = hue % 360; hue = hue % 360;
var f = hue % 60, p = (brightness * (1 - saturation)) / 1, var f = hue % 60,
p = (brightness * (1 - saturation)) / 1,
q = (brightness * (60 - saturation * f)) / 60, q = (brightness * (60 - saturation * f)) / 60,
t = (brightness * (60 - saturation * (60 - f))) / 60; t = (brightness * (60 - saturation * (60 - f))) / 60;
switch (Math.floor(hue / 60)) { switch (Math.floor(hue / 60)) {

View file

@ -212,6 +212,7 @@ var Curve = this.Curve = Base.extend({
+ ' }'; + ' }';
} }
}, new function() { }, new function() {
function evaluate(that, t, type) { function evaluate(that, t, type) {
// Calculate the polynomial coefficients. caution: handles are relative // Calculate the polynomial coefficients. caution: handles are relative
// to points // to points
@ -269,6 +270,7 @@ var Curve = this.Curve = Base.extend({
// the x and y coordinates: // the x and y coordinates:
x = (3 * ax * t + 2 * bx) * t + cx, x = (3 * ax * t + 2 * bx) * t + cx,
y = (3 * ay * t + 2 * by) * t + cy; y = (3 * ay * t + 2 * by) * t + cy;
break;
} }
} }
// The normal is simply the rotated tangent: // The normal is simply the rotated tangent:

View file

@ -21,9 +21,9 @@ var Numerical = new function() {
-0.9324695142, 0.9324695142, -0.6612093865, 0.6612093865, -0.2386191861, 0.2386191861, -0.9324695142, 0.9324695142, -0.6612093865, 0.6612093865, -0.2386191861, 0.2386191861,
-0.9491079123, 0.9491079123, -0.7415311856, 0.7415311856, -0.4058451514, 0.4058451514, 0.0000000000, -0.9491079123, 0.9491079123, -0.7415311856, 0.7415311856, -0.4058451514, 0.4058451514, 0.0000000000,
-0.9602898565, 0.9602898565, -0.7966664774, 0.7966664774, -0.5255324099, 0.5255324099, -0.1834346425, 0.1834346425 -0.9602898565, 0.9602898565, -0.7966664774, 0.7966664774, -0.5255324099, 0.5255324099, -0.1834346425, 0.1834346425
]; ],
var weight = [ weight = [
1, 1, 1, 1,
0.5555555556, 0.5555555556, 0.8888888888, 0.5555555556, 0.5555555556, 0.8888888888,
0.3478548451, 0.3478548451, 0.6521451549, 0.6521451549, 0.3478548451, 0.3478548451, 0.6521451549, 0.6521451549,
@ -31,7 +31,11 @@ var Numerical = new function() {
0.1713244924, 0.1713244924, 0.3607615730, 0.3607615730, 0.4679139346, 0.4679139346, 0.1713244924, 0.1713244924, 0.3607615730, 0.3607615730, 0.4679139346, 0.4679139346,
0.1294849662, 0.1294849662, 0.2797053915, 0.2797053915, 0.3818300505, 0.3818300505, 0.4179591837, 0.1294849662, 0.1294849662, 0.2797053915, 0.2797053915, 0.3818300505, 0.3818300505, 0.4179591837,
0.1012285363, 0.1012285363, 0.2223810345, 0.2223810345, 0.3137066459, 0.3137066459, 0.3626837834, 0.3626837834 0.1012285363, 0.1012285363, 0.2223810345, 0.2223810345, 0.3137066459, 0.3137066459, 0.3626837834, 0.3626837834
]; ],
max = Math.max,
min = Math.min,
abs = Math.abs;
return { return {
TOLERANCE: 10e-6, TOLERANCE: 10e-6,
@ -43,7 +47,7 @@ var Numerical = new function() {
* All Rights Reserved. * All Rights Reserved.
*/ */
integrate: function(f, a, b, n) { integrate: function(f, a, b, n) {
n = Math.min(Math.max(n, 2), 8); n = min(max(n, 2), 8);
var l = n == 2 ? 0 : n * (n - 1) / 2 - 1, var l = n == 2 ? 0 : n * (n - 1) / 2 - 1,
sum = 0, sum = 0,
@ -71,7 +75,7 @@ var Numerical = new function() {
fc = fa; fc = fa;
e = d = b - a; e = d = b - a;
} }
if (Math.abs(fc) < Math.abs(fb)) { if (abs(fc) < abs(fb)) {
a = b; a = b;
b = c; b = c;
c = a; c = a;
@ -79,12 +83,12 @@ var Numerical = new function() {
fb = fc; fb = fc;
fc = fa; fc = fa;
} }
var tol1 = 2 * Number.MIN_VALUE * Math.abs(b) + 0.5 * tol, var tol1 = 2 * Number.MIN_VALUE * abs(b) + 0.5 * tol,
xm = 0.5 * (c - b); xm = 0.5 * (c - b);
if (Math.abs(xm) <= tol1 || fb == 0) { if (abs(xm) <= tol1 || fb == 0) {
return b; return b;
} }
if (Math.abs(e) >= tol1 && Math.abs(fa) > Math.abs(fb)) { if (abs(e) >= tol1 && abs(fa) > abs(fb)) {
var p, q, r, var p, q, r,
s = fb / fa; s = fb / fa;
if (a == c) { if (a == c) {
@ -98,9 +102,9 @@ var Numerical = new function() {
} }
if (p > 0) if (p > 0)
q = -q; q = -q;
p = Math.abs(p); p = abs(p);
var min1 = 3 * xm * q - Math.abs(tol1 * q), var min1 = 3 * xm * q - abs(tol1 * q),
min2 = Math.abs(e * q); min2 = abs(e * q);
if (2 * p < (min1 < min2 ? min1 : min2)) { if (2 * p < (min1 < min2 ? min1 : min2)) {
e = d; e = d;
d = p / q; d = p / q;
@ -114,10 +118,10 @@ var Numerical = new function() {
} }
a = b; a = b;
fa = fb; fa = fb;
if (Math.abs(d) > tol1) if (abs(d) > tol1)
b += d; b += d;
else else
b += xm >= 0 ? Math.abs(tol1) : -Math.abs(tol1); b += xm >= 0 ? abs(tol1) : -abs(tol1);
fb = f(b); fb = f(b);
} }
return b; return b;