Skip to content

rendx-bounding

轴对齐包围盒(AABB)的计算与操作,是形状碰撞检测、布局计算的基础。

BoundingBox

typescript
import { BoundingBox } from 'rendx-bounding';

// 创建
const box = BoundingBox.fromRect(10, 20, 100, 80);
const box2 = BoundingBox.fromPoints(10, 20, 110, 100);

计算属性

属性说明
x, y, width, height基本尺寸
cx, cy中心点
right, bottom右/下边界
radius外接圆半径
aspect宽高比
area面积
empty是否为空

方法

方法说明
containsPoint(x, y)点包含检测
containsBox(box)盒包含检测
intersects(box)相交检测
intersection(box)返回相交区域
union(box)返回并集
expandPoint(x, y)扩展包含点
pad(top, right, bottom, left)内边距
vertices()四个顶点