fabric-texture
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
72 lines (40 loc) • 1.05 kB
Markdown
[**fabric-texture**](../../../../README.md)
***
# Function: calcExpandCoord()
> **calcExpandCoord**(`a`, `b`, `c`, `expandValue`): `object`
计算点在线段方向上的扩展坐标
将点 a 沿着其到线段 bc 的垂线方向扩展指定距离。
## Parameters
### a
`Coord`
需要扩展的点坐标
### b
`Coord`
参考线段的起点
### c
`Coord`
参考线段的终点
### expandValue
`number` = `1`
扩展距离,默认为 1 个单位
## Returns
`object`
扩展后的坐标点
### x
> **x**: `number`
### y
> **y**: `number`
## Example
```typescript
// 基础用法
const point = { x: 0, y: 0 };
const lineStart = { x: -1, y: 1 };
const lineEnd = { x: 1, y: 1 };
const expanded = calcExpandCoord(point, lineStart, lineEnd);
// 结果:点会向远离线段的方向移动 1 个单位
// 自定义扩展距离
const expandedMore = calcExpandCoord(point, lineStart, lineEnd, 2);
// 结果:点会向远离线段的方向移动 2 个单位
```
## Remarks
- 如果点在线段上,扩展方向将垂直于线段