Lint fixes and related cleanup

This commit is contained in:
Christopher Willis-Ford 2017-01-19 12:50:46 -08:00
parent 369c02b5d5
commit a6190da774
3 changed files with 55 additions and 28 deletions

View file

@ -81,9 +81,9 @@ Scratch3PenBlocks.prototype._getPenState = function (target) {
/** /**
* Handle a target which has moved. This only fires when the pen is down. * Handle a target which has moved. This only fires when the pen is down.
* @param {RenderedTarget} target * @param {RenderedTarget} target - the target which has moved.
* @param {number} oldX * @param {number} oldX - the previous X position.
* @param {number} oldY * @param {number} oldY - the previous Y position.
* @private * @private
*/ */
Scratch3PenBlocks.prototype._onTargetMoved = function (target, oldX, oldY) { Scratch3PenBlocks.prototype._onTargetMoved = function (target, oldX, oldY) {

View file

@ -166,7 +166,8 @@ RenderedTarget.prototype.setXY = function (x, y) {
if (this.isStage) { if (this.isStage) {
return; return;
} }
var oldX = this.x, oldY = this.y; var oldX = this.x;
var oldY = this.y;
this.x = x; this.x = x;
this.y = y; this.y = y;
if (this.renderer) { if (this.renderer) {

View file

@ -99,14 +99,10 @@ Color.hexToDecimal = function (hex) {
* @returns {RGBObject} rgb - {r: red [0,255], g: green [0,255], b: blue [0,255]}. * @returns {RGBObject} rgb - {r: red [0,255], g: green [0,255], b: blue [0,255]}.
*/ */
Color.hsvToRgb = function (hsv) { Color.hsvToRgb = function (hsv) {
var h = hsv.h; var h = hsv.h % 360;
var s = hsv.s;
var v = hsv.v;
h = h % 360;
if (h < 0) h += 360; if (h < 0) h += 360;
s = Math.max(0, Math.min(s, 1)); var s = Math.max(0, Math.min(hsv.s, 1));
v = Math.max(0, Math.min(v, 1)); var v = Math.max(0, Math.min(hsv.v, 1));
var i = Math.floor(h / 60); var i = Math.floor(h / 60);
var f = (h / 60) - i; var f = (h / 60) - i;
@ -114,13 +110,43 @@ Color.hsvToRgb = function (hsv) {
var q = v * (1 - (s * f)); var q = v * (1 - (s * f));
var t = v * (1 - (s * (1 - f))); var t = v * (1 - (s * (1 - f)));
var r, g, b; var r;
if (i == 0) { r = v; g = t; b = p; } var g;
else if (i == 1) { r = q; g = v; b = p; } var b;
else if (i == 2) { r = p; g = v; b = t; }
else if (i == 3) { r = p; g = q; b = v; } switch (i) {
else if (i == 4) { r = t; g = p; b = v; } default:
else if (i == 5) { r = v; g = p; b = q; } case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;
b = q;
break;
}
return { return {
r: Math.floor(r * 255), r: Math.floor(r * 255),
@ -135,18 +161,18 @@ Color.hsvToRgb = function (hsv) {
* @returns {HSVObject} hsv - {h: hue [0,360), s: saturation [0,1], v: value [0,1]} * @returns {HSVObject} hsv - {h: hue [0,360), s: saturation [0,1], v: value [0,1]}
*/ */
Color.rgbToHsv = function (rgb) { Color.rgbToHsv = function (rgb) {
var v, x, f, i;
var h = 0, s = 0;
var r = rgb.r; var r = rgb.r;
var g = rgb.g; var g = rgb.g;
var b = rgb.b; var b = rgb.b;
x = Math.min(Math.min(r, g), b); var x = Math.min(Math.min(r, g), b);
v = Math.max(Math.max(r, g), b); var v = Math.max(Math.max(r, g), b);
// For grays, hue will be arbitrarily reported as zero. Otherwise, calculate // For grays, hue will be arbitrarily reported as zero. Otherwise, calculate
if (x != v) { var h = 0;
f = (r == x) ? g - b : ((g == x) ? b - r : r - g); var s = 0;
i = (r == x) ? 3 : ((g == x) ? 5 : 1); if (x !== v) {
var f = (r === x) ? g - b : ((g === x) ? b - r : r - g);
var i = (r === x) ? 3 : ((g === x) ? 5 : 1);
h = ((i - (f / (v - x))) * 60) % 360; h = ((i - (f / (v - x))) * 60) % 360;
s = (v - x) / v; s = (v - x) / v;
} }
@ -166,9 +192,9 @@ Color.mixRgb = function (rgb0, rgb1, fraction1) {
if (fraction1 >= 1) return rgb1; if (fraction1 >= 1) return rgb1;
var fraction0 = 1 - fraction1; var fraction0 = 1 - fraction1;
return { return {
r: fraction0 * rgb0.r + fraction1 * rgb1.r, r: (fraction0 * rgb0.r) + (fraction1 * rgb1.r),
g: fraction0 * rgb0.g + fraction1 * rgb1.g, g: (fraction0 * rgb0.g) + (fraction1 * rgb1.g),
b: fraction0 * rgb0.b + fraction1 * rgb1.b b: (fraction0 * rgb0.b) + (fraction1 * rgb1.b)
}; };
}; };