Appearance
@jtopo/core / GeomUtils
Class: GeomUtils
几何顶点(坐标)生成与操作工具类
此类生成的所有顶点坐标均经过归一化([-1, 1])处理。
归一化后的顶点坐标极大地简化了图形变换操作,如缩放、旋转、斜切等。
Since
2.6.0
Table of contents
Constructors
Methods
- getBoundingBox
- getFirstIntersectPoint
- getLineIntersectPoint
- getLineIntersectPoints
- isPointInPolygon
- normalizePoints
- pointsToNormalVecs
- rotatePoints
Constructors
constructor
new GeomUtils()
Methods
getBoundingBox
Static
getBoundingBox(points
): Rectangle
计算一组点的最小外接矩形(Bounding Box)
Parameters
Name | Type | Description |
---|---|---|
points | PointLike [] | 点集合 |
Returns
包含所有点的最小矩形
getFirstIntersectPoint
Static
getFirstIntersectPoint(p1
, p2
, segPoints
, isClosed
): Object
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
segPoints | PointLike [] |
isClosed | boolean |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
getLineIntersectPoint
Static
getLineIntersectPoint(p1
, p2
, p3
, p4
): Object
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
p3 | PointLike |
p4 | PointLike |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
getLineIntersectPoints
Static
getLineIntersectPoints(p1
, p2
, segPoints
, isClosed
): PointLike
[]
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
segPoints | PointLike [] |
isClosed | boolean |
Returns
isPointInPolygon
Static
isPointInPolygon(point
, polygon
): boolean
Parameters
Name | Type |
---|---|
point | PointLike |
polygon | PointLike [] |
Returns
boolean
normalizePoints
Static
normalizePoints(points
): { x
: number
; y
: number
}[]
归一化([-1, 1])到一个尺寸为2x2的正方形内
Parameters
Name | Type | Description |
---|---|---|
points | PointLike [] | 顶点坐标数组 |
Returns
{ x
: number
; y
: number
}[]
坐标归一化后的坐标数组
pointsToNormalVecs
Static
pointsToNormalVecs(out
, points
, isClosed?
): void
点坐标转换为法向向量
Parameters
Name | Type | Default value | Description |
---|---|---|---|
out | vec2 [] | undefined | - |
points | PointLike [] | undefined | 点坐标数组 |
isClosed | boolean | false | 是否闭合 |
Returns
void
向量数组
rotatePoints
Static
rotatePoints(normalPoints
, angle
, cx?
, cy?
): PointLike
[]
旋转点坐标
Parameters
Name | Type | Default value | Description |
---|---|---|---|
normalPoints | PointLike [] | undefined | 归一化坐标数组 |
angle | number | undefined | |
cx | number | 0 | 旋转中心x坐标,默认为几何原点 |
cy | number | 0 | 旋转中心y坐标, 默认为几何原点 |