@gitborlando/geo 3.0.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @gitborlando/geo
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 7773415: XY,AABB类破坏性更新
8
+
9
+ ## 3.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 2b4693c: 更新xy类
14
+ - 0ee9da2: XY类小幅更新
15
+
3
16
  ## 3.0.0
4
17
 
5
18
  ### Major Changes
@@ -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.expand(aabb, 2)
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.expand(aabb, 1, 2, 3, 4)
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 expand(aabb: AABB, ...expands: [number] | [number, number, number, number]): AABB;
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,15 +212,24 @@ 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(another: IXY, origin: IXY): XY;
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;
229
+ static _(x?: number, y?: number): {
230
+ x: number;
231
+ y: number;
232
+ };
224
233
  static of(x: number, y: number): XY;
225
234
  static from(xy: IXY): XY;
226
235
  static center(xy: {
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(another, origin) {
175
- return _XY.of(2 * origin.x - another.x, 2 * origin.y - another.y);
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,10 +193,14 @@ 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
  }
196
+ static _(x = 0, y = 0) {
197
+ return { x, y };
198
+ }
188
199
  static of(x, y) {
189
200
  return new _XY(x, y);
190
201
  }
191
202
  static from(xy) {
203
+ if (xy instanceof _XY) return xy;
192
204
  return _XY.of(xy.x, xy.y);
193
205
  }
194
206
  static center(xy) {
@@ -237,7 +249,7 @@ var AABB = class _AABB {
237
249
  const included = large.minX <= small.minX && large.maxX >= small.maxX && large.minY <= small.minY && large.maxY >= small.maxY;
238
250
  return included ? result : -1;
239
251
  }
240
- static expand(aabb, ...expands) {
252
+ static extend(aabb, ...expands) {
241
253
  const { minX, minY, maxX, maxY } = aabb;
242
254
  if (expands.length === 1) {
243
255
  const expand = expands[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitborlando/geo",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
package/src/aabb.ts CHANGED
@@ -47,7 +47,7 @@ export class AABB {
47
47
  return included ? result : -1
48
48
  }
49
49
 
50
- static expand(
50
+ static extend(
51
51
  aabb: AABB,
52
52
  ...expands: [number] | [number, number, number, number]
53
53
  ): AABB {
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(another: IXY, origin: IXY) {
133
- return XY.of(2 * origin.x - another.x, 2 * origin.y - another.y)
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,11 +158,16 @@ export class XY {
148
158
  )
149
159
  }
150
160
 
161
+ static _(x: number = 0, y: number = 0) {
162
+ return { x, y }
163
+ }
164
+
151
165
  static of(x: number, y: number) {
152
166
  return new XY(x, y)
153
167
  }
154
168
 
155
169
  static from(xy: IXY) {
170
+ if (xy instanceof XY) return xy
156
171
  return XY.of(xy.x, xy.y)
157
172
  }
158
173