mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
6b5ce7c18c
4 changed files with 50 additions and 35 deletions
|
@ -246,20 +246,20 @@ var Rectangle = this.Rectangle = Base.extend({
|
|||
// by checking the first character for [R]ight or [L]eft;
|
||||
var xFirst = /^[RL]/.test(key);
|
||||
// Rename Center to CenterX or CenterY:
|
||||
if (index >= 4) parts[1] += xFirst ? 'Y' : 'X';
|
||||
var xIndex = xFirst ? 0 : 1,
|
||||
yIndex = xFirst ? 1 : 0,
|
||||
getX = 'get' + parts[xIndex],
|
||||
getY = 'get' + parts[yIndex],
|
||||
setX = 'set' + parts[xIndex],
|
||||
setY = 'set' + parts[yIndex];
|
||||
if (index >= 4)
|
||||
parts[1] += xFirst ? 'Y' : 'X';
|
||||
var x = parts[xFirst ? 0 : 1],
|
||||
y = parts[xFirst ? 1 : 0],
|
||||
getX = 'get' + x,
|
||||
getY = 'get' + y,
|
||||
setX = 'set' + x,
|
||||
setY = 'set' + y;
|
||||
this['get' + key] = function() {
|
||||
return Point.create(this[getX](), this[getY]());
|
||||
};
|
||||
this['set' + key] = function(value) {
|
||||
var pt = Point.read(arguments);
|
||||
return this[setX](pt.x) // Note: chaining here!
|
||||
[setY](pt.y);
|
||||
return this[setX](pt.x)[setY](pt.y); // Note: chaining here!
|
||||
};
|
||||
}, { beans: true });
|
||||
});
|
||||
|
|
|
@ -29,9 +29,8 @@ var Color = this.Color = Base.extend({
|
|||
},
|
||||
|
||||
setAlpha: function(alpha) {
|
||||
if (alpha < 0) this._alpha = 0;
|
||||
else if (alpha > 1) this._alpha = 1;
|
||||
else this._alpha = alpha;
|
||||
this._alpha = Math.min(Math.max(alpha, 0), 1);
|
||||
this._alpha = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
|
||||
this._cssString = null;
|
||||
},
|
||||
|
||||
|
@ -49,9 +48,14 @@ var Color = this.Color = Base.extend({
|
|||
}
|
||||
}, new function() {
|
||||
function colorToHsb(color) {
|
||||
var r = color.getRed(), g = color.getGreen(), 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,
|
||||
var r = color.getRed(),
|
||||
g = color.getGreen(),
|
||||
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;
|
||||
if (saturation == 0) {
|
||||
hue = 0;
|
||||
|
@ -59,19 +63,24 @@ var Color = this.Color = Base.extend({
|
|||
var rr = (max - r) / delta,
|
||||
gr = (max - g) / delta,
|
||||
br = (max - b) / delta;
|
||||
if (r == max) hue = br - gr;
|
||||
else if (g == max) hue = 2 + rr - br;
|
||||
else hue = 4 + gr - rr;
|
||||
hue = r == max
|
||||
? br - gr
|
||||
: g == max
|
||||
? 2 + rr - br
|
||||
: 4 + gr - rr;
|
||||
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) {
|
||||
if(hue < 0) hue += 360;
|
||||
if (hue < 0)
|
||||
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,
|
||||
t = (brightness * (60 - saturation * (60 - f))) / 60;
|
||||
switch (Math.floor(hue / 60)) {
|
||||
|
|
|
@ -212,6 +212,7 @@ var Curve = this.Curve = Base.extend({
|
|||
+ ' }';
|
||||
}
|
||||
}, new function() {
|
||||
|
||||
function evaluate(that, t, type) {
|
||||
// Calculate the polynomial coefficients. caution: handles are relative
|
||||
// to points
|
||||
|
@ -269,6 +270,7 @@ var Curve = this.Curve = Base.extend({
|
|||
// the x and y coordinates:
|
||||
x = (3 * ax * t + 2 * bx) * t + cx,
|
||||
y = (3 * ay * t + 2 * by) * t + cy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The normal is simply the rotated tangent:
|
||||
|
|
|
@ -21,9 +21,9 @@ var Numerical = new function() {
|
|||
-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.9602898565, 0.9602898565, -0.7966664774, 0.7966664774, -0.5255324099, 0.5255324099, -0.1834346425, 0.1834346425
|
||||
];
|
||||
],
|
||||
|
||||
var weight = [
|
||||
weight = [
|
||||
1, 1,
|
||||
0.5555555556, 0.5555555556, 0.8888888888,
|
||||
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.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
|
||||
];
|
||||
],
|
||||
|
||||
max = Math.max,
|
||||
min = Math.min,
|
||||
abs = Math.abs;
|
||||
|
||||
return {
|
||||
TOLERANCE: 10e-6,
|
||||
|
@ -43,7 +47,7 @@ var Numerical = new function() {
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
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,
|
||||
sum = 0,
|
||||
|
@ -71,7 +75,7 @@ var Numerical = new function() {
|
|||
fc = fa;
|
||||
e = d = b - a;
|
||||
}
|
||||
if (Math.abs(fc) < Math.abs(fb)) {
|
||||
if (abs(fc) < abs(fb)) {
|
||||
a = b;
|
||||
b = c;
|
||||
c = a;
|
||||
|
@ -79,12 +83,12 @@ var Numerical = new function() {
|
|||
fb = fc;
|
||||
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);
|
||||
if (Math.abs(xm) <= tol1 || fb == 0) {
|
||||
if (abs(xm) <= tol1 || fb == 0) {
|
||||
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,
|
||||
s = fb / fa;
|
||||
if (a == c) {
|
||||
|
@ -98,9 +102,9 @@ var Numerical = new function() {
|
|||
}
|
||||
if (p > 0)
|
||||
q = -q;
|
||||
p = Math.abs(p);
|
||||
var min1 = 3 * xm * q - Math.abs(tol1 * q),
|
||||
min2 = Math.abs(e * q);
|
||||
p = abs(p);
|
||||
var min1 = 3 * xm * q - abs(tol1 * q),
|
||||
min2 = abs(e * q);
|
||||
if (2 * p < (min1 < min2 ? min1 : min2)) {
|
||||
e = d;
|
||||
d = p / q;
|
||||
|
@ -114,10 +118,10 @@ var Numerical = new function() {
|
|||
}
|
||||
a = b;
|
||||
fa = fb;
|
||||
if (Math.abs(d) > tol1)
|
||||
if (abs(d) > tol1)
|
||||
b += d;
|
||||
else
|
||||
b += xm >= 0 ? Math.abs(tol1) : -Math.abs(tol1);
|
||||
b += xm >= 0 ? abs(tol1) : -abs(tol1);
|
||||
fb = f(b);
|
||||
}
|
||||
return b;
|
||||
|
|
Loading…
Reference in a new issue