UNPKG

2.44 kBTypeScriptView Raw
1import { DIRECTION } from '../constant';
2import { Padding, Point, Region } from '../interface';
3import { BBox as BBoxObject } from '../dependents';
4/**
5 * 用于包围盒计算。
6 */
7export declare class BBox {
8 /** x 轴坐标系 */
9 x: number;
10 /** y 轴坐标系 */
11 y: number;
12 /** 包围盒高度 */
13 height: number;
14 /** 包围盒宽度 */
15 width: number;
16 static fromRange(minX: number, minY: number, maxX: number, maxY: number): BBox;
17 static fromObject(bbox: BBoxObject): BBox;
18 constructor(x?: number, y?: number, width?: number, height?: number);
19 get minX(): number;
20 get maxX(): number;
21 get minY(): number;
22 get maxY(): number;
23 get tl(): Point;
24 get tr(): Point;
25 get bl(): Point;
26 get br(): Point;
27 get top(): Point;
28 get right(): Point;
29 get bottom(): Point;
30 get left(): Point;
31 /**
32 * 包围盒是否相等
33 * @param {BBox} bbox 包围盒
34 * @returns 包围盒是否相等
35 */
36 isEqual(bbox: BBox): boolean;
37 /**
38 * 是否包含了另一个包围盒
39 * @param child
40 */
41 contains(child: BBox): boolean;
42 /**
43 * 克隆包围盒
44 * @returns 包围盒
45 */
46 clone(): BBox;
47 /**
48 * 取并集
49 * @param subBBox
50 */
51 add(...subBBox: BBox[]): BBox;
52 /**
53 * 取交集
54 * @param subBBox
55 */
56 merge(...subBBox: BBox[]): BBox;
57 /**
58 * bbox 剪裁
59 * @param subBBox
60 * @param direction
61 */
62 cut(subBBox: BBox, direction: DIRECTION): BBox;
63 /**
64 * 收缩形成新的
65 * @param gap
66 */
67 shrink(gap: Padding): BBox;
68 /**
69 * 扩张形成新的
70 * @param gap
71 */
72 expand(gap: Padding): BBox;
73 /**
74 * get the gap of two bbox, if not exceed, then 0
75 * @param bbox
76 * @returns [top, right, bottom, left]
77 */
78 exceed(bbox: BBox): Padding;
79 /**
80 * 是否碰撞
81 * @param bbox
82 */
83 collide(bbox: BBox): boolean;
84 /**
85 * 获取包围盒大小
86 * @returns 包围盒大小
87 */
88 size(): number;
89 /**
90 * 点是否在 bbox 中
91 * @param p
92 */
93 isPointIn(p: Point): boolean;
94}
95/**
96 * 从一个 bbox 的 region 获取 bbox
97 * @param bbox
98 * @param region
99 */
100export declare const getRegionBBox: (bbox: BBox, region: Region) => BBox;
101/**
102 * 将 bbox 转换成 points
103 * @param bbox
104 */
105export declare function toPoints(bbox: Partial<BBox>): any[];