UNPKG

fabric-texture

Version:

This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.

50 lines (49 loc) 1.53 kB
/** * 在直线上计算特定距离的点坐标 * * 在由两点确定的直线上,从起点出发计算特定距离处的点坐标。 * 该函数处理了以下情况: * 1. 两点重合的特殊情况 * 2. 垂直于坐标轴的直线 * 3. 水平于坐标轴的直线 * 4. 一般斜线情况 * * @param p0 - 起点坐标 * @property {number} x - x坐标 * @property {number} y - y坐标 * @param p1 - 方向参考点坐标 * @property {number} x - x坐标 * @property {number} y - y坐标 * @param value - 目标距离 * - 正值:向 p1 方向移动 * - 负值:向 p1 相反方向移动 * - 零值:返回起点坐标 * * @returns {Coord} 计算得到的新坐标点 * * @example * ```typescript * // 在水平线上移动 * const start = { x: 0, y: 0 }; * const direction = { x: 10, y: 0 }; * * // 向右移动5个单位 * const point1 = calcRelativeCoord(start, direction, 5); * console.log(point1); // { x: 5, y: 0 } * * // 向左移动3个单位 * const point2 = calcRelativeCoord(start, direction, -3); * console.log(point2); // { x: -3, y: 0 } * * // 在斜线上移动 * const diagonal = { x: 3, y: 4 }; * const point3 = calcRelativeCoord(start, diagonal, 5); * // 返回在斜线方向上距离为5的点 * ``` * * @remarks * - 如果两点重合,返回起点坐标 * - 支持任意方向的直线 * - 计算结果精度受 JavaScript 浮点数精度限制 */ export declare const calcRelativeCoord: (p0: Coord, p1: Coord, value: number) => Coord;