@esengine/ecs-framework-math 2.10.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10420 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +20 -11
- package/bin/Animation/Easing.d.ts +0 -244
- package/bin/Animation/Easing.d.ts.map +0 -1
- package/bin/Animation/Easing.js +0 -407
- package/bin/Animation/Easing.js.map +0 -1
- package/bin/Animation/Interpolation.d.ts +0 -172
- package/bin/Animation/Interpolation.d.ts.map +0 -1
- package/bin/Animation/Interpolation.js +0 -327
- package/bin/Animation/Interpolation.js.map +0 -1
- package/bin/Animation/index.d.ts +0 -8
- package/bin/Animation/index.d.ts.map +0 -1
- package/bin/Animation/index.js +0 -8
- package/bin/Animation/index.js.map +0 -1
- package/bin/Circle.d.ts +0 -277
- package/bin/Circle.d.ts.map +0 -1
- package/bin/Circle.js +0 -496
- package/bin/Circle.js.map +0 -1
- package/bin/Collision/CollisionDetector.d.ts +0 -114
- package/bin/Collision/CollisionDetector.d.ts.map +0 -1
- package/bin/Collision/CollisionDetector.js +0 -353
- package/bin/Collision/CollisionDetector.js.map +0 -1
- package/bin/Collision/index.d.ts +0 -7
- package/bin/Collision/index.d.ts.map +0 -1
- package/bin/Collision/index.js +0 -7
- package/bin/Collision/index.js.map +0 -1
- package/bin/Color.d.ts +0 -277
- package/bin/Color.d.ts.map +0 -1
- package/bin/Color.js +0 -470
- package/bin/Color.js.map +0 -1
- package/bin/Fixed32.d.ts +0 -266
- package/bin/Fixed32.d.ts.map +0 -1
- package/bin/Fixed32.js +0 -381
- package/bin/Fixed32.js.map +0 -1
- package/bin/FixedMath.d.ts +0 -109
- package/bin/FixedMath.d.ts.map +0 -1
- package/bin/FixedMath.js +0 -264
- package/bin/FixedMath.js.map +0 -1
- package/bin/FixedVector2.d.ts +0 -293
- package/bin/FixedVector2.d.ts.map +0 -1
- package/bin/FixedVector2.js +0 -413
- package/bin/FixedVector2.js.map +0 -1
- package/bin/MathUtils.d.ts +0 -312
- package/bin/MathUtils.d.ts.map +0 -1
- package/bin/MathUtils.js +0 -500
- package/bin/MathUtils.js.map +0 -1
- package/bin/Matrix3.d.ts +0 -288
- package/bin/Matrix3.d.ts.map +0 -1
- package/bin/Matrix3.js +0 -542
- package/bin/Matrix3.js.map +0 -1
- package/bin/Rectangle.d.ts +0 -266
- package/bin/Rectangle.d.ts.map +0 -1
- package/bin/Rectangle.js +0 -437
- package/bin/Rectangle.js.map +0 -1
- package/bin/Vector2.d.ts +0 -333
- package/bin/Vector2.d.ts.map +0 -1
- package/bin/Vector2.js +0 -484
- package/bin/Vector2.js.map +0 -1
- package/bin/Vector3.d.ts +0 -257
- package/bin/Vector3.d.ts.map +0 -1
- package/bin/Vector3.js +0 -372
- package/bin/Vector3.js.map +0 -1
- package/bin/index.d.ts +0 -25
- package/bin/index.d.ts.map +0 -1
- package/bin/index.js +0 -32
- package/bin/index.js.map +0 -1
- package/bin/nodes/ColorNodes.d.ts +0 -70
- package/bin/nodes/ColorNodes.d.ts.map +0 -1
- package/bin/nodes/ColorNodes.js +0 -427
- package/bin/nodes/ColorNodes.js.map +0 -1
- package/bin/nodes/FixedNodes.d.ts +0 -98
- package/bin/nodes/FixedNodes.d.ts.map +0 -1
- package/bin/nodes/FixedNodes.js +0 -612
- package/bin/nodes/FixedNodes.js.map +0 -1
- package/bin/nodes/FixedVectorNodes.d.ts +0 -58
- package/bin/nodes/FixedVectorNodes.d.ts.map +0 -1
- package/bin/nodes/FixedVectorNodes.js +0 -330
- package/bin/nodes/FixedVectorNodes.js.map +0 -1
- package/bin/nodes/VectorNodes.d.ts +0 -62
- package/bin/nodes/VectorNodes.d.ts.map +0 -1
- package/bin/nodes/VectorNodes.js +0 -355
- package/bin/nodes/VectorNodes.js.map +0 -1
- package/bin/nodes/index.d.ts +0 -20
- package/bin/nodes/index.d.ts.map +0 -1
- package/bin/nodes/index.js +0 -27
- package/bin/nodes/index.js.map +0 -1
package/bin/Rectangle.d.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from './Vector2';
|
|
2
|
-
/**
|
|
3
|
-
* 2D矩形类
|
|
4
|
-
*
|
|
5
|
-
* 表示一个轴对齐的矩形,提供矩形相关的几何运算功能:
|
|
6
|
-
* - 矩形创建和属性获取
|
|
7
|
-
* - 包含检测(点、矩形)
|
|
8
|
-
* - 相交检测和计算
|
|
9
|
-
* - 变换和操作
|
|
10
|
-
*/
|
|
11
|
-
export declare class Rectangle {
|
|
12
|
-
/** 矩形左上角X坐标 */
|
|
13
|
-
x: number;
|
|
14
|
-
/** 矩形左上角Y坐标 */
|
|
15
|
-
y: number;
|
|
16
|
-
/** 矩形宽度 */
|
|
17
|
-
width: number;
|
|
18
|
-
/** 矩形高度 */
|
|
19
|
-
height: number;
|
|
20
|
-
/**
|
|
21
|
-
* 创建矩形
|
|
22
|
-
* @param x 左上角X坐标,默认为0
|
|
23
|
-
* @param y 左上角Y坐标,默认为0
|
|
24
|
-
* @param width 宽度,默认为0
|
|
25
|
-
* @param height 高度,默认为0
|
|
26
|
-
*/
|
|
27
|
-
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
28
|
-
/** 空矩形 */
|
|
29
|
-
static readonly EMPTY: Rectangle;
|
|
30
|
-
/** 获取左边界 */
|
|
31
|
-
get left(): number;
|
|
32
|
-
/** 获取右边界 */
|
|
33
|
-
get right(): number;
|
|
34
|
-
/** 获取上边界 */
|
|
35
|
-
get top(): number;
|
|
36
|
-
/** 获取下边界 */
|
|
37
|
-
get bottom(): number;
|
|
38
|
-
/** 获取中心X坐标 */
|
|
39
|
-
get centerX(): number;
|
|
40
|
-
/** 获取中心Y坐标 */
|
|
41
|
-
get centerY(): number;
|
|
42
|
-
/** 获取中心点 */
|
|
43
|
-
get center(): Vector2;
|
|
44
|
-
/** 获取左上角点 */
|
|
45
|
-
get topLeft(): Vector2;
|
|
46
|
-
/** 获取右上角点 */
|
|
47
|
-
get topRight(): Vector2;
|
|
48
|
-
/** 获取左下角点 */
|
|
49
|
-
get bottomLeft(): Vector2;
|
|
50
|
-
/** 获取右下角点 */
|
|
51
|
-
get bottomRight(): Vector2;
|
|
52
|
-
/** 获取面积 */
|
|
53
|
-
get area(): number;
|
|
54
|
-
/** 获取周长 */
|
|
55
|
-
get perimeter(): number;
|
|
56
|
-
/** 检查是否为空矩形 */
|
|
57
|
-
get isEmpty(): boolean;
|
|
58
|
-
/** 检查是否为正方形 */
|
|
59
|
-
get isSquare(): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* 设置矩形属性
|
|
62
|
-
* @param x 左上角X坐标
|
|
63
|
-
* @param y 左上角Y坐标
|
|
64
|
-
* @param width 宽度
|
|
65
|
-
* @param height 高度
|
|
66
|
-
* @returns 当前矩形实例(链式调用)
|
|
67
|
-
*/
|
|
68
|
-
set(x: number, y: number, width: number, height: number): this;
|
|
69
|
-
/**
|
|
70
|
-
* 复制另一个矩形的值
|
|
71
|
-
* @param other 源矩形
|
|
72
|
-
* @returns 当前矩形实例(链式调用)
|
|
73
|
-
*/
|
|
74
|
-
copy(other: Rectangle): this;
|
|
75
|
-
/**
|
|
76
|
-
* 克隆当前矩形
|
|
77
|
-
* @returns 新的矩形实例
|
|
78
|
-
*/
|
|
79
|
-
clone(): Rectangle;
|
|
80
|
-
/**
|
|
81
|
-
* 设置矩形位置
|
|
82
|
-
* @param x 新的X坐标
|
|
83
|
-
* @param y 新的Y坐标
|
|
84
|
-
* @returns 当前矩形实例(链式调用)
|
|
85
|
-
*/
|
|
86
|
-
setPosition(x: number, y: number): this;
|
|
87
|
-
/**
|
|
88
|
-
* 设置矩形大小
|
|
89
|
-
* @param width 新的宽度
|
|
90
|
-
* @param height 新的高度
|
|
91
|
-
* @returns 当前矩形实例(链式调用)
|
|
92
|
-
*/
|
|
93
|
-
setSize(width: number, height: number): this;
|
|
94
|
-
/**
|
|
95
|
-
* 设置矩形中心点
|
|
96
|
-
* @param centerX 中心X坐标
|
|
97
|
-
* @param centerY 中心Y坐标
|
|
98
|
-
* @returns 当前矩形实例(链式调用)
|
|
99
|
-
*/
|
|
100
|
-
setCenter(centerX: number, centerY: number): this;
|
|
101
|
-
/**
|
|
102
|
-
* 平移矩形
|
|
103
|
-
* @param dx X方向偏移
|
|
104
|
-
* @param dy Y方向偏移
|
|
105
|
-
* @returns 当前矩形实例(链式调用)
|
|
106
|
-
*/
|
|
107
|
-
translate(dx: number, dy: number): this;
|
|
108
|
-
/**
|
|
109
|
-
* 缩放矩形(从中心缩放)
|
|
110
|
-
* @param scaleX X方向缩放因子
|
|
111
|
-
* @param scaleY Y方向缩放因子,默认等于scaleX
|
|
112
|
-
* @returns 当前矩形实例(链式调用)
|
|
113
|
-
*/
|
|
114
|
-
scale(scaleX: number, scaleY?: number): this;
|
|
115
|
-
/**
|
|
116
|
-
* 扩展矩形
|
|
117
|
-
* @param amount 扩展量(正值扩大,负值缩小)
|
|
118
|
-
* @returns 当前矩形实例(链式调用)
|
|
119
|
-
*/
|
|
120
|
-
inflate(amount: number): this;
|
|
121
|
-
/**
|
|
122
|
-
* 扩展矩形(分别指定水平和垂直方向)
|
|
123
|
-
* @param horizontal 水平方向扩展量
|
|
124
|
-
* @param vertical 垂直方向扩展量
|
|
125
|
-
* @returns 当前矩形实例(链式调用)
|
|
126
|
-
*/
|
|
127
|
-
inflateXY(horizontal: number, vertical: number): this;
|
|
128
|
-
/**
|
|
129
|
-
* 检查是否包含指定点
|
|
130
|
-
* @param point 点
|
|
131
|
-
* @returns 是否包含
|
|
132
|
-
*/
|
|
133
|
-
containsPoint(point: Vector2): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* 检查是否包含指定坐标
|
|
136
|
-
* @param x X坐标
|
|
137
|
-
* @param y Y坐标
|
|
138
|
-
* @returns 是否包含
|
|
139
|
-
*/
|
|
140
|
-
contains(x: number, y: number): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* 检查是否完全包含另一个矩形
|
|
143
|
-
* @param other 另一个矩形
|
|
144
|
-
* @returns 是否完全包含
|
|
145
|
-
*/
|
|
146
|
-
containsRect(other: Rectangle): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* 检查是否与另一个矩形相交
|
|
149
|
-
* @param other 另一个矩形
|
|
150
|
-
* @returns 是否相交
|
|
151
|
-
*/
|
|
152
|
-
intersects(other: Rectangle): boolean;
|
|
153
|
-
/**
|
|
154
|
-
* 计算与另一个矩形的相交矩形
|
|
155
|
-
* @param other 另一个矩形
|
|
156
|
-
* @returns 相交矩形,如果不相交返回空矩形
|
|
157
|
-
*/
|
|
158
|
-
intersection(other: Rectangle): Rectangle;
|
|
159
|
-
/**
|
|
160
|
-
* 计算与另一个矩形的并集矩形
|
|
161
|
-
* @param other 另一个矩形
|
|
162
|
-
* @returns 并集矩形
|
|
163
|
-
*/
|
|
164
|
-
union(other: Rectangle): Rectangle;
|
|
165
|
-
/**
|
|
166
|
-
* 计算相交面积
|
|
167
|
-
* @param other 另一个矩形
|
|
168
|
-
* @returns 相交面积
|
|
169
|
-
*/
|
|
170
|
-
intersectionArea(other: Rectangle): number;
|
|
171
|
-
/**
|
|
172
|
-
* 计算点到矩形的最短距离
|
|
173
|
-
* @param point 点
|
|
174
|
-
* @returns 最短距离
|
|
175
|
-
*/
|
|
176
|
-
distanceToPoint(point: Vector2): number;
|
|
177
|
-
/**
|
|
178
|
-
* 计算两个矩形间的最短距离
|
|
179
|
-
* @param other 另一个矩形
|
|
180
|
-
* @returns 最短距离(相交时为0)
|
|
181
|
-
*/
|
|
182
|
-
distanceToRect(other: Rectangle): number;
|
|
183
|
-
/**
|
|
184
|
-
* 获取矩形上距离指定点最近的点
|
|
185
|
-
* @param point 指定点
|
|
186
|
-
* @returns 最近点
|
|
187
|
-
*/
|
|
188
|
-
closestPointTo(point: Vector2): Vector2;
|
|
189
|
-
/**
|
|
190
|
-
* 检查两个矩形是否相等
|
|
191
|
-
* @param other 另一个矩形
|
|
192
|
-
* @param epsilon 容差,默认为Number.EPSILON
|
|
193
|
-
* @returns 是否相等
|
|
194
|
-
*/
|
|
195
|
-
equals(other: Rectangle, epsilon?: number): boolean;
|
|
196
|
-
/**
|
|
197
|
-
* 检查两个矩形是否完全相等
|
|
198
|
-
* @param other 另一个矩形
|
|
199
|
-
* @returns 是否完全相等
|
|
200
|
-
*/
|
|
201
|
-
exactEquals(other: Rectangle): boolean;
|
|
202
|
-
/**
|
|
203
|
-
* 从中心点和大小创建矩形
|
|
204
|
-
* @param centerX 中心X坐标
|
|
205
|
-
* @param centerY 中心Y坐标
|
|
206
|
-
* @param width 宽度
|
|
207
|
-
* @param height 高度
|
|
208
|
-
* @returns 新的矩形实例
|
|
209
|
-
*/
|
|
210
|
-
static fromCenter(centerX: number, centerY: number, width: number, height: number): Rectangle;
|
|
211
|
-
/**
|
|
212
|
-
* 从两个点创建矩形
|
|
213
|
-
* @param point1 第一个点
|
|
214
|
-
* @param point2 第二个点
|
|
215
|
-
* @returns 新的矩形实例
|
|
216
|
-
*/
|
|
217
|
-
static fromPoints(point1: Vector2, point2: Vector2): Rectangle;
|
|
218
|
-
/**
|
|
219
|
-
* 从点数组创建包围矩形
|
|
220
|
-
* @param points 点数组
|
|
221
|
-
* @returns 包围矩形
|
|
222
|
-
*/
|
|
223
|
-
static fromPointArray(points: Vector2[]): Rectangle;
|
|
224
|
-
/**
|
|
225
|
-
* 创建正方形
|
|
226
|
-
* @param x 左上角X坐标
|
|
227
|
-
* @param y 左上角Y坐标
|
|
228
|
-
* @param size 边长
|
|
229
|
-
* @returns 新的正方形矩形
|
|
230
|
-
*/
|
|
231
|
-
static square(x: number, y: number, size: number): Rectangle;
|
|
232
|
-
/**
|
|
233
|
-
* 线性插值两个矩形
|
|
234
|
-
* @param a 起始矩形
|
|
235
|
-
* @param b 目标矩形
|
|
236
|
-
* @param t 插值参数(0到1)
|
|
237
|
-
* @returns 新的插值结果矩形
|
|
238
|
-
*/
|
|
239
|
-
static lerp(a: Rectangle, b: Rectangle, t: number): Rectangle;
|
|
240
|
-
/**
|
|
241
|
-
* 转换为字符串
|
|
242
|
-
* @returns 字符串表示
|
|
243
|
-
*/
|
|
244
|
-
toString(): string;
|
|
245
|
-
/**
|
|
246
|
-
* 转换为数组
|
|
247
|
-
* @returns [x, y, width, height] 数组
|
|
248
|
-
*/
|
|
249
|
-
toArray(): [number, number, number, number];
|
|
250
|
-
/**
|
|
251
|
-
* 转换为普通对象
|
|
252
|
-
* @returns {x, y, width, height} 对象
|
|
253
|
-
*/
|
|
254
|
-
toObject(): {
|
|
255
|
-
x: number;
|
|
256
|
-
y: number;
|
|
257
|
-
width: number;
|
|
258
|
-
height: number;
|
|
259
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* 获取四个顶点
|
|
262
|
-
* @returns 顶点数组 [topLeft, topRight, bottomRight, bottomLeft]
|
|
263
|
-
*/
|
|
264
|
-
getVertices(): Vector2[];
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=Rectangle.d.ts.map
|
package/bin/Rectangle.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Rectangle.d.ts","sourceRoot":"","sources":["../src/Rectangle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;GAQG;AACH,qBAAa,SAAS;IAClB,eAAe;IACR,CAAC,EAAE,MAAM,CAAC;IAEjB,eAAe;IACR,CAAC,EAAE,MAAM,CAAC;IAEjB,WAAW;IACJ,KAAK,EAAE,MAAM,CAAC;IAErB,WAAW;IACJ,MAAM,EAAE,MAAM,CAAC;IAEtB;;;;;;KAMC;gBACW,CAAC,GAAE,MAAU,EAAE,CAAC,GAAE,MAAU,EAAE,KAAK,GAAE,MAAU,EAAE,MAAM,GAAE,MAAU;IAQ/E,UAAU;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AO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS;IAI7F;;;;;KAKC;IACD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS;IAQ9D;;;;KAIC;IACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS;IAoBnD;;;;;;KAMC;IACD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IAI5D;;;;;;KAMC;IACD,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS;IAW7D;;;KAGC;IACD,QAAQ,IAAI,MAAM;IAIlB;;;KAGC;IACD,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAI3C;;;KAGC;IACD,QAAQ,IAAI;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAInE;;;KAGC;IACD,WAAW,IAAI,OAAO,EAAE;CAQ3B"}
|
package/bin/Rectangle.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from './Vector2';
|
|
2
|
-
/**
|
|
3
|
-
* 2D矩形类
|
|
4
|
-
*
|
|
5
|
-
* 表示一个轴对齐的矩形,提供矩形相关的几何运算功能:
|
|
6
|
-
* - 矩形创建和属性获取
|
|
7
|
-
* - 包含检测(点、矩形)
|
|
8
|
-
* - 相交检测和计算
|
|
9
|
-
* - 变换和操作
|
|
10
|
-
*/
|
|
11
|
-
export class Rectangle {
|
|
12
|
-
/**
|
|
13
|
-
* 创建矩形
|
|
14
|
-
* @param x 左上角X坐标,默认为0
|
|
15
|
-
* @param y 左上角Y坐标,默认为0
|
|
16
|
-
* @param width 宽度,默认为0
|
|
17
|
-
* @param height 高度,默认为0
|
|
18
|
-
*/
|
|
19
|
-
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
20
|
-
this.x = x;
|
|
21
|
-
this.y = y;
|
|
22
|
-
this.width = width;
|
|
23
|
-
this.height = height;
|
|
24
|
-
}
|
|
25
|
-
// 属性获取
|
|
26
|
-
/** 获取左边界 */
|
|
27
|
-
get left() {
|
|
28
|
-
return this.x;
|
|
29
|
-
}
|
|
30
|
-
/** 获取右边界 */
|
|
31
|
-
get right() {
|
|
32
|
-
return this.x + this.width;
|
|
33
|
-
}
|
|
34
|
-
/** 获取上边界 */
|
|
35
|
-
get top() {
|
|
36
|
-
return this.y;
|
|
37
|
-
}
|
|
38
|
-
/** 获取下边界 */
|
|
39
|
-
get bottom() {
|
|
40
|
-
return this.y + this.height;
|
|
41
|
-
}
|
|
42
|
-
/** 获取中心X坐标 */
|
|
43
|
-
get centerX() {
|
|
44
|
-
return this.x + this.width * 0.5;
|
|
45
|
-
}
|
|
46
|
-
/** 获取中心Y坐标 */
|
|
47
|
-
get centerY() {
|
|
48
|
-
return this.y + this.height * 0.5;
|
|
49
|
-
}
|
|
50
|
-
/** 获取中心点 */
|
|
51
|
-
get center() {
|
|
52
|
-
return new Vector2(this.centerX, this.centerY);
|
|
53
|
-
}
|
|
54
|
-
/** 获取左上角点 */
|
|
55
|
-
get topLeft() {
|
|
56
|
-
return new Vector2(this.x, this.y);
|
|
57
|
-
}
|
|
58
|
-
/** 获取右上角点 */
|
|
59
|
-
get topRight() {
|
|
60
|
-
return new Vector2(this.right, this.y);
|
|
61
|
-
}
|
|
62
|
-
/** 获取左下角点 */
|
|
63
|
-
get bottomLeft() {
|
|
64
|
-
return new Vector2(this.x, this.bottom);
|
|
65
|
-
}
|
|
66
|
-
/** 获取右下角点 */
|
|
67
|
-
get bottomRight() {
|
|
68
|
-
return new Vector2(this.right, this.bottom);
|
|
69
|
-
}
|
|
70
|
-
/** 获取面积 */
|
|
71
|
-
get area() {
|
|
72
|
-
return this.width * this.height;
|
|
73
|
-
}
|
|
74
|
-
/** 获取周长 */
|
|
75
|
-
get perimeter() {
|
|
76
|
-
return 2 * (this.width + this.height);
|
|
77
|
-
}
|
|
78
|
-
/** 检查是否为空矩形 */
|
|
79
|
-
get isEmpty() {
|
|
80
|
-
return this.width <= 0 || this.height <= 0;
|
|
81
|
-
}
|
|
82
|
-
/** 检查是否为正方形 */
|
|
83
|
-
get isSquare() {
|
|
84
|
-
return this.width === this.height && this.width > 0;
|
|
85
|
-
}
|
|
86
|
-
// 基础操作
|
|
87
|
-
/**
|
|
88
|
-
* 设置矩形属性
|
|
89
|
-
* @param x 左上角X坐标
|
|
90
|
-
* @param y 左上角Y坐标
|
|
91
|
-
* @param width 宽度
|
|
92
|
-
* @param height 高度
|
|
93
|
-
* @returns 当前矩形实例(链式调用)
|
|
94
|
-
*/
|
|
95
|
-
set(x, y, width, height) {
|
|
96
|
-
this.x = x;
|
|
97
|
-
this.y = y;
|
|
98
|
-
this.width = width;
|
|
99
|
-
this.height = height;
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* 复制另一个矩形的值
|
|
104
|
-
* @param other 源矩形
|
|
105
|
-
* @returns 当前矩形实例(链式调用)
|
|
106
|
-
*/
|
|
107
|
-
copy(other) {
|
|
108
|
-
this.x = other.x;
|
|
109
|
-
this.y = other.y;
|
|
110
|
-
this.width = other.width;
|
|
111
|
-
this.height = other.height;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 克隆当前矩形
|
|
116
|
-
* @returns 新的矩形实例
|
|
117
|
-
*/
|
|
118
|
-
clone() {
|
|
119
|
-
return new Rectangle(this.x, this.y, this.width, this.height);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 设置矩形位置
|
|
123
|
-
* @param x 新的X坐标
|
|
124
|
-
* @param y 新的Y坐标
|
|
125
|
-
* @returns 当前矩形实例(链式调用)
|
|
126
|
-
*/
|
|
127
|
-
setPosition(x, y) {
|
|
128
|
-
this.x = x;
|
|
129
|
-
this.y = y;
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 设置矩形大小
|
|
134
|
-
* @param width 新的宽度
|
|
135
|
-
* @param height 新的高度
|
|
136
|
-
* @returns 当前矩形实例(链式调用)
|
|
137
|
-
*/
|
|
138
|
-
setSize(width, height) {
|
|
139
|
-
this.width = width;
|
|
140
|
-
this.height = height;
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* 设置矩形中心点
|
|
145
|
-
* @param centerX 中心X坐标
|
|
146
|
-
* @param centerY 中心Y坐标
|
|
147
|
-
* @returns 当前矩形实例(链式调用)
|
|
148
|
-
*/
|
|
149
|
-
setCenter(centerX, centerY) {
|
|
150
|
-
this.x = centerX - this.width * 0.5;
|
|
151
|
-
this.y = centerY - this.height * 0.5;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
// 变换操作
|
|
155
|
-
/**
|
|
156
|
-
* 平移矩形
|
|
157
|
-
* @param dx X方向偏移
|
|
158
|
-
* @param dy Y方向偏移
|
|
159
|
-
* @returns 当前矩形实例(链式调用)
|
|
160
|
-
*/
|
|
161
|
-
translate(dx, dy) {
|
|
162
|
-
this.x += dx;
|
|
163
|
-
this.y += dy;
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 缩放矩形(从中心缩放)
|
|
168
|
-
* @param scaleX X方向缩放因子
|
|
169
|
-
* @param scaleY Y方向缩放因子,默认等于scaleX
|
|
170
|
-
* @returns 当前矩形实例(链式调用)
|
|
171
|
-
*/
|
|
172
|
-
scale(scaleX, scaleY = scaleX) {
|
|
173
|
-
const centerX = this.centerX;
|
|
174
|
-
const centerY = this.centerY;
|
|
175
|
-
this.width *= scaleX;
|
|
176
|
-
this.height *= scaleY;
|
|
177
|
-
return this.setCenter(centerX, centerY);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 扩展矩形
|
|
181
|
-
* @param amount 扩展量(正值扩大,负值缩小)
|
|
182
|
-
* @returns 当前矩形实例(链式调用)
|
|
183
|
-
*/
|
|
184
|
-
inflate(amount) {
|
|
185
|
-
this.x -= amount;
|
|
186
|
-
this.y -= amount;
|
|
187
|
-
this.width += amount * 2;
|
|
188
|
-
this.height += amount * 2;
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* 扩展矩形(分别指定水平和垂直方向)
|
|
193
|
-
* @param horizontal 水平方向扩展量
|
|
194
|
-
* @param vertical 垂直方向扩展量
|
|
195
|
-
* @returns 当前矩形实例(链式调用)
|
|
196
|
-
*/
|
|
197
|
-
inflateXY(horizontal, vertical) {
|
|
198
|
-
this.x -= horizontal;
|
|
199
|
-
this.y -= vertical;
|
|
200
|
-
this.width += horizontal * 2;
|
|
201
|
-
this.height += vertical * 2;
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
// 包含检测
|
|
205
|
-
/**
|
|
206
|
-
* 检查是否包含指定点
|
|
207
|
-
* @param point 点
|
|
208
|
-
* @returns 是否包含
|
|
209
|
-
*/
|
|
210
|
-
containsPoint(point) {
|
|
211
|
-
return point.x >= this.x && point.x <= this.right &&
|
|
212
|
-
point.y >= this.y && point.y <= this.bottom;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 检查是否包含指定坐标
|
|
216
|
-
* @param x X坐标
|
|
217
|
-
* @param y Y坐标
|
|
218
|
-
* @returns 是否包含
|
|
219
|
-
*/
|
|
220
|
-
contains(x, y) {
|
|
221
|
-
return x >= this.x && x <= this.right &&
|
|
222
|
-
y >= this.y && y <= this.bottom;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* 检查是否完全包含另一个矩形
|
|
226
|
-
* @param other 另一个矩形
|
|
227
|
-
* @returns 是否完全包含
|
|
228
|
-
*/
|
|
229
|
-
containsRect(other) {
|
|
230
|
-
return this.x <= other.x && this.y <= other.y &&
|
|
231
|
-
this.right >= other.right && this.bottom >= other.bottom;
|
|
232
|
-
}
|
|
233
|
-
// 相交检测
|
|
234
|
-
/**
|
|
235
|
-
* 检查是否与另一个矩形相交
|
|
236
|
-
* @param other 另一个矩形
|
|
237
|
-
* @returns 是否相交
|
|
238
|
-
*/
|
|
239
|
-
intersects(other) {
|
|
240
|
-
return this.x < other.right && this.right > other.x &&
|
|
241
|
-
this.y < other.bottom && this.bottom > other.y;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* 计算与另一个矩形的相交矩形
|
|
245
|
-
* @param other 另一个矩形
|
|
246
|
-
* @returns 相交矩形,如果不相交返回空矩形
|
|
247
|
-
*/
|
|
248
|
-
intersection(other) {
|
|
249
|
-
if (!this.intersects(other)) {
|
|
250
|
-
return Rectangle.EMPTY.clone();
|
|
251
|
-
}
|
|
252
|
-
const x = Math.max(this.x, other.x);
|
|
253
|
-
const y = Math.max(this.y, other.y);
|
|
254
|
-
const right = Math.min(this.right, other.right);
|
|
255
|
-
const bottom = Math.min(this.bottom, other.bottom);
|
|
256
|
-
return new Rectangle(x, y, right - x, bottom - y);
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* 计算与另一个矩形的并集矩形
|
|
260
|
-
* @param other 另一个矩形
|
|
261
|
-
* @returns 并集矩形
|
|
262
|
-
*/
|
|
263
|
-
union(other) {
|
|
264
|
-
const x = Math.min(this.x, other.x);
|
|
265
|
-
const y = Math.min(this.y, other.y);
|
|
266
|
-
const right = Math.max(this.right, other.right);
|
|
267
|
-
const bottom = Math.max(this.bottom, other.bottom);
|
|
268
|
-
return new Rectangle(x, y, right - x, bottom - y);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 计算相交面积
|
|
272
|
-
* @param other 另一个矩形
|
|
273
|
-
* @returns 相交面积
|
|
274
|
-
*/
|
|
275
|
-
intersectionArea(other) {
|
|
276
|
-
const intersection = this.intersection(other);
|
|
277
|
-
return intersection.isEmpty ? 0 : intersection.area;
|
|
278
|
-
}
|
|
279
|
-
// 距离计算
|
|
280
|
-
/**
|
|
281
|
-
* 计算点到矩形的最短距离
|
|
282
|
-
* @param point 点
|
|
283
|
-
* @returns 最短距离
|
|
284
|
-
*/
|
|
285
|
-
distanceToPoint(point) {
|
|
286
|
-
const dx = Math.max(0, Math.max(this.x - point.x, point.x - this.right));
|
|
287
|
-
const dy = Math.max(0, Math.max(this.y - point.y, point.y - this.bottom));
|
|
288
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* 计算两个矩形间的最短距离
|
|
292
|
-
* @param other 另一个矩形
|
|
293
|
-
* @returns 最短距离(相交时为0)
|
|
294
|
-
*/
|
|
295
|
-
distanceToRect(other) {
|
|
296
|
-
if (this.intersects(other)) {
|
|
297
|
-
return 0;
|
|
298
|
-
}
|
|
299
|
-
const dx = Math.max(0, Math.max(this.x - other.right, other.x - this.right));
|
|
300
|
-
const dy = Math.max(0, Math.max(this.y - other.bottom, other.y - this.bottom));
|
|
301
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* 获取矩形上距离指定点最近的点
|
|
305
|
-
* @param point 指定点
|
|
306
|
-
* @returns 最近点
|
|
307
|
-
*/
|
|
308
|
-
closestPointTo(point) {
|
|
309
|
-
return new Vector2(Math.max(this.x, Math.min(this.right, point.x)), Math.max(this.y, Math.min(this.bottom, point.y)));
|
|
310
|
-
}
|
|
311
|
-
// 比较操作
|
|
312
|
-
/**
|
|
313
|
-
* 检查两个矩形是否相等
|
|
314
|
-
* @param other 另一个矩形
|
|
315
|
-
* @param epsilon 容差,默认为Number.EPSILON
|
|
316
|
-
* @returns 是否相等
|
|
317
|
-
*/
|
|
318
|
-
equals(other, epsilon = Number.EPSILON) {
|
|
319
|
-
return Math.abs(this.x - other.x) < epsilon &&
|
|
320
|
-
Math.abs(this.y - other.y) < epsilon &&
|
|
321
|
-
Math.abs(this.width - other.width) < epsilon &&
|
|
322
|
-
Math.abs(this.height - other.height) < epsilon;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* 检查两个矩形是否完全相等
|
|
326
|
-
* @param other 另一个矩形
|
|
327
|
-
* @returns 是否完全相等
|
|
328
|
-
*/
|
|
329
|
-
exactEquals(other) {
|
|
330
|
-
return this.x === other.x && this.y === other.y &&
|
|
331
|
-
this.width === other.width && this.height === other.height;
|
|
332
|
-
}
|
|
333
|
-
// 静态方法
|
|
334
|
-
/**
|
|
335
|
-
* 从中心点和大小创建矩形
|
|
336
|
-
* @param centerX 中心X坐标
|
|
337
|
-
* @param centerY 中心Y坐标
|
|
338
|
-
* @param width 宽度
|
|
339
|
-
* @param height 高度
|
|
340
|
-
* @returns 新的矩形实例
|
|
341
|
-
*/
|
|
342
|
-
static fromCenter(centerX, centerY, width, height) {
|
|
343
|
-
return new Rectangle(centerX - width * 0.5, centerY - height * 0.5, width, height);
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* 从两个点创建矩形
|
|
347
|
-
* @param point1 第一个点
|
|
348
|
-
* @param point2 第二个点
|
|
349
|
-
* @returns 新的矩形实例
|
|
350
|
-
*/
|
|
351
|
-
static fromPoints(point1, point2) {
|
|
352
|
-
const x = Math.min(point1.x, point2.x);
|
|
353
|
-
const y = Math.min(point1.y, point2.y);
|
|
354
|
-
const width = Math.abs(point2.x - point1.x);
|
|
355
|
-
const height = Math.abs(point2.y - point1.y);
|
|
356
|
-
return new Rectangle(x, y, width, height);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* 从点数组创建包围矩形
|
|
360
|
-
* @param points 点数组
|
|
361
|
-
* @returns 包围矩形
|
|
362
|
-
*/
|
|
363
|
-
static fromPointArray(points) {
|
|
364
|
-
if (points.length === 0) {
|
|
365
|
-
return Rectangle.EMPTY.clone();
|
|
366
|
-
}
|
|
367
|
-
let minX = points[0].x;
|
|
368
|
-
let minY = points[0].y;
|
|
369
|
-
let maxX = points[0].x;
|
|
370
|
-
let maxY = points[0].y;
|
|
371
|
-
for (let i = 1; i < points.length; i++) {
|
|
372
|
-
minX = Math.min(minX, points[i].x);
|
|
373
|
-
minY = Math.min(minY, points[i].y);
|
|
374
|
-
maxX = Math.max(maxX, points[i].x);
|
|
375
|
-
maxY = Math.max(maxY, points[i].y);
|
|
376
|
-
}
|
|
377
|
-
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* 创建正方形
|
|
381
|
-
* @param x 左上角X坐标
|
|
382
|
-
* @param y 左上角Y坐标
|
|
383
|
-
* @param size 边长
|
|
384
|
-
* @returns 新的正方形矩形
|
|
385
|
-
*/
|
|
386
|
-
static square(x, y, size) {
|
|
387
|
-
return new Rectangle(x, y, size, size);
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* 线性插值两个矩形
|
|
391
|
-
* @param a 起始矩形
|
|
392
|
-
* @param b 目标矩形
|
|
393
|
-
* @param t 插值参数(0到1)
|
|
394
|
-
* @returns 新的插值结果矩形
|
|
395
|
-
*/
|
|
396
|
-
static lerp(a, b, t) {
|
|
397
|
-
return new Rectangle(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.width + (b.width - a.width) * t, a.height + (b.height - a.height) * t);
|
|
398
|
-
}
|
|
399
|
-
// 字符串转换
|
|
400
|
-
/**
|
|
401
|
-
* 转换为字符串
|
|
402
|
-
* @returns 字符串表示
|
|
403
|
-
*/
|
|
404
|
-
toString() {
|
|
405
|
-
return `Rectangle(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.width.toFixed(2)}, ${this.height.toFixed(2)})`;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* 转换为数组
|
|
409
|
-
* @returns [x, y, width, height] 数组
|
|
410
|
-
*/
|
|
411
|
-
toArray() {
|
|
412
|
-
return [this.x, this.y, this.width, this.height];
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* 转换为普通对象
|
|
416
|
-
* @returns {x, y, width, height} 对象
|
|
417
|
-
*/
|
|
418
|
-
toObject() {
|
|
419
|
-
return { x: this.x, y: this.y, width: this.width, height: this.height };
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* 获取四个顶点
|
|
423
|
-
* @returns 顶点数组 [topLeft, topRight, bottomRight, bottomLeft]
|
|
424
|
-
*/
|
|
425
|
-
getVertices() {
|
|
426
|
-
return [
|
|
427
|
-
this.topLeft,
|
|
428
|
-
this.topRight,
|
|
429
|
-
this.bottomRight,
|
|
430
|
-
this.bottomLeft
|
|
431
|
-
];
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
// 静态常量
|
|
435
|
-
/** 空矩形 */
|
|
436
|
-
Rectangle.EMPTY = new Rectangle(0, 0, 0, 0);
|
|
437
|
-
//# sourceMappingURL=Rectangle.js.map
|