Skip to content

Commit 2062e8d

Browse files
committed
Further performance improvements #44
1 parent 5e7a3ee commit 2062e8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4534
-1984
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
[![typescript version](https://img.shields.io/badge/typescript-5.6.3-brightgreen)](https://www.typescriptlang.org/)
88
[![prettier version](https://img.shields.io/badge/prettier-2.8.8-brightgreen)](https://prettier.io/)
99
[![eslint version](https://img.shields.io/badge/eslint-8.57.1-brightgreen)](https://github.com/eslint)
10-
[![vitest version](https://img.shields.io/badge/vitest-2.1.2-brightgreen)](https://vitest.dev/)
11-
[![vite version](https://img.shields.io/badge/vite-5.4.8-brightgreen)](https://vitejs.dev/)
10+
[![vitest version](https://img.shields.io/badge/vitest-2.1.3-brightgreen)](https://vitest.dev/)
11+
[![vite version](https://img.shields.io/badge/vite-5.4.9-brightgreen)](https://vitejs.dev/)
1212

1313
![image](./docs/assets/SVGPathCommander.svg)
1414

deno.lock

Lines changed: 2194 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/svg-path-commander.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/svg-path-commander.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/svg-path-commander.d.ts

Lines changed: 207 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export type SegmentProperties = {
55
index: number;
66
length: number;
77
lengthAtSegment: number;
8-
[key: string]: any;
98
};
109
export type PointProperties = {
1110
closest: {
@@ -443,7 +442,49 @@ export type LineCoordinates = [
443442
number
444443
];
445444
export type DeriveCallback = (t: number) => Point;
446-
export type IteratorCallback = (segment: PathSegment, params: ParserParams, index: number) => PathSegment;
445+
export type IteratorCallback = (segment: PathSegment, index: number, lastX: number, lastY: number) => PathSegment | false | void | undefined;
446+
declare const arcLength: (rx: number, ry: number, theta: number) => number;
447+
declare const arcPoint: (cx: number, cy: number, rx: number, ry: number, alpha: number, theta: number) => {
448+
x: number;
449+
y: number;
450+
};
451+
declare const angleBetween: (v0: Point, v1: Point) => number;
452+
declare const getArcProps: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => {
453+
rx: number;
454+
ry: number;
455+
startAngle: number;
456+
endAngle: number;
457+
center: {
458+
x: number;
459+
y: number;
460+
};
461+
};
462+
declare const getArcLength: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => number;
463+
declare const getPointAtArcLength: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number, distance?: number) => {
464+
x: number;
465+
y: number;
466+
};
467+
declare const getArcBBox: (x1: number, y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, x: number, y: number) => {
468+
min: {
469+
x: number;
470+
y: number;
471+
};
472+
max: {
473+
x: number;
474+
y: number;
475+
};
476+
};
477+
declare class PathParser {
478+
segments: PathArray | PathSegment[];
479+
pathValue: string;
480+
max: number;
481+
index: number;
482+
param: number;
483+
segmentStart: number;
484+
data: (string | number)[];
485+
err: string;
486+
constructor(pathString: string);
487+
}
447488
/**
448489
* Creates a new SVGPathCommander instance with the following properties:
449490
* * segments: `pathArray`
@@ -456,7 +497,130 @@ export type IteratorCallback = (segment: PathSegment, params: ParserParams, inde
456497
*/
457498
declare class SVGPathCommander {
458499
static CSSMatrix: typeof CSSMatrix$1;
459-
static getSVGMatrix: (transform: TransformObjectValues) => CSSMatrix$1;
500+
static pathToAbsolute: (pathInput: string | PathArray) => AbsoluteArray;
501+
static pathToRelative: (pathInput: string | PathArray) => RelativeArray;
502+
static pathToCurve: (pathInput: string | PathArray) => CurveArray;
503+
static pathToString: (path: PathArray, roundOption?: number | "off") => string;
504+
static arcTools: typeof arcTools;
505+
static bezierTools: {
506+
Cvalues: number[];
507+
Tvalues: number[];
508+
minmaxC: ([v1, cp1, cp2, v2]: [
509+
number,
510+
number,
511+
number,
512+
number
513+
]) => PointTuple;
514+
minmaxQ: ([v1, cp, v2]: [
515+
number,
516+
number,
517+
number
518+
]) => PointTuple;
519+
getBezierLength: (curve: CubicCoordinates | QuadCoordinates) => number;
520+
bezierLength: (derivativeFn: DeriveCallback) => number;
521+
calculateBezier: (derivativeFn: DeriveCallback, t: number) => number;
522+
computeBezier: (points: DerivedQuadPoints | DerivedCubicPoints, t: number) => DerivedPoint;
523+
deriveBezier: (points: QuadPoints | CubicPoints) => (DerivedQuadPoints | DerivedCubicPoints)[];
524+
CBEZIER_MINMAX_EPSILON: number;
525+
};
526+
static cubicTools: {
527+
getCubicLength: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => number;
528+
getCubicBBox: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => {
529+
min: {
530+
x: number;
531+
y: number;
532+
};
533+
max: {
534+
x: number;
535+
y: number;
536+
};
537+
};
538+
getPointAtCubicLength: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number, distance?: number) => {
539+
x: number;
540+
y: number;
541+
};
542+
getPointAtCubicSegmentLength: ([x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates, t: number) => {
543+
x: number;
544+
y: number;
545+
};
546+
};
547+
static lineTools: {
548+
getPointAtLineLength: (x1: number, y1: number, x2: number, y2: number, distance?: number) => {
549+
x: number;
550+
y: number;
551+
};
552+
getLineBBox: (x1: number, y1: number, x2: number, y2: number) => {
553+
min: {
554+
x: number;
555+
y: number;
556+
};
557+
max: {
558+
x: number;
559+
y: number;
560+
};
561+
};
562+
getLineLength: (x1: number, y1: number, x2: number, y2: number) => number;
563+
};
564+
static quadTools: {
565+
getPointAtQuadSegmentLength: ([x1, y1, cx, cy, x2, y2]: QuadCoordinates, t: number) => {
566+
x: number;
567+
y: number;
568+
};
569+
getQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => number;
570+
getQuadBBox: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => {
571+
min: {
572+
x: number;
573+
y: number;
574+
};
575+
max: {
576+
x: number;
577+
y: number;
578+
};
579+
};
580+
getPointAtQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number, distance?: number) => {
581+
x: number;
582+
y: number;
583+
};
584+
};
585+
static polygonTools: {
586+
polygonArea: (polygon: PointTuple[]) => number;
587+
polygonLength: (polygon: PointTuple[]) => number;
588+
};
589+
static distanceSquareRoot: (a: PointTuple, b: PointTuple) => number;
590+
static distanceEpsilon: number;
591+
static midPoint: (a: PointTuple, b: PointTuple, t: number) => PointTuple;
592+
static rotateVector: (x: number, y: number, rad: number) => {
593+
x: number;
594+
y: number;
595+
};
596+
static roundTo: (n: number, round: number) => number;
597+
static finalizeSegment: (path: PathParser) => void;
598+
static invalidPathValue: string;
599+
static isArcCommand: (code: number) => code is 97;
600+
static isDigit: (code: number) => code is DigitNumber;
601+
static isDigitStart: (code: number) => code is DigitNumber | 43 | 45 | 46;
602+
static isMoveCommand: (code: number) => code is 109 | 77;
603+
static isPathCommand: (code: number) => code is PathCommandNumber;
604+
static isSpace: (ch: number) => ch is SpaceNumber;
605+
static paramsCount: {
606+
a: number;
607+
c: number;
608+
h: number;
609+
l: number;
610+
m: number;
611+
r: number;
612+
q: number;
613+
s: number;
614+
t: number;
615+
v: number;
616+
z: number;
617+
};
618+
static paramsParser: ParserParams;
619+
static pathParser: typeof PathParser;
620+
static scanFlag: (path: PathParser) => void;
621+
static scanParam: (path: PathParser) => void;
622+
static scanSegment: (path: PathParser) => void;
623+
static skipSpaces: (path: PathParser) => void;
460624
static getPathBBox: (pathInput: PathArray | string) => {
461625
x: number;
462626
y: number;
@@ -476,12 +640,7 @@ declare class SVGPathCommander {
476640
y: number;
477641
};
478642
static getPropertiesAtLength: (pathInput: string | PathArray, distance?: number) => SegmentProperties;
479-
static getPropertiesAtPoint: (pathInput: string | PathArray, point: {
480-
x: number;
481-
y: number;
482-
}) => PointProperties;
483-
static polygonLength: (polygon: PointTuple[]) => number;
484-
static polygonArea: (polygon: PointTuple[]) => number;
643+
static getPropertiesAtPoint: (pathInput: string | PathArray, point: Point) => PointProperties;
485644
static getClosestPoint: (pathInput: string | PathArray, point: {
486645
x: number;
487646
y: number;
@@ -506,22 +665,47 @@ declare class SVGPathCommander {
506665
static isNormalizedArray: (path: unknown) => path is NormalArray;
507666
static shapeToPath: (element: ShapeTypes | ShapeOps, replace?: boolean, ownerDocument?: Document) => SVGPathElement | false;
508667
static shapeToPathArray: (element: ShapeTypes | ShapeOps, ownerDocument?: Document) => false | PathArray;
509-
static parsePathString: (pathInput: string | PathArray) => PathArray;
668+
static shapeParams: ShapeParams;
669+
static parsePathString: <T extends PathArray>(pathInput: string | T) => PathArray;
670+
static absolutizeSegment: (segment: PathSegment, index: number, lastX: number, lastY: number) => AbsoluteSegment;
671+
static arcToCubic: (X1: number, Y1: number, RX: number, RY: number, angle: number, LAF: number, SF: number, X2: number, Y2: number, recursive?: [
672+
number,
673+
number,
674+
number,
675+
number
676+
]) => number[];
677+
static getSVGMatrix: (transform: TransformObjectValues) => CSSMatrix$1;
678+
static iterate: <T extends PathArray>(path: PathArray, iterator: IteratorCallback) => T;
679+
static lineToCubic: (x1: number, y1: number, x2: number, y2: number) => number[];
680+
static normalizePath: (pathInput: string | PathArray) => NormalArray;
681+
static normalizeSegment: (segment: PathSegment, params: ParserParams) => NormalSegment;
682+
static optimizePath: (pathInput: PathArray, roundOption: number) => PathArray;
683+
static projection2d: (m: CSSMatrix$1, point2D: PointTuple, origin: [
684+
number,
685+
number,
686+
number
687+
]) => PointTuple;
688+
static quadToCubic: (x1: number, y1: number, qx: number, qy: number, x2: number, y2: number) => [
689+
number,
690+
number,
691+
number,
692+
number,
693+
number,
694+
number
695+
];
696+
static relativizeSegment: (segment: PathSegment, index: number, lastX: number, lastY: number) => MSegment | RelativeSegment;
697+
static reverseCurve: (path: CurveArray) => CurveArray;
698+
static reversePath: (pathInput: PathArray) => PathArray;
510699
static roundPath: (path: PathArray, roundOption?: number | "off") => PathArray;
511-
static splitPath: (pathInput: PathArray) => PathArray[];
700+
static roundSegment: <T extends PathSegment>(segment: T, roundOption: number) => T;
701+
static segmentToCubic: (segment: PathSegment, params: ParserParams) => MSegment | CSegment;
702+
static shortenSegment: (segment: AbsoluteSegment, normalSegment: NormalSegment, params: ParserParams, prevCommand: PathCommand) => ShortSegment;
512703
static splitCubic: (pts: number[], ratio?: number) => [
513704
CubicSegment,
514705
CubicSegment
515706
];
516-
static optimizePath: (pathInput: PathArray, round: "off" | number) => PathArray;
517-
static reverseCurve: (path: CurveArray) => CurveArray;
518-
static reversePath: (pathInput: PathArray) => PathArray;
519-
static normalizePath: (pathInput: string | PathArray) => NormalArray;
707+
static splitPath: (pathInput: PathArray) => PathArray[];
520708
static transformPath: (pathInput: PathArray | string, transform?: Partial<TransformObject>) => PathArray;
521-
static pathToAbsolute: (pathInput: string | PathArray) => AbsoluteArray;
522-
static pathToRelative: (pathInput: string | PathArray) => RelativeArray;
523-
static pathToCurve: (pathInput: string | PathArray) => CurveArray;
524-
static pathToString: (path: PathArray, round?: number | "off") => string;
525709
segments: PathArray;
526710
round: number | "off";
527711
origin: [
@@ -657,6 +841,10 @@ declare class SVGPathCommander {
657841
toString(): string;
658842
}
659843

844+
declare namespace arcTools {
845+
export { angleBetween, arcLength, arcPoint, getArcBBox, getArcLength, getArcProps, getPointAtArcLength };
846+
}
847+
660848
export {
661849
SVGPathCommander as default,
662850
};

dist/svg-path-commander.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/svg-path-commander.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)