跳到主要内容

KBoundingBox2d 接口

export interface KBoundingBox2d 

KBoundingBox2d类代表着二维空间中的一个包围盒。

The KBoundingBox2d class represents a bounding box in 2d space.

属性

center

readonly center: KPoint2d;

获取包围盒的中心点。

Get bounding box' center point.

类型: KPoint2d

height

readonly height: number;

获取包围盒的高度(y方向)。

Get bounding box' height (y direction).

max

readonly max: KPoint2d;

获取包围盒的右上端点。

Get bounding box' maximum point.

类型: KPoint2d

min

readonly min: KPoint2d;

获取包围盒的左下端点。

Get bounding box' minimum point.

类型: KPoint2d

width

readonly width: number;

获取包围盒的宽度(x方向)。

Get bounding box' width (x direction).

方法

addPoint

addPoint(point: KPoint2d): void;

包围盒加入一个点,包围盒的表征范围会改变。

Add point into bounding box, bounding box's min and max will maybe be changed.

参数:

  • point: KPoint2d

    要加入的点。

    the added point.

返回值: void

expand

expand(delta: number): void;

包围盒的范围各向扩大一个Δ。 注意:如何Δ是一个负数,则包围盒的控制范围会减小,甚至会反转。

Expand the bounding box by a delta value. NOTE: if delta is a minus value, bounding box will be shrunk or even be reversed.

参数:

  • delta: number

    扩张参数。

    The expanded coefficient.

返回值: void

isEqual

isEqual(other: KBoundingBox2d, tolerance?: number): boolean;

在指定的容差下检查两个包围盒是否相等。

Check whether two bounding boxes are equal with specified tolerances.

参数:

  • other: KBoundingBox2d

    需要被比较的包围盒。

    The bounding box to compare this bounding box with.

  • tolerance: number

    指定容差·1,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: boolean

两者相等返回true,否则为false。

Return true if equal, otherwise return false.

isInside

isInside(other: KBoundingBox2d, tolerance?: number): boolean;

检查输入包围盒在指定容差下是否落在包围盒中。 注意:包围盒的区域范围包括包围盒边界。

Check whether this bounding box is in the input bounding box with specified tolerance. NOTE: boundary is included.

参数:

  • other: KBoundingBox2d

    传入包围盒。

    The input bounding box.

  • tolerance: number

    传入容差。

    The specified tolerance.

返回值: boolean

当输入包围盒落在包围盒中,返回true。

Return True if this box is inside the input box, otherwise return false.

isOverlapping

isOverlapping(other: KBoundingBox2d, tolerance?: number): boolean;

检查传入包围盒在指定容差下,与当前包围盒是否有重叠区域。 注意:重叠区域的子集包括两个包围盒为嵌套关系。

Check whether this input bounding box and this bounding box share the same space with specified tolerance. NOTE: 'inside' relationship is included.

参数:

  • other: KBoundingBox2d

    传入包围盒。

    The input bounding box.

  • tolerance: number

    传入容差。

    The specified tolerance.

返回值: boolean

当输入包围盒与当前包围盒有共同区域,返回true。

Return true if two box share the same space, otherwise return false.

isPointInside

isPointInside(point: KPoint2d, tolerance?: number): boolean;

检查输入点在指定容差下是否落在包围盒中。 注意:包围盒的区域范围包括包围盒边界。

Check whether the input point is in this bounding box with specified tolerance. NOTE: boundary is included.

参数:

  • point: KPoint2d

    输入点。

    The input point.

  • tolerance: number

    传入容差。

    The specified tolerance.

返回值: boolean

当输入点落在包围盒中,返回true。

Return True if the input point is inside this box, otherwise return false.

isValid

isValid(): boolean;

包围盒是否有效。

Whether this bounding box is valid.

返回值: boolean

当左下角点的坐标小于右上角的坐标时返回true。

True will be returned if min's xy are smaller or equal to max' xy.

merge

merge(box: KBoundingBox2d): void;

合并另外一个包围盒,使得当前包围盒可以包围传入包围盒。

Merge another bounding box, thus this bounding box is able to contain the another box.

参数:

  • box: KBoundingBox2d

    要合并的包围盒。

    The merged bounding box.

返回值: void