refactor for const over let

This commit is contained in:
Thibaut(Teebo) 2024-10-09 14:57:46 +00:00
parent 16bd91bba1
commit 9a7e688f48
7 changed files with 24 additions and 32 deletions

View File

@ -15,12 +15,11 @@ import { getNumberValidator } from '../Validators';
*/ */
export const HSV: Filter = function (imageData) { export const HSV: Filter = function (imageData) {
let data = imageData.data, const data = imageData.data,
nPixels = data.length, nPixels = data.length,
v = Math.pow(2, this.value()), v = Math.pow(2, this.value()),
s = Math.pow(2, this.saturation()), s = Math.pow(2, this.saturation()),
h = Math.abs(this.hue() + 360) % 360, h = Math.abs(this.hue() + 360) % 360;
i;
// Basis for the technique used: // Basis for the technique used:
// http://beesbuzz.biz/code/hsv_color_transforms.php // http://beesbuzz.biz/code/hsv_color_transforms.php
@ -49,7 +48,7 @@ export const HSV: Filter = function (imageData) {
let r, g, b, a; let r, g, b, a;
for (i = 0; i < nPixels; i += 4) { for (let i = 0; i < nPixels; i += 4) {
r = data[i + 0]; r = data[i + 0];
g = data[i + 1]; g = data[i + 1];
b = data[i + 2]; b = data[i + 2];

View File

@ -15,13 +15,12 @@ import { getNumberValidator } from '../Validators';
* node.noise(0.8); * node.noise(0.8);
*/ */
export const Noise: Filter = function (imageData) { export const Noise: Filter = function (imageData) {
let amount = this.noise() * 255, const amount = this.noise() * 255,
data = imageData.data, data = imageData.data,
nPixels = data.length, nPixels = data.length,
half = amount / 2, half = amount / 2;
i;
for (i = 0; i < nPixels; i += 4) { for (let i = 0; i < nPixels; i += 4) {
data[i + 0] += half - 2 * half * Math.random(); data[i + 0] += half - 2 * half * Math.random();
data[i + 1] += half - 2 * half * Math.random(); data[i + 1] += half - 2 * half * Math.random();
data[i + 2] += half - 2 * half * Math.random(); data[i + 2] += half - 2 * half * Math.random();

View File

@ -18,17 +18,15 @@ import { RGBComponent } from '../Validators';
*/ */
export const RGBA: Filter = function (imageData) { export const RGBA: Filter = function (imageData) {
let data = imageData.data, const data = imageData.data,
nPixels = data.length, nPixels = data.length,
red = this.red(), red = this.red(),
green = this.green(), green = this.green(),
blue = this.blue(), blue = this.blue(),
alpha = this.alpha(), alpha = this.alpha();
i,
ia;
for (i = 0; i < nPixels; i += 4) { for (let i = 0; i < nPixels; i += 4) {
ia = 1 - alpha; const ia = 1 - alpha;
data[i] = red * alpha + data[i] * ia; // r data[i] = red * alpha + data[i] * ia; // r
data[i + 1] = green * alpha + data[i + 1] * ia; // g data[i + 1] = green * alpha + data[i + 1] * ia; // g

View File

@ -14,11 +14,12 @@ import { Filter } from '../Node';
*/ */
export const Solarize: Filter = function (imageData) { export const Solarize: Filter = function (imageData) {
let data = imageData.data, const data = imageData.data,
w = imageData.width, w = imageData.width,
h = imageData.height, h = imageData.height,
w4 = w * 4, w4 = w * 4;
y = h;
let y = h;
do { do {
const offsetY = (y - 1) * w4; const offsetY = (y - 1) * w4;

View File

@ -17,12 +17,11 @@ import { getNumberValidator } from '../Validators';
*/ */
export const Threshold: Filter = function (imageData) { export const Threshold: Filter = function (imageData) {
let level = this.threshold() * 255, const level = this.threshold() * 255,
data = imageData.data, data = imageData.data,
len = data.length, len = data.length;
i;
for (i = 0; i < len; i += 1) { for (let i = 0; i < len; i += 1) {
data[i] = data[i] < level ? 0 : 255; data[i] = data[i] < level ? 0 : 255;
} }
}; };

View File

@ -1,11 +1,10 @@
import { Util } from '../Util';
import { Factory } from '../Factory'; import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { getNumberValidator, getNumberArrayValidator } from '../Validators';
import { _registerNode } from '../Global'; import { _registerNode } from '../Global';
import { Shape, ShapeConfig } from '../Shape';
import { getNumberArrayValidator, getNumberValidator } from '../Validators';
import { GetSet } from '../types';
import { Context } from '../Context'; import { Context } from '../Context';
import { GetSet } from '../types';
function getControlPoints(x0, y0, x1, y1, x2, y2, t) { function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)),
@ -21,13 +20,11 @@ function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
} }
function expandPoints(p, tension) { function expandPoints(p, tension) {
let len = p.length, const len = p.length,
allPoints: Array<number> = [], allPoints: Array<number> = [];
n,
cp;
for (n = 2; n < len - 2; n += 2) { for (let n = 2; n < len - 2; n += 2) {
cp = getControlPoints( const cp = getControlPoints(
p[n - 2], p[n - 2],
p[n - 1], p[n - 1],
p[n], p[n],

View File

@ -69,7 +69,6 @@ const AUTO = 'auto',
CONTEXT_2D = '2d', CONTEXT_2D = '2d',
DASH = '-', DASH = '-',
LEFT = 'left', LEFT = 'left',
LTR = 'ltr',
TEXT = 'text', TEXT = 'text',
TEXT_UPPER = 'Text', TEXT_UPPER = 'Text',
TOP = 'top', TOP = 'top',