Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Dec 20, 2023
1 parent f6d3906 commit b50a6e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
58 changes: 29 additions & 29 deletions plugins/optimizePathOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exports.fn = (root, params) => {
console.warn(
'optimizePathOrder is enabled, but data from convertPathData is not present. ' +
'If you want to use optimizePathOrder, enable convertPathData and put optimizePathOrder after it. ' +
'If you do not want to use optimizePathOrder, disable it.'
'If you do not want to use optimizePathOrder, disable it.',
);
return;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ exports.fn = (root, params) => {
for (const [i, part] of parts.entries()) {
if (part.valid) {
const internalData = part.data.filter(
(item) => item.command != 'm' && item.command != 'M'
(item) => item.command != 'm' && item.command != 'M',
);
if (internalData.length > 0) {
const start = internalData[0].base;
Expand Down Expand Up @@ -148,25 +148,25 @@ exports.fn = (root, params) => {
y2: item.args[3] + item.base[1],
}
: item.command == 'C'
? {
x1: item.args[0],
y1: item.args[1],
x2: item.args[2],
y2: item.args[3],
}
: undefined,
? {
x1: item.args[0],
y1: item.args[1],
x2: item.args[2],
y2: item.args[3],
}
: undefined,
q:
item.command == 'q'
? {
x: item.args[0] + item.base[0],
y: item.args[1] + item.base[1],
}
: item.command == 'Q'
? {
x: item.args[0],
y: item.args[1],
}
: undefined,
? {
x: item.args[0],
y: item.args[1],
}
: undefined,
base: item.base,
coords: item.coords,
})),
Expand Down Expand Up @@ -269,8 +269,8 @@ function optimizePart({
{ ...item, command: getCommand(item) },
precision,
output[output.length - 1].command,
output.length == input.length && !unsafeToChangeStart
)
output.length == input.length && !unsafeToChangeStart,
),
);
}
} else {
Expand All @@ -291,16 +291,16 @@ function optimizePart({
{ ...previousItem, command: getCommand(previousItem) },
precision,
output[output.length - 1].command,
false
)
false,
),
);
output.push(
transformCommand(
{ ...newItem, command: getCommand(newItem) },
precision,
output[output.length - 1].command,
!unsafeToChangeStart
)
!unsafeToChangeStart,
),
);
}
i++;
Expand All @@ -310,7 +310,7 @@ function optimizePart({
(next
? estimateLength(
transformMove(next, output[output.length - 1].coords),
precision
precision,
)
: 0);
if (size < best.size) {
Expand All @@ -334,10 +334,10 @@ function getCommand(item) {
return item.command == 'a' || item.command == 'A'
? 'A'
: item.command == 'c' || item.command == 'C'
? 'C'
: item.command == 'q' || item.command == 'Q'
? 'Q'
: 'L';
? 'C'
: item.command == 'q' || item.command == 'Q'
? 'Q'
: 'L';
}

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ function transformCommand(command, precision, lastCommand, useZ) {
);
const args = [data.x1, data.y1, data.x2, data.y2, ...command.coords];
const argsRelative = args.map((a, i) =>
i % 2 == 0 ? a - command.base[0] : a - command.base[1]
i % 2 == 0 ? a - command.base[0] : a - command.base[1],
);
const absoluteLength =
estimateLength(args, precision) + (lastCommand == 'C' ? 0 : 1);
Expand All @@ -400,7 +400,7 @@ function transformCommand(command, precision, lastCommand, useZ) {
const data = /** @type {{x: number, y: number}} */ (command.q);
const args = [data.x, data.y, ...command.coords];
const argsRelative = args.map((a, i) =>
i % 2 == 0 ? a - command.base[0] : a - command.base[1]
i % 2 == 0 ? a - command.base[0] : a - command.base[1],
);
const absoluteLength =
estimateLength(args, precision) + (lastCommand == 'Q' ? 0 : 1);
Expand All @@ -425,7 +425,7 @@ function transformCommand(command, precision, lastCommand, useZ) {
} else if (command.base[1] == command.coords[1]) {
const absoluteLength = toPrecision(
command.coords[0],
precision
precision,
).toString().length;
const relativeLength = toPrecision(relativeX, precision).toString()
.length;
Expand All @@ -439,7 +439,7 @@ function transformCommand(command, precision, lastCommand, useZ) {
} else if (command.base[0] == command.coords[0]) {
const absoluteLength = toPrecision(
command.coords[1],
precision
precision,
).toString().length;
const relativeLength = toPrecision(relativeY, precision).toString()
.length;
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/optimizePathOrder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ test('should rotate paths properly', () => {
expect(
optimize(svg, {
plugins: ['convertPathData', 'optimizePathOrder'],
}).data
}).data,
).toEqual(`<svg><path d="M0 0h10v10z"/></svg>`);
});
test('should reverse paths properly', () => {
const svg = `<svg><path d="m 16 14 v -2 h -8 v 2 z"/></svg>`;
expect(
optimize(svg, {
plugins: ['convertPathData', 'optimizePathOrder'],
}).data
}).data,
).toEqual(`<svg><path d="M8 12h8v2H8z"/></svg>`);
});

0 comments on commit b50a6e7

Please sign in to comment.