Skip to content

Commit 07d6e99

Browse files
committed
Changes:
* reverse all previous changes related to sampleSize * added bezier tools by @Pomax to greatly improve performance and accuracy of Q and C segments parsing/processing * added new tools for A segments process/parsing to improve both performance and accuracy * replace older pathLengthFactory with a new pathFactory utility where bbox is a getter property * added 2 new getters for the SVGPathCommmander instance: `length` and `bbox`, where `length` is the path total length and `bbox` is the path bounding box * updated tests * updated dependencies * version bump to 2.1.0
1 parent e52951a commit 07d6e99

Some content is hidden

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

41 files changed

+1777
-1466
lines changed

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module.exports = {
8585
"hoist": "all"
8686
}
8787
],
88+
"@typescript-eslint/no-loss-of-precision": "off",
8889
"@typescript-eslint/no-unused-expressions": "error",
8990
"@typescript-eslint/no-use-before-define": "off",
9091
"@typescript-eslint/no-var-requires": "error",

dist/svg-path-commander.cjs

+1-1
Large diffs are not rendered by default.

dist/svg-path-commander.cjs.map

+1-1
Large diffs are not rendered by default.

dist/svg-path-commander.d.ts

+35-17
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export type LengthFactory = {
143143
export type Options = {
144144
round: "auto" | "off" | number;
145145
origin: number[];
146-
sampleSize: number;
147146
};
148147
export type PathTransform = {
149148
s: PathSegment;
@@ -361,6 +360,10 @@ export type TransformObjectValues = Partial<TransformObject> & {
361360
number
362361
];
363362
};
363+
export type Point = {
364+
x: number;
365+
y: number;
366+
};
364367
/**
365368
* Creates a new SVGPathCommander instance with the following properties:
366369
* * segments: `pathArray`
@@ -374,20 +377,36 @@ export type TransformObjectValues = Partial<TransformObject> & {
374377
declare class SVGPathCommander {
375378
static CSSMatrix: typeof CSSMatrix$1;
376379
static getSVGMatrix: (transform: TransformObjectValues) => CSSMatrix$1;
377-
static getPathBBox: (path: PathArray | string, sampleSize?: number | undefined) => PathBBox;
380+
static getPathBBox: (path: PathArray | string) => PathBBox;
378381
static getPathArea: (path: PathArray) => number;
379-
static getTotalLength: (pathInput: string | PathArray, sampleSize?: number | undefined) => number;
382+
static getTotalLength: (pathInput: string | PathArray) => number;
380383
static getDrawDirection: (path: string | PathArray) => boolean;
381-
static getPointAtLength: (pathInput: string | PathArray, distance: number, sampleSize?: number | undefined) => {
384+
static getPointAtLength: (pathInput: string | PathArray, distance: number) => {
382385
x: number;
383386
y: number;
384387
};
385-
static pathLengthFactory: (pathInput: string | PathArray, distance: number | undefined, sampleSize?: number | undefined) => LengthFactory;
386-
static getPropertiesAtLength: (pathInput: string | PathArray, distance?: number, samplesize?: number) => SegmentProperties;
388+
static pathFactory: (pathInput: string | PathArray, distance?: number) => {
389+
point: {
390+
x: number;
391+
y: number;
392+
};
393+
length: number;
394+
readonly bbox: {
395+
min: {
396+
x: number;
397+
y: number;
398+
};
399+
max: {
400+
x: number;
401+
y: number;
402+
};
403+
};
404+
};
405+
static getPropertiesAtLength: (pathInput: string | PathArray, distance?: number) => SegmentProperties;
387406
static getPropertiesAtPoint: (pathInput: string | PathArray, point: {
388407
x: number;
389408
y: number;
390-
}, sampleSize?: number) => PointProperties;
409+
}) => PointProperties;
391410
static polygonLength: (polygon: [
392411
number,
393412
number
@@ -399,19 +418,19 @@ declare class SVGPathCommander {
399418
static getClosestPoint: (pathInput: string | PathArray, point: {
400419
x: number;
401420
y: number;
402-
}, sampleSize?: number | undefined) => {
421+
}) => {
403422
x: number;
404423
y: number;
405424
};
406425
static getSegmentOfPoint: (path: string | PathArray, point: {
407426
x: number;
408427
y: number;
409-
}, sampleSize?: number | undefined) => SegmentProperties | undefined;
410-
static getSegmentAtLength: (pathInput: string | PathArray, distance?: number, sampleSize?: number) => PathSegment | undefined;
428+
}) => SegmentProperties | undefined;
429+
static getSegmentAtLength: (pathInput: string | PathArray, distance?: number) => PathSegment | undefined;
411430
static isPointInStroke: (pathInput: string | PathArray, point: {
412431
x: number;
413432
y: number;
414-
}, sampleSize?: number) => boolean;
433+
}) => boolean;
415434
static isValidPath: (pathString: string) => boolean;
416435
static isPathArray: (path: unknown) => path is PathArray;
417436
static isAbsoluteArray: (path: unknown) => path is AbsoluteArray;
@@ -450,32 +469,31 @@ declare class SVGPathCommander {
450469
* @param config instance options
451470
*/
452471
constructor(pathValue: string, config?: Partial<Options>);
472+
get bbox(): PathBBox;
473+
get length(): number;
453474
/**
454475
* Returns the path bounding box, equivalent to native `path.getBBox()`.
455476
*
456477
* @public
457-
* @param sampleSize the scan resolution
458478
* @returns the pathBBox
459479
*/
460-
getBBox(sampleSize?: number | undefined): PathBBox;
480+
getBBox(): PathBBox;
461481
/**
462482
* Returns the total path length, equivalent to native `path.getTotalLength()`.
463483
*
464484
* @public
465-
* @param sampleSize the scan resolution
466485
* @returns the path total length
467486
*/
468-
getTotalLength(sampleSize?: number | undefined): number;
487+
getTotalLength(): number;
469488
/**
470489
* Returns an `{x,y}` point in the path stroke at a given length,
471490
* equivalent to the native `path.getPointAtLength()`.
472491
*
473492
* @public
474493
* @param length the length
475-
* @param sampleSize the scan resolution
476494
* @returns the requested point
477495
*/
478-
getPointAtLength(length: number, sampleSize?: number | undefined): {
496+
getPointAtLength(length: number): {
479497
x: number;
480498
y: number;
481499
};

dist/svg-path-commander.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/svg-path-commander.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)