Skip to content

Commit

Permalink
refactor(util): remove lang_array since there are no more use cases (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Sep 11, 2022
1 parent 18e6416 commit 268d092
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 118 deletions.
11 changes: 4 additions & 7 deletions src/color/color.class.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

//@ts-nocheck
import { max, min } from '../util/lang_array';
import { ColorNameMap } from './color_map';
import { reHSLa, reHex, reRGBa } from './constants';
import { hue2rgb, hexify } from './util';
Expand All @@ -18,8 +17,8 @@ export class Color {
private _source: TColorAlphaSource;

/**
*
* @param {string} [color] optional in hex or rgb(a) or hsl format or from known color list
*
* @param {string} [color] optional in hex or rgb(a) or hsl format or from known color list
*/
constructor(color?: string) {
if (!color) {
Expand Down Expand Up @@ -63,8 +62,8 @@ export class Color {
*/
_rgbToHsl(r: number, g: number, b: number): TColorSource {
r /= 255; g /= 255; b /= 255;
const maxValue = max([r, g, b]),
minValue = min([r, g, b]);
const maxValue = Math.max(r, g, b),
minValue = Math.min(r, g, b);

let h, s;
const l = (maxValue + minValue) / 2;
Expand Down Expand Up @@ -400,8 +399,6 @@ export class Color {
oColor.setSource(source);
return oColor;
}


}


Expand Down
24 changes: 7 additions & 17 deletions src/shapes/polyline.class.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//@ts-nocheck

import { config } from "../config";
import { Point } from "../point.class";
import { makeBoundingBoxFromPoints } from '../util/misc/boundingBoxFromPoints';


(function(global) {
var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend,
min = fabric.util.array.min,
max = fabric.util.array.max,
toFixed = fabric.util.toFixed,
projectStrokeOnPoints = fabric.util.projectStrokeOnPoints;

Expand Down Expand Up @@ -121,21 +121,11 @@ import { config } from "../config";
* @private
*/
_calcDimensions: function() {

var points = this.exactBoundingBox ? this._projectStrokeOnPoints() : this.points,
minX = min(points, 'x') || 0,
minY = min(points, 'y') || 0,
maxX = max(points, 'x') || 0,
maxY = max(points, 'y') || 0,
width = (maxX - minX),
height = (maxY - minY);

return {
left: minX,
top: minY,
width: width,
height: height,
};
const points = this.exactBoundingBox ? this._projectStrokeOnPoints() : this.points.map(p => new Point(p));
if (points.length === 0) {
return makeBoundingBoxFromPoints([new Point(0, 0)]);
}
return makeBoundingBoxFromPoints(points);
},

/**
Expand Down
56 changes: 0 additions & 56 deletions src/util/lang_array.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/util/misc/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ import {
enlivenObjects,
enlivenObjectEnlivables,
} from './objectEnlive';
import {
min,
max,
} from '../lang_array';
import { pick } from './pick';
import {
joinPath,
Expand Down Expand Up @@ -164,10 +160,6 @@ fabric.util = {
loadImage,
enlivenObjects,
enlivenObjectEnlivables,
array: {
min,
max,
},
pick,
joinPath,
parsePath,
Expand Down
30 changes: 0 additions & 30 deletions test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,36 +570,6 @@
assert.ok(true, 'test did not throw on null element removeListener');
});

QUnit.test('fabric.util.array.min', function(assert) {
assert.ok(typeof fabric.util.array.min === 'function');

assert.equal(1, fabric.util.array.min([1, 3, 2]));
assert.equal(-1, fabric.util.array.min([3, 1, 'f', 3, -1, 3]));
assert.equal(-3, fabric.util.array.min([-1, -2, -3]));
assert.equal('a', fabric.util.array.min(['a', 'c', 'b']));

var obj1 = { valueOf: function(){ return 1; } };
var obj2 = { valueOf: function(){ return 2; } };
var obj3 = { valueOf: function(){ return 3; } };

assert.equal(obj1, fabric.util.array.min([obj1, obj3, obj2]));
});

QUnit.test('fabric.util.array.max', function(assert) {
assert.ok(typeof fabric.util.array.max === 'function');

assert.equal(3, fabric.util.array.max([1, 3, 2]));
assert.equal(3, fabric.util.array.max([3, 1, 'f', 3, -1, 3]));
assert.equal(-1, fabric.util.array.max([-1, -2, -3]));
assert.equal('c', fabric.util.array.max(['a', 'c', 'b']));

var obj1 = { valueOf: function(){ return 1; } };
var obj2 = { valueOf: function(){ return 2; } };
var obj3 = { valueOf: function(){ return 3; } };

assert.equal(obj3, fabric.util.array.max([obj1, obj3, obj2]));
});

QUnit.test('fabric.util.pick', function(assert) {
assert.ok(typeof fabric.util.pick === 'function');

Expand Down

0 comments on commit 268d092

Please sign in to comment.