Skip to content

Commit

Permalink
Merge pull request #1836 from tbo47/better-code
Browse files Browse the repository at this point in the history
refactor for const over let
  • Loading branch information
lavrton authored Oct 10, 2024
2 parents 16bd91b + 9a7e688 commit e9b8d84
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 32 deletions.
7 changes: 3 additions & 4 deletions src/filters/HSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import { getNumberValidator } from '../Validators';
*/

export const HSV: Filter = function (imageData) {
let data = imageData.data,
const data = imageData.data,
nPixels = data.length,
v = Math.pow(2, this.value()),
s = Math.pow(2, this.saturation()),
h = Math.abs(this.hue() + 360) % 360,
i;
h = Math.abs(this.hue() + 360) % 360;

// Basis for the technique used:
// http://beesbuzz.biz/code/hsv_color_transforms.php
Expand Down Expand Up @@ -49,7 +48,7 @@ export const HSV: Filter = function (imageData) {

let r, g, b, a;

for (i = 0; i < nPixels; i += 4) {
for (let i = 0; i < nPixels; i += 4) {
r = data[i + 0];
g = data[i + 1];
b = data[i + 2];
Expand Down
7 changes: 3 additions & 4 deletions src/filters/Noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import { getNumberValidator } from '../Validators';
* node.noise(0.8);
*/
export const Noise: Filter = function (imageData) {
let amount = this.noise() * 255,
const amount = this.noise() * 255,
data = imageData.data,
nPixels = data.length,
half = amount / 2,
i;
half = amount / 2;

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 + 1] += half - 2 * half * Math.random();
data[i + 2] += half - 2 * half * Math.random();
Expand Down
10 changes: 4 additions & 6 deletions src/filters/RGBA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import { RGBComponent } from '../Validators';
*/

export const RGBA: Filter = function (imageData) {
let data = imageData.data,
const data = imageData.data,
nPixels = data.length,
red = this.red(),
green = this.green(),
blue = this.blue(),
alpha = this.alpha(),
i,
ia;
alpha = this.alpha();

for (i = 0; i < nPixels; i += 4) {
ia = 1 - alpha;
for (let i = 0; i < nPixels; i += 4) {
const ia = 1 - alpha;

data[i] = red * alpha + data[i] * ia; // r
data[i + 1] = green * alpha + data[i + 1] * ia; // g
Expand Down
7 changes: 4 additions & 3 deletions src/filters/Solarize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { Filter } from '../Node';
*/

export const Solarize: Filter = function (imageData) {
let data = imageData.data,
const data = imageData.data,
w = imageData.width,
h = imageData.height,
w4 = w * 4,
y = h;
w4 = w * 4;

let y = h;

do {
const offsetY = (y - 1) * w4;
Expand Down
7 changes: 3 additions & 4 deletions src/filters/Threshold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import { getNumberValidator } from '../Validators';
*/

export const Threshold: Filter = function (imageData) {
let level = this.threshold() * 255,
const level = this.threshold() * 255,
data = imageData.data,
len = data.length,
i;
len = data.length;

for (i = 0; i < len; i += 1) {
for (let i = 0; i < len; i += 1) {
data[i] = data[i] < level ? 0 : 255;
}
};
Expand Down
17 changes: 7 additions & 10 deletions src/shapes/Line.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Util } from '../Util';
import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { getNumberValidator, getNumberArrayValidator } from '../Validators';
import { _registerNode } from '../Global';
import { Shape, ShapeConfig } from '../Shape';
import { getNumberArrayValidator, getNumberValidator } from '../Validators';

import { GetSet } from '../types';
import { Context } from '../Context';
import { GetSet } from '../types';

function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)),
Expand All @@ -21,13 +20,11 @@ function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
}

function expandPoints(p, tension) {
let len = p.length,
allPoints: Array<number> = [],
n,
cp;
const len = p.length,
allPoints: Array<number> = [];

for (n = 2; n < len - 2; n += 2) {
cp = getControlPoints(
for (let n = 2; n < len - 2; n += 2) {
const cp = getControlPoints(
p[n - 2],
p[n - 1],
p[n],
Expand Down
1 change: 0 additions & 1 deletion src/shapes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const AUTO = 'auto',
CONTEXT_2D = '2d',
DASH = '-',
LEFT = 'left',
LTR = 'ltr',
TEXT = 'text',
TEXT_UPPER = 'Text',
TOP = 'top',
Expand Down

0 comments on commit e9b8d84

Please sign in to comment.