File imagetracer_v1.2.6.ts
has 1511 lines of code (exceeds 250 allowed). Consider refactoring.
imagetracer.js version 1.2.6
Simple raster image tracer and vectorizer written in JavaScript.
andras@jankovics.net
*/
Function pathscan
has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
private pathscan(array: number[][], pathomit: number): Path[] {
const paths: Path[] = [];
let pacnt = 0;
let pcnt = 0;
let px = 0;
Function svgpathstring
has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
svgpathstring(tracedata: TraceData, lnum: number, pathnum: number, options: Options): SVGString {
const layer = tracedata.layers[lnum];
const smp = layer[pathnum];
const str: string[] = [];
Function colorquantization
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
private colorquantization(imageData: ImageData, options: Options): ClusteredImageData {
const array: number[][] = [];
let idx = 0;
let cd: number;
let cdl: number;
Function layering
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
private layering(ii: ClusteredImageData): number[][][] {
const layers: number[][][] = [];
let val = 0;
const ah = ii.array.length;
Function svgpathstring
has 142 lines of code (exceeds 25 allowed). Consider refactoring.
svgpathstring(tracedata: TraceData, lnum: number, pathnum: number, options: Options): SVGString {
const layer = tracedata.layers[lnum];
const smp = layer[pathnum];
const str: string[] = [];
ImageTracer
has 34 functions (exceeds 20 allowed). Consider refactoring.
export default class ImageTracer {
private readonly versionnumber = '1.2.6';
Function blur
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
blur(imgd: ImageData, radius: number, delta: number) {
let i, j, k, d, idx, racc, gacc, bacc, aacc, wacc;
const imgd2: ImageData = { width: imgd.width, height: imgd.height, data: new Uint8ClampedArray() };
Function fitseq
has 93 lines of code (exceeds 25 allowed). Consider refactoring.
private fitseq(
path: Path,
ltres: number,
qtres: number,
seqstart: number,
Function colorquantization
has 90 lines of code (exceeds 25 allowed). Consider refactoring.
private colorquantization(imageData: ImageData, options: Options): ClusteredImageData {
const array: number[][] = [];
let idx = 0;
let cd: number;
let cdl: number;
Function blur
has 80 lines of code (exceeds 25 allowed). Consider refactoring.
blur(imgd: ImageData, radius: number, delta: number) {
let i, j, k, d, idx, racc, gacc, bacc, aacc, wacc;
const imgd2: ImageData = { width: imgd.width, height: imgd.height, data: new Uint8ClampedArray() };
Function pathscan
has 80 lines of code (exceeds 25 allowed). Consider refactoring.
private pathscan(array: number[][], pathomit: number): Path[] {
const paths: Path[] = [];
let pacnt = 0;
let pcnt = 0;
let px = 0;
Function fitseq
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
private fitseq(
path: Path,
ltres: number,
qtres: number,
seqstart: number,
Function layeringstep
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
private layeringstep(ii: ClusteredImageData, cnum: number): number[][] {
const layer: number[][] = [];
const ah = ii.array.length;
const aw = ii.array[0].length;
Function internodes
has 57 lines of code (exceeds 25 allowed). Consider refactoring.
private internodes(paths: Path[], options: Options): Path[] {
const ins: Path[] = [];
let palen = 0;
let nextidx = 0;
let nextidx2 = 0;
Function layering
has 48 lines of code (exceeds 25 allowed). Consider refactoring.
private layering(ii: ClusteredImageData): number[][][] {
const layers: number[][][] = [];
let val = 0;
const ah = ii.array.length;
Function getdirection
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
getdirection(x1: number, y1: number, x2: number, y2: number): Direction {
let val: Direction = 8;
if (x1 < x2) {
if (y1 < y2) {
val = 1;
Function generatepalette
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
private generatepalette(numberofcolors: number): Palette {
const palette: Palette = [];
let rcnt: number;
let gcnt: number;
let bcnt: number;
Function generatepalette
has 40 lines of code (exceeds 25 allowed). Consider refactoring.
private generatepalette(numberofcolors: number): Palette {
const palette: Palette = [];
let rcnt: number;
let gcnt: number;
let bcnt: number;
Function tracepath
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
private tracepath(path: Path, ltres: number, qtres: number): TracedSegment {
let pcnt = 0;
let segtype1;
let segtype2;
let seqend;
Function tracepath
has 36 lines of code (exceeds 25 allowed). Consider refactoring.
private tracepath(path: Path, ltres: number, qtres: number): TracedSegment {
let pcnt = 0;
let segtype1;
let segtype2;
let seqend;
Function drawLayers
has 34 lines of code (exceeds 25 allowed). Consider refactoring.
drawLayers(layers: number[][][], palette: Palette, scale: number, parentid?: string) {
scale = scale || 1;
let div: HTMLDivElement;
Function getdirection
has 33 lines of code (exceeds 25 allowed). Consider refactoring.
getdirection(x1: number, y1: number, x2: number, y2: number): Direction {
let val: Direction = 8;
if (x1 < x2) {
if (y1 < y2) {
val = 1;
Function imagedataToTracedata
has 33 lines of code (exceeds 25 allowed). Consider refactoring.
imagedataToTracedata(imageData: ImageData, options?: Options): TraceData {
const opts = this.checkoptions(options);
const ii = this.colorquantization(imageData, opts);
Function internodes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
private internodes(paths: Path[], options: Options): Path[] {
const ins: Path[] = [];
let palen = 0;
let nextidx = 0;
let nextidx2 = 0;
Avoid deeply nested control flow statements.
if (py - 1 < paths[pacnt].boundingbox[1]) {
paths[pacnt].boundingbox[1] = py - 1;
}
Avoid deeply nested control flow statements.
if (px - 1 === paths[pacnt].points[0].x && py - 1 === paths[pacnt].points[0].y) {
pathfinished = true;
if (paths[pacnt].points.length < pathomit) {
Avoid deeply nested control flow statements.
if (px - 1 > paths[pacnt].boundingbox[2]) {
paths[pacnt].boundingbox[2] = px - 1;
}
Avoid deeply nested control flow statements.
if (py - 1 > paths[pacnt].boundingbox[3]) {
paths[pacnt].boundingbox[3] = py - 1;
}
Avoid deeply nested control flow statements.
if (cd < cdl) {
cdl = cd;
ci = k;
}
Avoid deeply nested control flow statements.
if (px - 1 < paths[pacnt].boundingbox[0]) {
paths[pacnt].boundingbox[0] = px - 1;
}
Function samplepalette2
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
private samplepalette2(numberofcolors: number, imageData: ImageData): Palette {
let idx: number;
const palette: Palette = [];
const ni = Math.ceil(Math.sqrt(numberofcolors));
const nj = Math.ceil(numberofcolors / ni);
Function getsvgstring
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
getsvgstring(tracedata: TraceData, options: Options): SVGString {
options = this.checkoptions(options);
const w = tracedata.width * options.scale;
const h = tracedata.height * options.scale;
Function imagedataToTracedata
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
imagedataToTracedata(imageData: ImageData, options?: Options): TraceData {
const opts = this.checkoptions(options);
const ii = this.colorquantization(imageData, opts);
Similar blocks of code found in 2 locations. Consider refactoring.
for (let pcnt = 0; pcnt < hsmp.segments.length; pcnt++) {
const pnt = hsmp.segments[pcnt];
if (pnt.x3 != null && options.qcpr) {
str.push(
`<circle cx="${pnt.x2 * options.scale}" cy="${pnt.y2 * options.scale}" r="${
Similar blocks of code found in 2 locations. Consider refactoring.
for (let pcnt = 0; pcnt < smp.segments.length; pcnt++) {
const pnt = smp.segments[pcnt];
if (pnt.x3 != null && options.qcpr) {
str.push(
`<circle cx="${pnt.x2 * options.scale}" cy="${pnt.y2 * options.scale}" r="${
Similar blocks of code found in 2 locations. Consider refactoring.
(path.points[idx3].x === path.points[idx1].x &&
path.points[idx3].x === path.points[idx2].x &&
path.points[idx3].y === path.points[idx4].y &&
path.points[idx3].y === path.points[idx5].y) ||
Similar blocks of code found in 2 locations. Consider refactoring.
(path.points[idx3].y === path.points[idx1].y &&
path.points[idx3].y === path.points[idx2].y &&
path.points[idx3].x === path.points[idx4].x &&
path.points[idx3].x === path.points[idx5].x)
Similar blocks of code found in 2 locations. Consider refactoring.
palette.push({
r: Math.floor(Math.random() * 255) as ColorComponentValue,
g: Math.floor(Math.random() * 255) as ColorComponentValue,
b: Math.floor(Math.random() * 255) as ColorComponentValue,
a: Math.floor(Math.random() * 255) as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
palette[k] = {
r: Math.floor(Math.random() * 255) as ColorComponentValue,
g: Math.floor(Math.random() * 255) as ColorComponentValue,
b: Math.floor(Math.random() * 255) as ColorComponentValue,
a: Math.floor(Math.random() * 255) as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
palette.push({
r: imageData.data[idx] as ColorComponentValue,
g: imageData.data[idx + 1] as ColorComponentValue,
b: imageData.data[idx + 2] as ColorComponentValue,
a: imageData.data[idx + 3] as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
palette.push({
r: imageData.data[idx] as ColorComponentValue,
g: imageData.data[idx + 1] as ColorComponentValue,
b: imageData.data[idx + 2] as ColorComponentValue,
a: imageData.data[idx + 3] as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
imageToTracedata(imageURL: string, callback: TraceDataCallback, options?: Options) {
const opts = this.checkoptions(options);
this.loadImage(
imageURL,
Similar blocks of code found in 2 locations. Consider refactoring.
imageToSVG(imageURL: string, callback: ResultCallback, options?: Options) {
const opts = this.checkoptions(options);
this.loadImage(
imageURL,
Similar blocks of code found in 2 locations. Consider refactoring.
dist2 =
(path.points[pcnt].x - px) * (path.points[pcnt].x - px) +
(path.points[pcnt].y - py) * (path.points[pcnt].y - py);
Similar blocks of code found in 2 locations. Consider refactoring.
dist2 =
(path.points[pcnt].x - px) * (path.points[pcnt].x - px) +
(path.points[pcnt].y - py) * (path.points[pcnt].y - py);
Similar blocks of code found in 2 locations. Consider refactoring.
for (let i = 0; i < numberofcolors; i++) {
palette.push({
r: (i * graystep) as ColorComponentValue,
g: (i * graystep) as ColorComponentValue,
b: (i * graystep) as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
for (bcnt = 0; bcnt < colorqnum; bcnt++) {
palette.push({
r: (rcnt * colorstep) as ColorComponentValue,
g: (gcnt * colorstep) as ColorComponentValue,
b: (bcnt * colorstep) as ColorComponentValue,
Similar blocks of code found in 2 locations. Consider refactoring.
const cpx = (t1 * path.points[seqstart].x + t3 * path.points[seqend].x - path.points[fitpoint].x) / -t2,
Similar blocks of code found in 2 locations. Consider refactoring.
cpy = (t1 * path.points[seqstart].y + t3 * path.points[seqend].y - path.points[fitpoint].y) / -t2;
Similar blocks of code found in 2 locations. Consider refactoring.
} else if (x1 > x2) {
if (y1 < y2) {
val = 3;
}
else if (y1 > y2) {
Similar blocks of code found in 2 locations. Consider refactoring.
if (x1 < x2) {
if (y1 < y2) {
val = 1;
}
else if (y1 > y2) {
Similar blocks of code found in 2 locations. Consider refactoring.
} else {
str.push(spacify('M', this.roundtodec(prev.x2 * options.scale), this.roundtodec(prev.y2 * options.scale)));
}
Similar blocks of code found in 2 locations. Consider refactoring.
if (prev.x3 != null) {
str.push(spacify('M', this.roundtodec(prev.x3 * options.scale), this.roundtodec(prev.y3 * options.scale)));
} else {
Identical blocks of code found in 2 locations. Consider refactoring.
[
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
Identical blocks of code found in 2 locations. Consider refactoring.
[
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
Similar blocks of code found in 2 locations. Consider refactoring.
str.push(spacify(this.roundtodec(pnt.x2 * options.scale), this.roundtodec(pnt.y2 * options.scale)));
Similar blocks of code found in 2 locations. Consider refactoring.
str.push(spacify(this.roundtodec(pnt.x1 * options.scale), this.roundtodec(pnt.y1 * options.scale)));
Similar blocks of code found in 2 locations. Consider refactoring.
str.push(spacify(hsmp.segments[pcnt].x2 * options.scale, hsmp.segments[pcnt].y2 * options.scale));
Similar blocks of code found in 2 locations. Consider refactoring.
str.push(spacify(hsmp.segments[pcnt].x1 * options.scale, hsmp.segments[pcnt].y1 * options.scale));
Similar blocks of code found in 2 locations. Consider refactoring.
px = t1 * path.points[seqstart].x + t2 * cpx + t3 * path.points[seqend].x;
Similar blocks of code found in 2 locations. Consider refactoring.
py = t1 * path.points[seqstart].y + t2 * cpy + t3 * path.points[seqend].y;
Similar blocks of code found in 2 locations. Consider refactoring.
if (px - 1 > paths[pacnt].boundingbox[2]) {
paths[pacnt].boundingbox[2] = px - 1;
}
Similar blocks of code found in 2 locations. Consider refactoring.
if (py - 1 < paths[pacnt].boundingbox[1]) {
paths[pacnt].boundingbox[1] = py - 1;
}
Similar blocks of code found in 2 locations. Consider refactoring.
x: (paths[pacnt].points[pcnt].x + paths[pacnt].points[nextidx].x) / 2,
Identical blocks of code found in 2 locations. Consider refactoring.
[
[0, 1, 0, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[0, 2, -1, 0],
Similar blocks of code found in 2 locations. Consider refactoring.
y: (paths[pacnt].points[pcnt].y + paths[pacnt].points[nextidx].y) / 2,
Identical blocks of code found in 2 locations. Consider refactoring.
[
[0, 1, 0, -1],
[-1, -1, -1, -1],
[-1, -1, -1, -1],
[0, 2, -1, 0],
There are no issues that match your filters.