Skip to content

bounds

元素的边界属性, 可通过 Bounds 类使用边界。

包围盒

只读属性

画面排版的基础,从元素的宽高、笔触、阴影计算而来。

boxBounds: IBoundsData

相对内部坐标的基础边界(OBB 包围盒)。

renderBounds: IBoundsData

相对内部坐标的渲染边界(AABB 包围盒)

worldBoxBounds: IBoundsData

相对世界坐标的基础边界(AABB 包围盒)。

通过 boxBounds 与 worldTransform 相乘而来,如果元素旋转了,则是旋转之后取出的新边界。

worldRenderBounds: IBoundsData

相对世界坐标的渲染边界(AABB 包围盒)。

来源于

width: number

元素的宽度。

TIP

当宽度为负数时,为让程序继续运行,将重置为正数,并使用 -scaleX 镜像代替,开发环境中会发出一个警告。

height: number

元素的高度。

TIP

当高度为负数时,为让程序继续运行,将重置为正数,并使用 -scaleY 镜像代替,开发环境中会发出一个警告。

关键方法

出于性能和安全考虑,返回的数据为只读对象。

getBounds ( type: IBoundsType = 'box', relative?: ILocationType | UI = 'world' ): IBoundsData

获取 AABB 包围盒(边界)。

可获取不同 坐标体系 下的不同 边界类型,relative 可指定坐标体系或相对元素

getLayoutBounds ( type: IBoundsType = 'box', relative?: ILocationType | UI = 'world', unscale?: boolean ): ILayoutBoundsData

获取 OBB 包围盒(边界),含缩放、旋转等布局属性。

可设置 unscale = true 将 scale 转换为宽高,不过仍存在 scaleX / scaleY 为 -1 的镜像情况。

getLayoutPoints ( type: IBoundsType = 'box', relative: ILocationType | UI = 'world' ): IPointData[]

获取 OBB 包围盒(边界)的四个坐标点 [topLeft, topRight, bottomRight, bottomLeft]。

ts
type ILocationType = 'world' | 'local' | 'inner' // 坐标体系
type IBoundsType = 'content' | 'box' | 'stroke' | 'margin' | 'render' // 边界类型

rect.getBounds('box', 'local')
rect.getLayoutBounds('box', 'inner')
rect.getLayoutPoints('box', rect.leafer)

// 结合Bounds使用
new Bounds(rect.getBounds('box', 'local'))

边界转换

getWorldBounds ( inner: IBoundsData, relative?: UI, change?: boolean): IBoundsData

获取世界坐标的边界(AABB 包围盒,传入一个 内部坐标系 的边界进行转换)。

第二个可选参数:relative?: UI

relative 元素假设为世界坐标系,可以实现子级到任意一个父级坐标系之间的转换。

第三个可选参数:change?: boolean

直接修改传入的边界返回,可以节省创建新对象的开销。

归属

UI

Released under the MIT License.