Gathering detailed insights and metrics for @antv/matrix-util
Gathering detailed insights and metrics for @antv/matrix-util
Gathering detailed insights and metrics for @antv/matrix-util
Gathering detailed insights and metrics for @antv/matrix-util
npm install @antv/matrix-util
99
Supply Chain
79.9
Quality
83.6
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
74 Stars
34 Commits
27 Forks
32 Watching
3 Branches
58 Contributors
Updated on 20 Sept 2024
TypeScript (97.92%)
JavaScript (2.08%)
Cumulative downloads
Total Downloads
Last day
-14.1%
58,441
Compared to previous day
Last week
11.3%
344,418
Compared to previous week
Last month
10.6%
1,302,775
Compared to previous month
Last year
8.4%
16,532,148
Compared to previous year
3
3
AntV 底层依赖的工具库,不建议在自己业务中使用。
1import { gradient } from '@antv/util';
提供以下 Path 工具方法,包含转换、几何计算等。
将 PathArray 转换成字符串形式,不会对原始定义中的命令进行修改:
1const str: PathArray = [ 2 ['M', 10, 10], 3 ['L', 100, 100], 4 ['l', 10, 10], 5 ['h', 20], 6 ['v', 20], 7]; 8expect(path2String(str)).toEqual('M10 10L100 100l10 10h20v20');
将 PathArray 转换成数组,不会对原始定义中的命令进行修改:
1const str = 'M10 10L100 100l10 10h20v20'; 2expect(path2Array(str)).toEqual([ 3 ['M', 10, 10], 4 ['L', 100, 100], 5 ['l', 10, 10], 6 ['h', 20], 7 ['v', 20], 8]);
将定义中的相对命令转换成绝对命令,例如:
完整方法签名如下:
1path2Absolute(pathInput: string | PathArray): AbsoluteArray;
1const str: PathArray = [ 2 ['M', 10, 10], 3 ['L', 100, 100], 4 ['l', 10, 10], 5 ['h', 20], 6 ['v', 20], 7]; 8const arr = path2Absolute(str); 9expect(arr).toEqual([ 10 ['M', 10, 10], 11 ['L', 100, 100], 12 ['L', 110, 110], 13 ['H', 130], 14 ['V', 130], 15]);
将部分命令转曲,例如 L / A 转成 C 命令,借助 cubic bezier 易于分割的特性用于实现形变动画。 该方法内部会调用 path2Absolute,因此最终返回的 PathArray 中仅包含 M 和 C 命令。
完整方法签名如下:
1path2Curve(pathInput: string | PathArray): CurveArray;
1expect( 2 path2Curve([ 3 ['M', 0, 0], 4 ['L', 100, 100], 5 ]), 6).toEqual([ 7 ['M', 0, 0], 8 ['C', 44.194173824159215, 44.194173824159215, 68.75, 68.75, 100, 100], 9]);
复制路径:
1const cloned = clonePath(pathInput);
1const pathArray: CurveArray = [ 2 ['M', 170, 90], 3 ['C', 150, 90, 155, 10, 130, 10], 4 ['C', 105, 10, 110, 90, 90, 90], 5 ['C', 70, 90, 75, 10, 50, 10], 6 ['C', 25, 10, 30, 90, 10, 90], 7]; 8 9const reversed = reverseCurve(pathArray);
获取几何定义下的包围盒,形如:
1export interface PathBBox { 2 width: number; 3 height: number; 4 x: number; 5 y: number; 6 x2: number; 7 y2: number; 8 cx: number; 9 cy: number; 10 cz: number; 11}
1const bbox = getPathBBox([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']]); 2 3expect(bbox).toEqual({ cx: 50, cy: 50, cz: 150, height: 100, width: 100, x: 0, x2: 100, y: 0, y2: 100 });
获取路径总长度。
1const length = getTotalLength([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']]); 2 3expect(length).toEqual(400);
获取路径上从起点出发,到指定距离的点。
1const point = getPointAtLength([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']], 0); 2expect(point).toEqual({ x: 0, y: 0 });
计算路径包围的面积。内部实现中首先通过 path2Curve 转曲,再计算 cubic curve 面积,详见。
方法签名如下:
1function getPathArea(path: PathArray): number;
判断一个点是否在路径上,仅通过几何定义计算,不考虑其他样式属性例如线宽、lineJoin、miter 等。
方法签名如下:
1isPointInStroke(pathInput: string | PathArray, point: Point): boolean;
1const result = isPointInStroke(segments, { x: 10, y: 10 });
计算两点之间的距离。
方法签名如下:
1distanceSquareRoot(a: [number, number], b: [number, number]): number;
将两条路径处理成段数相同,用于形变动画前的分割操作。
1const [formattedPath1, formattedPath2] = equalizeSegments(path1, path2);
判断一个点是否在多边形内。多边形形如:
1const polygon = [ 2 [0, 0], 3 [0, 100], 4 [30, 100], 5 [30, 0], 6]; 7 8// [0, 0] 在多边形的边上 9isPointInPolygon(polygon, 0, 0); // true
判断两个多边形是否相交:
1isPolygonsIntersect(polygon1, polygon2);
Build first.
1yarn run benchmarks
We can get the following output in the console, it can be seen that the same method from 5.0 is ~3 times faster than 4.0.
1// logs 2// Path2String#4.0 x 14,795 ops/sec ±3.35% (79 runs sampled) 3// Path2String#5.0 x 51,710 ops/sec ±2.05% (85 runs sampled) 4// Fastest is Path2String#5.0 5 6// Path2Absolute#4.0 x 14,524 ops/sec ±2.55% (80 runs sampled) 7// Path2Absolute#5.0 x 35,120 ops/sec ±3.10% (81 runs sampled) 8// Fastest is Path2Absolute#5.0
MIT@AntV.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
3 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 3
Reason
Found 10/30 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More