DOMQuad:getBounds() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

注意:此功能在 Web Workers 中可用。

DOMQuadgetBounds() 方法返回一个 DOMRect 对象,表示完全包含该 DOMQuad 对象的最小矩形。

语法

js
getBounds()

参数

无。

返回值

一个 DOMRect 对象,包含 x、y、width 和 height 属性,用于根据 DOMQuad 的角坐标定义其边界框。

示例

此示例创建一个具有四个点的 DOMQuad,然后检索其边界矩形。

js
const quad = new DOMQuad(
  { x: 40, y: 25 },
  { x: 180, y: 8 },
  { x: 210, y: 150 },
  { x: 10, y: 180 },
);

const quadBounds = quad.getBounds();

An irregular quadrilateral with none of the sides being vertical or horizontal. Its four corners are marked with red circles. Around this quadrilateral is a dashed rectangle. All sides of this rectangle are vertical or horizontal and tangent the quadrilateral.

该图显示了一个由 DOMQuad 表示的不规则四边形。四个红色的圆圈代表 DOMPoint 属性 p1p4。虚线矩形代表 DOMQuadgetBounds() 方法返回的边界矩形。

规范

规范
Geometry Interfaces Module Level 1
# dom-domquad-getbounds

浏览器兼容性