@gitborlando/geo 4.0.0 → 4.1.1

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.d.ts CHANGED
@@ -62,6 +62,7 @@ declare class AABB {
62
62
  maxY: number;
63
63
  constructor(minX: number, minY: number, maxX: number, maxY: number);
64
64
  static rect(aabb: AABB): IRectWithCenter;
65
+ static rectTuple(aabb: AABB): readonly [number, number, number, number];
65
66
  static collide(one: AABB, another: AABB): boolean;
66
67
  static include(one: AABB, another: AABB): number;
67
68
  static extend(aabb: AABB, ...expands: [number] | [number, number, number, number]): AABB;
@@ -216,6 +217,7 @@ declare class XY {
216
217
  x: number;
217
218
  y: number;
218
219
  };
220
+ tuple(): readonly [number, number];
219
221
  plus(...others: IXY[]): XY;
220
222
  minus(...others: IXY[]): XY;
221
223
  multiply(...numbers: number[]): XY;
@@ -245,6 +247,8 @@ declare class XY {
245
247
  clientY: number;
246
248
  }): XY;
247
249
  static tuple(arr: [number, number]): XY;
250
+ static xAxis(rotation: number): XY;
251
+ static yAxis(rotation: number): XY;
248
252
  }
249
253
 
250
254
  export { AABB, Angle, type IMatrix, type IRect, type IRectWithCenter, type IXY, Matrix, OBB, PI, type Point, XY, abs, acos, asin, atan, atan2, ceil, cos, divide, floor, max, min, multiply, numberHalfFix, pointsOnBezierCurves, pow2, pow3, random, round, simplify, simplifyPoints, sin, sqrt, tan, twoDecimal, xy_, xy_center, xy_client, xy_distance, xy_divide, xy_dot, xy_from, xy_getRotation, xy_minus, xy_minus_mutate, xy_multiply, xy_multiply_mutate, xy_mutate, xy_opposite, xy_plus, xy_plus_all, xy_plus_mutate, xy_rotate, xy_symmetric, xy_toArray, xy_xAxis, xy_yAxis };
package/dist/index.js CHANGED
@@ -152,6 +152,9 @@ var XY = class _XY {
152
152
  plain() {
153
153
  return { x: this.x, y: this.y };
154
154
  }
155
+ tuple() {
156
+ return [this.x, this.y];
157
+ }
155
158
  plus(...others) {
156
159
  const x = others.reduce((sum, cur) => sum + cur.x, this.x);
157
160
  const y = others.reduce((sum, cur) => sum + cur.y, this.y);
@@ -215,6 +218,12 @@ var XY = class _XY {
215
218
  static tuple(arr) {
216
219
  return _XY.of(arr[0], arr[1]);
217
220
  }
221
+ static xAxis(rotation) {
222
+ return _XY.of(Angle.cos(rotation), Angle.sin(rotation));
223
+ }
224
+ static yAxis(rotation) {
225
+ return _XY.of(-Angle.sin(rotation), Angle.cos(rotation));
226
+ }
218
227
  };
219
228
 
220
229
  // src/aabb.ts
@@ -235,6 +244,14 @@ var AABB = class _AABB {
235
244
  centerY: aabb.minY + (aabb.maxY - aabb.minY) / 2
236
245
  };
237
246
  }
247
+ static rectTuple(aabb) {
248
+ return [
249
+ aabb.minX,
250
+ aabb.minY,
251
+ aabb.maxX - aabb.minX,
252
+ aabb.maxY - aabb.minY
253
+ ];
254
+ }
238
255
  static collide(one, another) {
239
256
  return one.minX <= another.maxX && one.maxX >= another.minX && one.minY <= another.maxY && one.maxY >= another.minY;
240
257
  }
@@ -274,8 +291,8 @@ var AABB = class _AABB {
274
291
  return new _AABB(xMin, yMin, xMax, yMax);
275
292
  }
276
293
  static fromOBB(obb) {
277
- const width = obb.projectionLengthAt(xy_(1, 0));
278
- const height = obb.projectionLengthAt(xy_(0, 1));
294
+ const width = obb.projectionLengthAt(XY._(1, 0));
295
+ const height = obb.projectionLengthAt(XY._(0, 1));
279
296
  return new _AABB(
280
297
  obb.center.x - width / 2,
281
298
  obb.center.y - height / 2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitborlando/geo",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,6 +9,10 @@
9
9
  "types": "./dist/index.d.ts"
10
10
  }
11
11
  },
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
12
16
  "publishConfig": {
13
17
  "access": "public",
14
18
  "registry": "https://registry.npmjs.org"
@@ -18,12 +22,28 @@
18
22
  "license": "ISC",
19
23
  "devDependencies": {
20
24
  "@vitest/ui": "^3.2.4",
21
- "vitest": "^3.2.4"
25
+ "vitest": "^3.2.4",
26
+ "@changesets/cli": "^2.29.5",
27
+ "@types/node": "^24.0.15",
28
+ "husky": "^9.1.7",
29
+ "pretty-quick": "^4.2.2",
30
+ "tsup": "^8.5.0",
31
+ "tsx": "^4.20.3",
32
+ "typescript": "^5.8.3"
33
+ },
34
+ "prettier": {
35
+ "printWidth": 85,
36
+ "jsxBracketSameLine": true,
37
+ "useTabs": false,
38
+ "tabWidth": 2,
39
+ "semi": false,
40
+ "singleQuote": true,
41
+ "jsxSingleQuote": true
22
42
  },
23
43
  "scripts": {
24
44
  "dev": "tsup --watch",
25
45
  "build": "tsup",
26
- "clean": "rm -rf node_modules",
46
+ "clean": "rm -rf node_modules pnpm-lock.yaml",
27
47
  "test": "vitest",
28
48
  "test:run": "vitest run",
29
49
  "test:ui": "vitest --ui"
@@ -1,8 +1,8 @@
1
1
  // 测试轴对齐包围盒功能
2
2
 
3
3
  import { describe, expect, it } from 'vitest'
4
- import { AABB } from '../src/aabb'
5
- import { OBB } from '../src/obb'
4
+ import { AABB } from '../aabb'
5
+ import { OBB } from '../obb'
6
6
 
7
7
  describe('AABB', () => {
8
8
  it('should create AABB correctly', () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { Angle, PI } from '../src/angle'
2
+ import { Angle, PI } from '../angle'
3
3
 
4
4
  describe('Angle', () => {
5
5
  it('should export PI constant correctly', () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import * as Geo from '../src/index'
2
+ import * as Geo from '../index'
3
3
 
4
4
  describe('Index exports', () => {
5
5
  it('should export all modules correctly', () => {
@@ -13,7 +13,7 @@ import {
13
13
  random,
14
14
  round,
15
15
  sqrt,
16
- } from '../src/math'
16
+ } from '../math'
17
17
 
18
18
  describe('Math utilities', () => {
19
19
  it('should export Math functions correctly', () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { AABB } from '../src/aabb'
3
- import { IMatrix, Matrix } from '../src/matrix'
2
+ import { AABB } from '../aabb'
3
+ import { IMatrix, Matrix } from '../matrix'
4
4
 
5
5
  describe('Matrix', () => {
6
6
  it('should create identity matrix correctly', () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { AABB } from '../src/aabb'
3
- import { OBB } from '../src/obb'
2
+ import { AABB } from '../aabb'
3
+ import { OBB } from '../obb'
4
4
 
5
5
  describe('OBB', () => {
6
6
  it('should create OBB correctly', () => {
@@ -4,7 +4,7 @@ import {
4
4
  pointsOnBezierCurves,
5
5
  simplify,
6
6
  simplifyPoints,
7
- } from '../src/points-of-bezier'
7
+ } from '../points-of-bezier'
8
8
 
9
9
  describe('Points of Bezier', () => {
10
10
  const createBezierPoints = (): Point[] => [
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { IRect, IRectWithCenter, IXY } from '../src/types'
2
+ import { IRect, IRectWithCenter, IXY } from '../types'
3
3
 
4
4
  describe('Types', () => {
5
5
  it('should define IXY interface correctly', () => {
@@ -14,7 +14,7 @@ import {
14
14
  xy_opposite,
15
15
  xy_plus,
16
16
  xy_toArray,
17
- } from '../src/xy'
17
+ } from '../xy'
18
18
 
19
19
  describe('XY utilities', () => {
20
20
  it('should create xy point correctly', () => {
package/src/aabb.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { max, min } from './math'
2
2
  import { OBB } from './obb'
3
3
  import { IRectWithCenter } from './types'
4
- import { xy_ } from './xy'
4
+ import { XY } from './xy'
5
5
 
6
6
  export class AABB {
7
7
  constructor(
@@ -22,6 +22,15 @@ export class AABB {
22
22
  }
23
23
  }
24
24
 
25
+ static rectTuple(aabb: AABB) {
26
+ return [
27
+ aabb.minX,
28
+ aabb.minY,
29
+ aabb.maxX - aabb.minX,
30
+ aabb.maxY - aabb.minY,
31
+ ] as const
32
+ }
33
+
25
34
  static collide(one: AABB, another: AABB): boolean {
26
35
  return (
27
36
  one.minX <= another.maxX &&
@@ -77,8 +86,8 @@ export class AABB {
77
86
  }
78
87
 
79
88
  static fromOBB(obb: OBB) {
80
- const width = obb.projectionLengthAt(xy_(1, 0))
81
- const height = obb.projectionLengthAt(xy_(0, 1))
89
+ const width = obb.projectionLengthAt(XY._(1, 0))
90
+ const height = obb.projectionLengthAt(XY._(0, 1))
82
91
  return new AABB(
83
92
  obb.center.x - width / 2,
84
93
  obb.center.y - height / 2,
package/src/xy.ts CHANGED
@@ -106,6 +106,10 @@ export class XY {
106
106
  return { x: this.x, y: this.y }
107
107
  }
108
108
 
109
+ tuple() {
110
+ return [this.x, this.y] as const
111
+ }
112
+
109
113
  plus(...others: IXY[]) {
110
114
  const x = others.reduce((sum, cur) => sum + cur.x, this.x)
111
115
  const y = others.reduce((sum, cur) => sum + cur.y, this.y)
@@ -186,4 +190,12 @@ export class XY {
186
190
  static tuple(arr: [number, number]) {
187
191
  return XY.of(arr[0], arr[1])
188
192
  }
193
+
194
+ static xAxis(rotation: number) {
195
+ return XY.of(Angle.cos(rotation), Angle.sin(rotation))
196
+ }
197
+
198
+ static yAxis(rotation: number) {
199
+ return XY.of(-Angle.sin(rotation), Angle.cos(rotation))
200
+ }
189
201
  }
package/CHANGELOG.md DELETED
@@ -1,38 +0,0 @@
1
- # @gitborlando/geo
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
-
16
- ## 3.0.0
17
-
18
- ### Major Changes
19
-
20
- - f121a3e: XY类破坏性更新
21
-
22
- ## 2.1.0
23
-
24
- ### Minor Changes
25
-
26
- - 7bd75bc: 新增一些方法
27
-
28
- ## 2.0.0
29
-
30
- ### Major Changes
31
-
32
- - b2c20d9: 修正了多个类的方法名称,统一为小写格式,更新了相关测试用例以匹配新的方法名。同时,更新了 package.json 中的导出路径,从 src 目录改为 dist 目录。
33
-
34
- ## 1.0.1
35
-
36
- ### Patch Changes
37
-
38
- - dd370ef: initial
package/tsup.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- outDir: 'dist',
6
- format: ['esm'],
7
- dts: true,
8
- splitting: true,
9
- clean: true,
10
- })
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- globals: true,
7
- },
8
- })