Skip to content

Commit

Permalink
feat: getLayerIconPath optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Nov 20, 2024
1 parent f6519ab commit c872b5b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 117 deletions.
13 changes: 2 additions & 11 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@
"build": "tsc && vite build"
},
"devDependencies": {
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.isequal": "^4.5.6",
"@types/lodash.omit": "^4.5.7",
"@types/lodash.throttle": "^4.1.7",
"@types/lodash-es": "^4.17.12",
"@types/uuid": "^9.0.2",
"vite": "^4.2.0"
},
"dependencies": {
"@types/lodash.pick": "^4.4.9",
"lodash.clonedeep": "^4.5.0",
"lodash.debounce": "^4.0.8",
"lodash.isequal": "^4.5.0",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"lodash.throttle": "^4.1.1",
"lodash-es": "^4.17.21",
"uuid": "^9.0.0"
}
}
9 changes: 1 addition & 8 deletions packages/common/src/lodash.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import cloneDeep from 'lodash.clonedeep';
import debounce from 'lodash.debounce';
import isEqual from 'lodash.isequal';
import omit from 'lodash.omit';
import pick from 'lodash.pick';
import throttle from 'lodash.throttle';

export { cloneDeep, debounce, isEqual, omit, pick, throttle };
export { cloneDeep, debounce, isEqual, omit, pick, throttle } from 'lodash-es';
2 changes: 1 addition & 1 deletion packages/core/src/graphics/ellipse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class SuikaEllipse extends SuikaGraphics<EllipseAttrs> {

override getLayerIconPath() {
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graphics/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class SuikaLine extends SuikaGraphics<LineAttrs> {

override getLayerIconPath() {
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graphics/path/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export class SuikaPath extends SuikaGraphics<PathAttrs> {

override getLayerIconPath(): string {
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/graphics/rect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { cloneDeep, parseHexToRGBA, parseRGBAStr } from '@suika/common';
import {
cloneDeep,
parseHexToRGBA,
parseRGBAStr,
remainDecimal,
} from '@suika/common';
import {
applyMatrix,
getPointsBbox,
Expand Down Expand Up @@ -409,7 +414,7 @@ export class SuikaRect extends SuikaGraphics<RectAttrs> {

override getLayerIconPath() {
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down Expand Up @@ -440,7 +445,11 @@ export class SuikaRect extends SuikaGraphics<RectAttrs> {

return `M${vertices
.map(
(item) => `${item.x.toFixed(precision)} ${item.y.toFixed(precision)}`,
(item) =>
`${remainDecimal(item.x, precision)} ${remainDecimal(
item.y,
precision,
)}`,
)
.join('L')}Z`;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graphics/regular_polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class SuikaRegularPolygon extends SuikaGraphics<RegularPolygonAttrs> {

override getLayerIconPath() {
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graphics/star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class SuikaStar extends SuikaGraphics<StarAttrs> {
override getLayerIconPath() {
// TODD: to optimize as same as regular polygon, no repeat code
const containerSize = 12;
const padding = 1;
const padding = 0.5;
const precision = 5;

const targetSize = containerSize - padding * 2;
Expand Down
9 changes: 8 additions & 1 deletion packages/geo/src/geo/geo_path_class.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { remainDecimal } from '@suika/common';

import {
type IPathCommand,
type IPathItem,
Expand Down Expand Up @@ -157,7 +159,12 @@ export const commandsToStr = (commands: IPathCommand[], precision: number) => {
(cmd) =>
cmd.type +
cmd.points
.map((pt) => pt.x.toFixed(precision) + ' ' + pt.y.toFixed(precision))
.map(
(pt) =>
remainDecimal(pt.x, precision) +
' ' +
remainDecimal(pt.y, precision),
)
.join(' '),
)
.join(' ');
Expand Down
Loading

0 comments on commit c872b5b

Please sign in to comment.