@fimbul-works/vec 1.0.0 → 1.0.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/README.md +0 -4
- package/dist/vec2.js +15 -15
- package/dist/vec3.d.ts +6 -10
- package/dist/vec3.js +18 -30
- package/dist/vec4.d.ts +7 -12
- package/dist/vec4.js +19 -34
- package/package.json +70 -73
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@ A high-performance TypeScript vector math library providing 2D, 3D, and 4D vecto
|
|
|
11
11
|
- 🛡️ **Type Safety**: Full TypeScript support with strict typing and readonly options
|
|
12
12
|
- 📏 **Multiple Distance Metrics**: Euclidean, Manhattan, Chebyshev, and Minkowski
|
|
13
13
|
- 🔒 **Immutability Support**: Both mutable and immutable operation modes
|
|
14
|
-
- 🎨 **Color Operations**: Built-in RGBA and RGB color handling
|
|
15
14
|
- 🎮 **Graphics Ready**: Homogeneous coordinates and transformation support
|
|
16
15
|
- 🧮 **Math Features**: Comprehensive geometric and arithmetic operations
|
|
17
16
|
- ⚡ **Memory Efficient**: Zero-allocation options for performance-critical code
|
|
@@ -37,9 +36,6 @@ position.add(movement);
|
|
|
37
36
|
// 3D graphics with homogeneous coordinates
|
|
38
37
|
const point = new Vec4(x, y, z, 1); // Point in 3D space
|
|
39
38
|
const vector = new Vec4(dx, dy, dz, 0); // Direction in 3D space
|
|
40
|
-
|
|
41
|
-
// Color manipulation
|
|
42
|
-
const color = new Vec4(1, 0, 0, 0.5); // Semi-transparent red
|
|
43
39
|
```
|
|
44
40
|
|
|
45
41
|
## Zero-Allocation Usage
|
package/dist/vec2.js
CHANGED
|
@@ -187,6 +187,21 @@ export class Vec2 {
|
|
|
187
187
|
const isZero = x === 0 && y === 0;
|
|
188
188
|
const xy = Object.freeze([...data.slice(0, 2)]);
|
|
189
189
|
return {
|
|
190
|
+
get x() {
|
|
191
|
+
return data[0];
|
|
192
|
+
},
|
|
193
|
+
get y() {
|
|
194
|
+
return data[1];
|
|
195
|
+
},
|
|
196
|
+
get xy() {
|
|
197
|
+
return xy;
|
|
198
|
+
},
|
|
199
|
+
get magnitude() {
|
|
200
|
+
return data[8];
|
|
201
|
+
},
|
|
202
|
+
get magnitudeSq() {
|
|
203
|
+
return data[10];
|
|
204
|
+
},
|
|
190
205
|
get angleX() {
|
|
191
206
|
return data[4];
|
|
192
207
|
},
|
|
@@ -202,21 +217,6 @@ export class Vec2 {
|
|
|
202
217
|
get isZero() {
|
|
203
218
|
return isZero;
|
|
204
219
|
},
|
|
205
|
-
get magnitude() {
|
|
206
|
-
return data[8];
|
|
207
|
-
},
|
|
208
|
-
get magnitudeSq() {
|
|
209
|
-
return data[10];
|
|
210
|
-
},
|
|
211
|
-
get x() {
|
|
212
|
-
return data[0];
|
|
213
|
-
},
|
|
214
|
-
get xy() {
|
|
215
|
-
return xy;
|
|
216
|
-
},
|
|
217
|
-
get y() {
|
|
218
|
-
return data[1];
|
|
219
|
-
},
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
222
|
/**
|
package/dist/vec3.d.ts
CHANGED
|
@@ -126,22 +126,18 @@ export declare class Vec3 {
|
|
|
126
126
|
* @returns An immutable object with Vec3-like properties.
|
|
127
127
|
*/
|
|
128
128
|
static immutable(x?: number, y?: number, z?: number): {
|
|
129
|
+
readonly x: number;
|
|
130
|
+
readonly y: number;
|
|
131
|
+
readonly z: number;
|
|
132
|
+
readonly xyz: readonly number[];
|
|
133
|
+
readonly magnitude: number;
|
|
134
|
+
readonly magnitudeSq: number;
|
|
129
135
|
readonly angleX: number;
|
|
130
136
|
readonly angleY: number;
|
|
131
137
|
readonly angleZ: number;
|
|
132
138
|
readonly isInfinite: boolean;
|
|
133
139
|
readonly isNaN: boolean;
|
|
134
140
|
readonly isZero: boolean;
|
|
135
|
-
readonly magnitude: number;
|
|
136
|
-
readonly magnitudeSq: number;
|
|
137
|
-
readonly r: number;
|
|
138
|
-
readonly g: number;
|
|
139
|
-
readonly b: number;
|
|
140
|
-
readonly rgb: readonly number[];
|
|
141
|
-
readonly x: number;
|
|
142
|
-
readonly xyz: readonly number[];
|
|
143
|
-
readonly y: number;
|
|
144
|
-
readonly z: number;
|
|
145
141
|
};
|
|
146
142
|
/**
|
|
147
143
|
* Checks if a vector has infinite components.
|
package/dist/vec3.js
CHANGED
|
@@ -211,6 +211,24 @@ export class Vec3 {
|
|
|
211
211
|
const isZero = x === 0 && y === 0 && z === 0;
|
|
212
212
|
const xyz = Object.freeze([...data.slice(0, 3)]);
|
|
213
213
|
return {
|
|
214
|
+
get x() {
|
|
215
|
+
return data[0];
|
|
216
|
+
},
|
|
217
|
+
get y() {
|
|
218
|
+
return data[1];
|
|
219
|
+
},
|
|
220
|
+
get z() {
|
|
221
|
+
return data[2];
|
|
222
|
+
},
|
|
223
|
+
get xyz() {
|
|
224
|
+
return xyz;
|
|
225
|
+
},
|
|
226
|
+
get magnitude() {
|
|
227
|
+
return data[8];
|
|
228
|
+
},
|
|
229
|
+
get magnitudeSq() {
|
|
230
|
+
return data[10];
|
|
231
|
+
},
|
|
214
232
|
get angleX() {
|
|
215
233
|
return data[4];
|
|
216
234
|
},
|
|
@@ -229,36 +247,6 @@ export class Vec3 {
|
|
|
229
247
|
get isZero() {
|
|
230
248
|
return isZero;
|
|
231
249
|
},
|
|
232
|
-
get magnitude() {
|
|
233
|
-
return data[8];
|
|
234
|
-
},
|
|
235
|
-
get magnitudeSq() {
|
|
236
|
-
return data[10];
|
|
237
|
-
},
|
|
238
|
-
get r() {
|
|
239
|
-
return data[0];
|
|
240
|
-
},
|
|
241
|
-
get g() {
|
|
242
|
-
return data[1];
|
|
243
|
-
},
|
|
244
|
-
get b() {
|
|
245
|
-
return data[2];
|
|
246
|
-
},
|
|
247
|
-
get rgb() {
|
|
248
|
-
return xyz;
|
|
249
|
-
},
|
|
250
|
-
get x() {
|
|
251
|
-
return data[0];
|
|
252
|
-
},
|
|
253
|
-
get xyz() {
|
|
254
|
-
return xyz;
|
|
255
|
-
},
|
|
256
|
-
get y() {
|
|
257
|
-
return data[1];
|
|
258
|
-
},
|
|
259
|
-
get z() {
|
|
260
|
-
return data[2];
|
|
261
|
-
},
|
|
262
250
|
};
|
|
263
251
|
}
|
|
264
252
|
/**
|
package/dist/vec4.d.ts
CHANGED
|
@@ -104,7 +104,13 @@ export declare class Vec4 {
|
|
|
104
104
|
* @returns An immutable object with Vec4-like properties.
|
|
105
105
|
*/
|
|
106
106
|
static immutable(x?: number, y?: number, z?: number, w?: number): {
|
|
107
|
-
readonly
|
|
107
|
+
readonly x: number;
|
|
108
|
+
readonly y: number;
|
|
109
|
+
readonly z: number;
|
|
110
|
+
readonly w: number;
|
|
111
|
+
readonly xyzw: readonly number[];
|
|
112
|
+
readonly magnitude: number;
|
|
113
|
+
readonly magnitudeSq: number;
|
|
108
114
|
readonly angleW: number;
|
|
109
115
|
readonly angleX: number;
|
|
110
116
|
readonly angleY: number;
|
|
@@ -112,17 +118,6 @@ export declare class Vec4 {
|
|
|
112
118
|
readonly isInfinite: boolean;
|
|
113
119
|
readonly isNaN: boolean;
|
|
114
120
|
readonly isZero: boolean;
|
|
115
|
-
readonly magnitude: number;
|
|
116
|
-
readonly magnitudeSq: number;
|
|
117
|
-
readonly r: number;
|
|
118
|
-
readonly g: number;
|
|
119
|
-
readonly b: number;
|
|
120
|
-
readonly rgba: readonly number[];
|
|
121
|
-
readonly w: number;
|
|
122
|
-
readonly x: number;
|
|
123
|
-
readonly xyzw: readonly number[];
|
|
124
|
-
readonly y: number;
|
|
125
|
-
readonly z: number;
|
|
126
121
|
};
|
|
127
122
|
/**
|
|
128
123
|
* Checks if a vector has infinite components.
|
package/dist/vec4.js
CHANGED
|
@@ -208,9 +208,27 @@ export class Vec4 {
|
|
|
208
208
|
const isZero = x === 0 && y === 0 && z === 0 && w === 0;
|
|
209
209
|
const xyzw = Object.freeze([...data.slice(0, 4)]);
|
|
210
210
|
return {
|
|
211
|
-
get
|
|
211
|
+
get x() {
|
|
212
|
+
return data[0];
|
|
213
|
+
},
|
|
214
|
+
get y() {
|
|
215
|
+
return data[1];
|
|
216
|
+
},
|
|
217
|
+
get z() {
|
|
218
|
+
return data[2];
|
|
219
|
+
},
|
|
220
|
+
get w() {
|
|
212
221
|
return data[3];
|
|
213
222
|
},
|
|
223
|
+
get xyzw() {
|
|
224
|
+
return xyzw;
|
|
225
|
+
},
|
|
226
|
+
get magnitude() {
|
|
227
|
+
return data[8];
|
|
228
|
+
},
|
|
229
|
+
get magnitudeSq() {
|
|
230
|
+
return data[10];
|
|
231
|
+
},
|
|
214
232
|
get angleW() {
|
|
215
233
|
return data[7];
|
|
216
234
|
},
|
|
@@ -232,39 +250,6 @@ export class Vec4 {
|
|
|
232
250
|
get isZero() {
|
|
233
251
|
return isZero;
|
|
234
252
|
},
|
|
235
|
-
get magnitude() {
|
|
236
|
-
return data[8];
|
|
237
|
-
},
|
|
238
|
-
get magnitudeSq() {
|
|
239
|
-
return data[10];
|
|
240
|
-
},
|
|
241
|
-
get r() {
|
|
242
|
-
return data[0];
|
|
243
|
-
},
|
|
244
|
-
get g() {
|
|
245
|
-
return data[1];
|
|
246
|
-
},
|
|
247
|
-
get b() {
|
|
248
|
-
return data[2];
|
|
249
|
-
},
|
|
250
|
-
get rgba() {
|
|
251
|
-
return xyzw;
|
|
252
|
-
},
|
|
253
|
-
get w() {
|
|
254
|
-
return data[3];
|
|
255
|
-
},
|
|
256
|
-
get x() {
|
|
257
|
-
return data[0];
|
|
258
|
-
},
|
|
259
|
-
get xyzw() {
|
|
260
|
-
return xyzw;
|
|
261
|
-
},
|
|
262
|
-
get y() {
|
|
263
|
-
return data[1];
|
|
264
|
-
},
|
|
265
|
-
get z() {
|
|
266
|
-
return data[2];
|
|
267
|
-
},
|
|
268
253
|
};
|
|
269
254
|
}
|
|
270
255
|
/**
|
package/package.json
CHANGED
|
@@ -1,73 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fimbul-works/vec",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A high-performance vector math library for TypeScript",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"private": false,
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"author": "FimbulWorks <contact@fimbul.works>",
|
|
9
|
-
"homepage": "https://github.com/fimbul-works/vec#readme",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/fimbul-works/vec.git"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/fimbul-works/vec/issues"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"2d",
|
|
19
|
-
"3d",
|
|
20
|
-
"4d",
|
|
21
|
-
"computer-graphics",
|
|
22
|
-
"game-development",
|
|
23
|
-
"geometry",
|
|
24
|
-
"graphics",
|
|
25
|
-
"linear-algebra",
|
|
26
|
-
"math",
|
|
27
|
-
"physics",
|
|
28
|
-
"vector-math",
|
|
29
|
-
"vector"
|
|
30
|
-
],
|
|
31
|
-
"main": "./dist/index.js",
|
|
32
|
-
"module": "./dist/index.js",
|
|
33
|
-
"types": "./dist/index.d.ts",
|
|
34
|
-
"files": [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"build": "tsc --build --clean && tsc"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fimbul-works/vec",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A high-performance vector math library for TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "FimbulWorks <contact@fimbul.works>",
|
|
9
|
+
"homepage": "https://github.com/fimbul-works/vec#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/fimbul-works/vec.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/fimbul-works/vec/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"2d",
|
|
19
|
+
"3d",
|
|
20
|
+
"4d",
|
|
21
|
+
"computer-graphics",
|
|
22
|
+
"game-development",
|
|
23
|
+
"geometry",
|
|
24
|
+
"graphics",
|
|
25
|
+
"linear-algebra",
|
|
26
|
+
"math",
|
|
27
|
+
"physics",
|
|
28
|
+
"vector-math",
|
|
29
|
+
"vector"
|
|
30
|
+
],
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "tsc --watch",
|
|
38
|
+
"build": "tsc --build --clean && tsc",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.js",
|
|
45
|
+
"require": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./vec2": {
|
|
48
|
+
"types": "./dist/vec2.d.ts",
|
|
49
|
+
"import": "./dist/vec2.js",
|
|
50
|
+
"require": "./dist/vec2.js"
|
|
51
|
+
},
|
|
52
|
+
"./vec3": {
|
|
53
|
+
"types": "./dist/vec3.d.ts",
|
|
54
|
+
"import": "./dist/vec3.js",
|
|
55
|
+
"require": "./dist/vec3.js"
|
|
56
|
+
},
|
|
57
|
+
"./vec4": {
|
|
58
|
+
"types": "./dist/vec4.d.ts",
|
|
59
|
+
"import": "./dist/vec4.js",
|
|
60
|
+
"require": "./dist/vec4.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=16.0.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@biomejs/biome": "^1.9.4",
|
|
68
|
+
"typescript": "^5.6.2"
|
|
69
|
+
}
|
|
70
|
+
}
|