@gitborlando/geo 3.1.0 → 4.0.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/CHANGELOG.md +6 -0
- package/__test__/aabb.test.ts +2 -2
- package/dist/index.d.ts +7 -6
- package/dist/index.js +11 -6
- package/package.json +1 -1
- package/src/aabb.ts +1 -1
- package/src/xy.ts +12 -6
package/CHANGELOG.md
CHANGED
package/__test__/aabb.test.ts
CHANGED
|
@@ -45,7 +45,7 @@ describe('AABB', () => {
|
|
|
45
45
|
|
|
46
46
|
it('should expand correctly with single value', () => {
|
|
47
47
|
const aabb = new AABB(5, 5, 15, 15)
|
|
48
|
-
const expanded = AABB.
|
|
48
|
+
const expanded = AABB.extend(aabb, 2)
|
|
49
49
|
expect(expanded.minX).toBe(3)
|
|
50
50
|
expect(expanded.minY).toBe(3)
|
|
51
51
|
expect(expanded.maxX).toBe(17)
|
|
@@ -54,7 +54,7 @@ describe('AABB', () => {
|
|
|
54
54
|
|
|
55
55
|
it('should expand correctly with four values', () => {
|
|
56
56
|
const aabb = new AABB(5, 5, 15, 15)
|
|
57
|
-
const expanded = AABB.
|
|
57
|
+
const expanded = AABB.extend(aabb, 1, 2, 3, 4)
|
|
58
58
|
expect(expanded.minX).toBe(4)
|
|
59
59
|
expect(expanded.minY).toBe(3)
|
|
60
60
|
expect(expanded.maxX).toBe(18)
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ declare class AABB {
|
|
|
64
64
|
static rect(aabb: AABB): IRectWithCenter;
|
|
65
65
|
static collide(one: AABB, another: AABB): boolean;
|
|
66
66
|
static include(one: AABB, another: AABB): number;
|
|
67
|
-
static
|
|
67
|
+
static extend(aabb: AABB, ...expands: [number] | [number, number, number, number]): AABB;
|
|
68
68
|
static merge(...aabbList: AABB[]): AABB;
|
|
69
69
|
static fromOBB(obb: OBB): AABB;
|
|
70
70
|
}
|
|
@@ -212,19 +212,20 @@ declare class XY {
|
|
|
212
212
|
x: number;
|
|
213
213
|
y: number;
|
|
214
214
|
constructor(x: number, y: number);
|
|
215
|
+
plain(): {
|
|
216
|
+
x: number;
|
|
217
|
+
y: number;
|
|
218
|
+
};
|
|
215
219
|
plus(...others: IXY[]): XY;
|
|
216
220
|
minus(...others: IXY[]): XY;
|
|
217
221
|
multiply(...numbers: number[]): XY;
|
|
218
222
|
divide(...numbers: number[]): XY;
|
|
219
223
|
rotate(origin: IXY, rotation: number): XY;
|
|
220
|
-
symmetric(
|
|
224
|
+
symmetric(origin: IXY): XY;
|
|
225
|
+
ratio(another: IXY, t: number): XY;
|
|
221
226
|
getDot(another: IXY): number;
|
|
222
227
|
getDistance(another: IXY): number;
|
|
223
228
|
getAngle(another: IXY, origin: IXY): number;
|
|
224
|
-
primitive(): {
|
|
225
|
-
x: number;
|
|
226
|
-
y: number;
|
|
227
|
-
};
|
|
228
229
|
static _(x?: number, y?: number): {
|
|
229
230
|
x: number;
|
|
230
231
|
y: number;
|
package/dist/index.js
CHANGED
|
@@ -149,6 +149,9 @@ var XY = class _XY {
|
|
|
149
149
|
this.x = x;
|
|
150
150
|
this.y = y;
|
|
151
151
|
}
|
|
152
|
+
plain() {
|
|
153
|
+
return { x: this.x, y: this.y };
|
|
154
|
+
}
|
|
152
155
|
plus(...others) {
|
|
153
156
|
const x = others.reduce((sum, cur) => sum + cur.x, this.x);
|
|
154
157
|
const y = others.reduce((sum, cur) => sum + cur.y, this.y);
|
|
@@ -171,8 +174,13 @@ var XY = class _XY {
|
|
|
171
174
|
if (rotation === 0) return _XY.from(this);
|
|
172
175
|
return _XY.from(Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation));
|
|
173
176
|
}
|
|
174
|
-
symmetric(
|
|
175
|
-
return _XY.of(2 * origin.x -
|
|
177
|
+
symmetric(origin) {
|
|
178
|
+
return _XY.of(2 * origin.x - this.x, 2 * origin.y - this.y);
|
|
179
|
+
}
|
|
180
|
+
ratio(another, t) {
|
|
181
|
+
const x = this.x + (another.x - this.x) * t;
|
|
182
|
+
const y = this.y + (another.y - this.y) * t;
|
|
183
|
+
return _XY.of(x, y);
|
|
176
184
|
}
|
|
177
185
|
getDot(another) {
|
|
178
186
|
return this.x * another.x + this.y * another.y;
|
|
@@ -185,9 +193,6 @@ var XY = class _XY {
|
|
|
185
193
|
Math.atan2(this.y - origin.y, this.x - origin.x) - Math.atan2(another.y - origin.y, another.x - origin.x)
|
|
186
194
|
);
|
|
187
195
|
}
|
|
188
|
-
primitive() {
|
|
189
|
-
return { x: this.x, y: this.y };
|
|
190
|
-
}
|
|
191
196
|
static _(x = 0, y = 0) {
|
|
192
197
|
return { x, y };
|
|
193
198
|
}
|
|
@@ -244,7 +249,7 @@ var AABB = class _AABB {
|
|
|
244
249
|
const included = large.minX <= small.minX && large.maxX >= small.maxX && large.minY <= small.minY && large.maxY >= small.maxY;
|
|
245
250
|
return included ? result : -1;
|
|
246
251
|
}
|
|
247
|
-
static
|
|
252
|
+
static extend(aabb, ...expands) {
|
|
248
253
|
const { minX, minY, maxX, maxY } = aabb;
|
|
249
254
|
if (expands.length === 1) {
|
|
250
255
|
const expand = expands[0];
|
package/package.json
CHANGED
package/src/aabb.ts
CHANGED
package/src/xy.ts
CHANGED
|
@@ -102,6 +102,10 @@ export class XY {
|
|
|
102
102
|
public x: number,
|
|
103
103
|
public y: number,
|
|
104
104
|
) {}
|
|
105
|
+
plain() {
|
|
106
|
+
return { x: this.x, y: this.y }
|
|
107
|
+
}
|
|
108
|
+
|
|
105
109
|
plus(...others: IXY[]) {
|
|
106
110
|
const x = others.reduce((sum, cur) => sum + cur.x, this.x)
|
|
107
111
|
const y = others.reduce((sum, cur) => sum + cur.y, this.y)
|
|
@@ -129,8 +133,14 @@ export class XY {
|
|
|
129
133
|
return XY.from(Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation))
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
symmetric(
|
|
133
|
-
return XY.of(2 * origin.x -
|
|
136
|
+
symmetric(origin: IXY) {
|
|
137
|
+
return XY.of(2 * origin.x - this.x, 2 * origin.y - this.y)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ratio(another: IXY, t: number) {
|
|
141
|
+
const x = this.x + (another.x - this.x) * t
|
|
142
|
+
const y = this.y + (another.y - this.y) * t
|
|
143
|
+
return XY.of(x, y)
|
|
134
144
|
}
|
|
135
145
|
|
|
136
146
|
getDot(another: IXY) {
|
|
@@ -148,10 +158,6 @@ export class XY {
|
|
|
148
158
|
)
|
|
149
159
|
}
|
|
150
160
|
|
|
151
|
-
primitive() {
|
|
152
|
-
return { x: this.x, y: this.y }
|
|
153
|
-
}
|
|
154
|
-
|
|
155
161
|
static _(x: number = 0, y: number = 0) {
|
|
156
162
|
return { x, y }
|
|
157
163
|
}
|