SYS_Math.getBBox() method
获取多边形的最小外接矩形(BBox)
签名
typescript
function getBBox(polygon: TSYS_MathPolygonInput): ISYS_MathBBox;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形 |
返回值
BBox
示例
javascript
// 1. 斜置的三角形,外接矩形由三个顶点的极值决定
const triangle = [{ x: 30, y: 10 }, { x: 120, y: 50 }, { x: 60, y: 90 }];
const bbox = eda.sys_Math.getBBox(triangle);
console.log('三角形的最小外接矩形:', JSON.stringify(bbox));
// 2. 布尔运算得到的多边形组同样可以求 BBox(取整组的外包范围)
const rectA = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const rectB = [{ x: 50, y: 20 }, { x: 150, y: 20 }, { x: 150, y: 60 }, { x: 50, y: 60 }];
const merged = eda.sys_Math.union(rectA, rectB);
console.log('合并区域的最小外接矩形:', JSON.stringify(eda.sys_Math.getBBox(merged)));
// 3. BBox 直接作为 bboxIntersects() 的输入做快速相交预检
const other = { minX: 200, minY: 0, maxX: 280, maxY: 40 };
console.log('两区域外接矩形相交:', eda.sys_Math.bboxIntersects(bbox, other));1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14