UNPKG

unit-path

Version:

Get points from paths that like straight lines, quadratic Bessel curves, cubic Bessel curves, circles, arcs

39 lines (38 loc) 1.73 kB
export interface Point { x: number; y: number; } export declare type CurveType = 'LINE' | 'TWO_ORDER_BEZIER' | 'THREE_ORDER_BEZIER' | 'ARC'; export declare type Calculator = (t: number) => Point; export interface UnitPathOptions { decimalPlaces?: number; defaultQuantity?: number; } export default class UnitPath { #private; /** * @param { UnitPathOptions } [options] - 可选 * @param { number } [options.decimalPlaces] - 保留几位小数,不设置则全保留 * @param { number } [options.defaultQuantity] - `getPoints()` 默认获取点的数量 */ constructor(options?: UnitPathOptions); setDecimalPlaces(decimalPlaces?: number): void; setDefaultQuantity(defaultQuantity: number): void; setPath(type: 'ARC', x: number, y: number, r: number, startAngle: number, endAngle: number, anticlockwise?: boolean): UnitPath; setPath(type: 'THREE_ORDER_BEZIER', startPoint: Point, controlPoint1: Point, controlPoint2: Point, endPoint: Point): UnitPath; setPath(type: 'TWO_ORDER_BEZIER', startPoint: Point, controlPoint: Point, endPoint: Point): UnitPath; setPath(type: 'LINE', startPoint: Point, endPoint: Point): UnitPath; /** * 获取路径上指定位置的点 * @param { number } [t] - 点位于路径的位置,取值范围 [0,1] * @returns { Point } 指定位置上的坐标 */ getPoint(t?: number): Point; /** * 获取路径上平均分布的点 * 获取点的数量为 quantity + 1 个点,包含起点和终点 * @param { number } quantity - 获取点的数量 * @returns { Point[] } 平均分布在曲线上指定数量的点组成的数组 */ getPoints(quantity?: number): Point[]; }