@arvarus/perlin-noise 0.1.3 → 0.1.4
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/package.json +16 -9
- package/dist/__tests__/grid.test.d.ts +0 -1
- package/dist/__tests__/grid.test.js +0 -270
- package/dist/__tests__/index.test.d.ts +0 -1
- package/dist/__tests__/index.test.js +0 -240
- package/dist/__tests__/interpolation.test.d.ts +0 -1
- package/dist/__tests__/interpolation.test.js +0 -253
- package/dist/__tests__/scalar.test.d.ts +0 -1
- package/dist/__tests__/scalar.test.js +0 -210
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arvarus/perlin-noise",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Perlin noise implementation in TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"watch": "tsc --watch",
|
|
10
10
|
"clean": "rm -rf dist",
|
|
11
|
-
"lint": "eslint src
|
|
12
|
-
"lint:fix": "eslint src --
|
|
11
|
+
"lint": "cross-env ESLINT_USE_FLAT_CONFIG=true eslint src",
|
|
12
|
+
"lint:fix": "cross-env ESLINT_USE_FLAT_CONFIG=true eslint src --fix",
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:watch": "jest --watch",
|
|
15
15
|
"test:coverage": "jest --coverage",
|
|
@@ -23,13 +23,20 @@
|
|
|
23
23
|
],
|
|
24
24
|
"author": "",
|
|
25
25
|
"license": "GPL-3.0",
|
|
26
|
+
"overrides": {
|
|
27
|
+
"minimatch": ">=10.2.1"
|
|
28
|
+
},
|
|
26
29
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@typescript-eslint/
|
|
30
|
-
"eslint": "^8.
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"@eslint/js": "^9.39.2",
|
|
31
|
+
"@types/jest": "^30.0.0",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
33
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
34
|
+
"cross-env": "^10.1.0",
|
|
35
|
+
"eslint": "^9.39.2",
|
|
36
|
+
"globals": "^17.3.0",
|
|
37
|
+
"jest": "^30.2.0",
|
|
38
|
+
"ts-jest": "^29.4.6",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
33
40
|
"typescript": "^5.0.0"
|
|
34
41
|
},
|
|
35
42
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const grid_1 = require("../grid");
|
|
4
|
-
describe('generateGradientGrid', () => {
|
|
5
|
-
describe('1D grid', () => {
|
|
6
|
-
it('should generate correct number of grid points', () => {
|
|
7
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
8
|
-
expect(grid.size).toBe(6); // size + 1
|
|
9
|
-
});
|
|
10
|
-
it('should generate scalars between -1 and 1', () => {
|
|
11
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [10], 456);
|
|
12
|
-
for (const gradient of grid.values()) {
|
|
13
|
-
expect(typeof gradient).toBe('number');
|
|
14
|
-
const scalar = gradient;
|
|
15
|
-
expect(scalar).toBeGreaterThanOrEqual(-1);
|
|
16
|
-
expect(scalar).toBeLessThanOrEqual(1);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
it('should generate same grid with same seed', () => {
|
|
20
|
-
const grid1 = (0, grid_1.generateGradientGrid)(1, [5], 789);
|
|
21
|
-
const grid2 = (0, grid_1.generateGradientGrid)(1, [5], 789);
|
|
22
|
-
expect(grid1.size).toBe(grid2.size);
|
|
23
|
-
for (const [key, value] of grid1.entries()) {
|
|
24
|
-
expect(grid2.get(key)).toBe(value);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
it('should generate different grid with different seed', () => {
|
|
28
|
-
const grid1 = (0, grid_1.generateGradientGrid)(1, [5], 100);
|
|
29
|
-
const grid2 = (0, grid_1.generateGradientGrid)(1, [5], 200);
|
|
30
|
-
// At least some values should be different
|
|
31
|
-
let hasDifference = false;
|
|
32
|
-
for (const [key, value] of grid1.entries()) {
|
|
33
|
-
if (grid2.get(key) !== value) {
|
|
34
|
-
hasDifference = true;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
expect(hasDifference).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
it('should have correct keys for 1D grid', () => {
|
|
41
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [3], 123);
|
|
42
|
-
expect(grid.has('0')).toBe(true);
|
|
43
|
-
expect(grid.has('1')).toBe(true);
|
|
44
|
-
expect(grid.has('2')).toBe(true);
|
|
45
|
-
expect(grid.has('3')).toBe(true);
|
|
46
|
-
expect(grid.has('4')).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe('2D grid', () => {
|
|
50
|
-
it('should generate correct number of grid points', () => {
|
|
51
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [3, 3], 123);
|
|
52
|
-
expect(grid.size).toBe(16); // (3 + 1) * (3 + 1) = 16
|
|
53
|
-
});
|
|
54
|
-
it('should generate unit-length 2D vectors', () => {
|
|
55
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 456);
|
|
56
|
-
for (const gradient of grid.values()) {
|
|
57
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
58
|
-
const vector = gradient;
|
|
59
|
-
expect(vector.length).toBe(2);
|
|
60
|
-
// Check unit length (within floating point precision)
|
|
61
|
-
const magnitude = Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]);
|
|
62
|
-
expect(magnitude).toBeCloseTo(1, 10);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
it('should generate same grid with same seed', () => {
|
|
66
|
-
const grid1 = (0, grid_1.generateGradientGrid)(2, [3, 3], 789);
|
|
67
|
-
const grid2 = (0, grid_1.generateGradientGrid)(2, [3, 3], 789);
|
|
68
|
-
expect(grid1.size).toBe(grid2.size);
|
|
69
|
-
for (const [key, value] of grid1.entries()) {
|
|
70
|
-
const v1 = value;
|
|
71
|
-
const v2 = grid2.get(key);
|
|
72
|
-
expect(v2).toBeDefined();
|
|
73
|
-
expect(v1[0]).toBeCloseTo(v2[0], 10);
|
|
74
|
-
expect(v1[1]).toBeCloseTo(v2[1], 10);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
it('should have correct keys for 2D grid', () => {
|
|
78
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [2, 2], 123);
|
|
79
|
-
expect(grid.has('0,0')).toBe(true);
|
|
80
|
-
expect(grid.has('0,1')).toBe(true);
|
|
81
|
-
expect(grid.has('1,0')).toBe(true);
|
|
82
|
-
expect(grid.has('2,2')).toBe(true);
|
|
83
|
-
expect(grid.has('3,3')).toBe(false); // size is 2, so max is 2
|
|
84
|
-
});
|
|
85
|
-
it('should support different sizes per dimension', () => {
|
|
86
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [2, 3], 123);
|
|
87
|
-
// First dimension: 2 + 1 = 3 points (0, 1, 2)
|
|
88
|
-
// Second dimension: 3 + 1 = 4 points (0, 1, 2, 3)
|
|
89
|
-
// Total: 3 * 4 = 12 points
|
|
90
|
-
expect(grid.size).toBe(12);
|
|
91
|
-
expect(grid.has('0,0')).toBe(true);
|
|
92
|
-
expect(grid.has('2,3')).toBe(true);
|
|
93
|
-
expect(grid.has('3,3')).toBe(false); // First dimension max is 2
|
|
94
|
-
expect(grid.has('2,4')).toBe(false); // Second dimension max is 3
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe('3D grid', () => {
|
|
98
|
-
it('should generate correct number of grid points', () => {
|
|
99
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [2, 2, 2], 123);
|
|
100
|
-
expect(grid.size).toBe(27); // (2 + 1) ^ 3 = 27
|
|
101
|
-
});
|
|
102
|
-
it('should generate unit-length 3D vectors', () => {
|
|
103
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [3, 3, 3], 456);
|
|
104
|
-
for (const gradient of grid.values()) {
|
|
105
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
106
|
-
const vector = gradient;
|
|
107
|
-
expect(vector.length).toBe(3);
|
|
108
|
-
// Check unit length
|
|
109
|
-
const magnitude = Math.sqrt(vector[0] * vector[0] +
|
|
110
|
-
vector[1] * vector[1] +
|
|
111
|
-
vector[2] * vector[2]);
|
|
112
|
-
expect(magnitude).toBeCloseTo(1, 10);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
it('should generate same grid with same seed', () => {
|
|
116
|
-
const grid1 = (0, grid_1.generateGradientGrid)(3, [2, 2, 2], 789);
|
|
117
|
-
const grid2 = (0, grid_1.generateGradientGrid)(3, [2, 2, 2], 789);
|
|
118
|
-
expect(grid1.size).toBe(grid2.size);
|
|
119
|
-
for (const [key, value] of grid1.entries()) {
|
|
120
|
-
const v1 = value;
|
|
121
|
-
const v2 = grid2.get(key);
|
|
122
|
-
expect(v2).toBeDefined();
|
|
123
|
-
expect(v1[0]).toBeCloseTo(v2[0], 10);
|
|
124
|
-
expect(v1[1]).toBeCloseTo(v2[1], 10);
|
|
125
|
-
expect(v1[2]).toBeCloseTo(v2[2], 10);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
it('should have correct keys for 3D grid', () => {
|
|
129
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [1, 1, 1], 123);
|
|
130
|
-
expect(grid.has('0,0,0')).toBe(true);
|
|
131
|
-
expect(grid.has('1,1,1')).toBe(true);
|
|
132
|
-
expect(grid.has('2,2,2')).toBe(false); // size is 1, so max is 1
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
describe('4D grid', () => {
|
|
136
|
-
it('should generate correct number of grid points', () => {
|
|
137
|
-
const grid = (0, grid_1.generateGradientGrid)(4, [2, 2, 2, 2], 123);
|
|
138
|
-
expect(grid.size).toBe(81); // (2 + 1) ^ 4 = 81
|
|
139
|
-
});
|
|
140
|
-
it('should generate unit-length 4D vectors', () => {
|
|
141
|
-
const grid = (0, grid_1.generateGradientGrid)(4, [2, 2, 2, 2], 456);
|
|
142
|
-
for (const gradient of grid.values()) {
|
|
143
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
144
|
-
const vector = gradient;
|
|
145
|
-
expect(vector.length).toBe(4);
|
|
146
|
-
// Check unit length
|
|
147
|
-
const magnitude = Math.sqrt(vector[0] * vector[0] +
|
|
148
|
-
vector[1] * vector[1] +
|
|
149
|
-
vector[2] * vector[2] +
|
|
150
|
-
vector[3] * vector[3]);
|
|
151
|
-
expect(magnitude).toBeCloseTo(1, 10);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
it('should generate same grid with same seed', () => {
|
|
155
|
-
const grid1 = (0, grid_1.generateGradientGrid)(4, [1, 1, 1, 1], 789);
|
|
156
|
-
const grid2 = (0, grid_1.generateGradientGrid)(4, [1, 1, 1, 1], 789);
|
|
157
|
-
expect(grid1.size).toBe(grid2.size);
|
|
158
|
-
for (const [key, value] of grid1.entries()) {
|
|
159
|
-
const v1 = value;
|
|
160
|
-
const v2 = grid2.get(key);
|
|
161
|
-
expect(v2).toBeDefined();
|
|
162
|
-
expect(v1[0]).toBeCloseTo(v2[0], 10);
|
|
163
|
-
expect(v1[1]).toBeCloseTo(v2[1], 10);
|
|
164
|
-
expect(v1[2]).toBeCloseTo(v2[2], 10);
|
|
165
|
-
expect(v1[3]).toBeCloseTo(v2[3], 10);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
it('should have correct keys for 4D grid', () => {
|
|
169
|
-
const grid = (0, grid_1.generateGradientGrid)(4, [1, 1, 1, 1], 123);
|
|
170
|
-
expect(grid.has('0,0,0,0')).toBe(true);
|
|
171
|
-
expect(grid.has('1,1,1,1')).toBe(true);
|
|
172
|
-
expect(grid.has('2,2,2,2')).toBe(false); // size is 1, so max is 1
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe('higher dimensions', () => {
|
|
176
|
-
it('should support 5D grids', () => {
|
|
177
|
-
const grid = (0, grid_1.generateGradientGrid)(5, [1, 1, 1, 1, 1], 123);
|
|
178
|
-
expect(grid.size).toBe(32); // (1 + 1) ^ 5 = 32
|
|
179
|
-
expect(grid.has('0,0,0,0,0')).toBe(true);
|
|
180
|
-
expect(grid.has('1,1,1,1,1')).toBe(true);
|
|
181
|
-
expect(grid.has('2,2,2,2,2')).toBe(false);
|
|
182
|
-
// Check that gradients are arrays of length 5
|
|
183
|
-
for (const gradient of grid.values()) {
|
|
184
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
185
|
-
const vector = gradient;
|
|
186
|
-
expect(vector.length).toBe(5);
|
|
187
|
-
// Check unit length
|
|
188
|
-
const magnitude = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
|
|
189
|
-
expect(magnitude).toBeCloseTo(1, 10);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
it('should support 6D grids', () => {
|
|
193
|
-
const grid = (0, grid_1.generateGradientGrid)(6, [1, 1, 1, 1, 1, 1], 123);
|
|
194
|
-
expect(grid.size).toBe(64); // (1 + 1) ^ 6 = 64
|
|
195
|
-
expect(grid.has('0,0,0,0,0,0')).toBe(true);
|
|
196
|
-
expect(grid.has('1,1,1,1,1,1')).toBe(true);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
describe('edge cases', () => {
|
|
200
|
-
it('should handle size 0', () => {
|
|
201
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [0], 123);
|
|
202
|
-
expect(grid.size).toBe(1); // 0 + 1 = 1
|
|
203
|
-
expect(grid.has('0')).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
it('should handle size 0 for 2D', () => {
|
|
206
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [0, 0], 123);
|
|
207
|
-
expect(grid.size).toBe(1); // (0 + 1) ^ 2 = 1
|
|
208
|
-
expect(grid.has('0,0')).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
it('should use different default seeds when seed not provided', () => {
|
|
211
|
-
const grid1 = (0, grid_1.generateGradientGrid)(1, [5]);
|
|
212
|
-
const grid2 = (0, grid_1.generateGradientGrid)(1, [5]);
|
|
213
|
-
// They might be the same by chance, but very unlikely
|
|
214
|
-
// We'll just check that the function doesn't crash
|
|
215
|
-
expect(grid1.size).toBe(6);
|
|
216
|
-
expect(grid2.size).toBe(6);
|
|
217
|
-
});
|
|
218
|
-
it('should throw error when size array length does not match dimension', () => {
|
|
219
|
-
expect(() => (0, grid_1.generateGradientGrid)(2, [3], 123)).toThrow();
|
|
220
|
-
expect(() => (0, grid_1.generateGradientGrid)(2, [3, 4, 5], 123)).toThrow();
|
|
221
|
-
expect(() => (0, grid_1.generateGradientGrid)(3, [2, 2], 123)).toThrow();
|
|
222
|
-
});
|
|
223
|
-
it('should throw error when dimension is not a positive integer', () => {
|
|
224
|
-
expect(() => (0, grid_1.generateGradientGrid)(0, [], 123)).toThrow();
|
|
225
|
-
expect(() => (0, grid_1.generateGradientGrid)(-1, [-1], 123)).toThrow();
|
|
226
|
-
expect(() => (0, grid_1.generateGradientGrid)(1.5, [1], 123)).toThrow();
|
|
227
|
-
expect(() => (0, grid_1.generateGradientGrid)(2.0, [1, 1], 123)).not.toThrow(); // 2.0 is valid
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
describe('getGradientAt', () => {
|
|
232
|
-
it('should retrieve gradient from 1D grid', () => {
|
|
233
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
234
|
-
const gradient = (0, grid_1.getGradientAt)(grid, [2]);
|
|
235
|
-
expect(gradient).toBeDefined();
|
|
236
|
-
expect(typeof gradient).toBe('number');
|
|
237
|
-
expect(gradient).toBe(grid.get('2'));
|
|
238
|
-
});
|
|
239
|
-
it('should retrieve gradient from 2D grid', () => {
|
|
240
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [3, 3], 123);
|
|
241
|
-
const gradient = (0, grid_1.getGradientAt)(grid, [1, 2]);
|
|
242
|
-
expect(gradient).toBeDefined();
|
|
243
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
244
|
-
expect(gradient).toEqual(grid.get('1,2'));
|
|
245
|
-
});
|
|
246
|
-
it('should retrieve gradient from 3D grid', () => {
|
|
247
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [2, 2, 2], 123);
|
|
248
|
-
const gradient = (0, grid_1.getGradientAt)(grid, [1, 0, 2]);
|
|
249
|
-
expect(gradient).toBeDefined();
|
|
250
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
251
|
-
expect(gradient).toEqual(grid.get('1,0,2'));
|
|
252
|
-
});
|
|
253
|
-
it('should retrieve gradient from 4D grid', () => {
|
|
254
|
-
const grid = (0, grid_1.generateGradientGrid)(4, [1, 1, 1, 1], 123);
|
|
255
|
-
const gradient = (0, grid_1.getGradientAt)(grid, [1, 1, 0, 1]);
|
|
256
|
-
expect(gradient).toBeDefined();
|
|
257
|
-
expect(Array.isArray(gradient)).toBe(true);
|
|
258
|
-
expect(gradient).toEqual(grid.get('1,1,0,1'));
|
|
259
|
-
});
|
|
260
|
-
it('should return undefined for non-existent coordinates', () => {
|
|
261
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [3, 3], 123);
|
|
262
|
-
const gradient = (0, grid_1.getGradientAt)(grid, [10, 10]);
|
|
263
|
-
expect(gradient).toBeUndefined();
|
|
264
|
-
});
|
|
265
|
-
it('should return undefined for empty grid', () => {
|
|
266
|
-
const emptyGrid = new Map();
|
|
267
|
-
const gradient = (0, grid_1.getGradientAt)(emptyGrid, [0, 0]);
|
|
268
|
-
expect(gradient).toBeUndefined();
|
|
269
|
-
});
|
|
270
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../index");
|
|
4
|
-
describe('PerlinNoise', () => {
|
|
5
|
-
describe('constructor', () => {
|
|
6
|
-
it('should create instance with default options', () => {
|
|
7
|
-
const noise = new index_1.PerlinNoise();
|
|
8
|
-
expect(noise).toBeInstanceOf(index_1.PerlinNoise);
|
|
9
|
-
});
|
|
10
|
-
it('should create instance with options object', () => {
|
|
11
|
-
const options = { seed: 456, gridSize: [10, 10, 10] };
|
|
12
|
-
const noise = new index_1.PerlinNoise(options);
|
|
13
|
-
expect(noise).toBeInstanceOf(index_1.PerlinNoise);
|
|
14
|
-
});
|
|
15
|
-
it('should use provided seed', () => {
|
|
16
|
-
const noise1 = new index_1.PerlinNoise({ seed: 789, gridSize: [10, 10, 10] });
|
|
17
|
-
const noise2 = new index_1.PerlinNoise({ seed: 789, gridSize: [10, 10, 10] });
|
|
18
|
-
// Same seed should produce same results
|
|
19
|
-
expect(noise1.noise([1.0, 1.0, 1.0])).toBeCloseTo(noise2.noise([1.0, 1.0, 1.0]), 10);
|
|
20
|
-
});
|
|
21
|
-
it('should use default grid size when not provided', () => {
|
|
22
|
-
const noise = new index_1.PerlinNoise({ seed: 123 });
|
|
23
|
-
// Should work with 3D coordinates (default dimension)
|
|
24
|
-
const value = noise.noise([1.0, 1.0, 1.0]);
|
|
25
|
-
expect(typeof value).toBe('number');
|
|
26
|
-
});
|
|
27
|
-
it('should throw error for invalid grid size length', () => {
|
|
28
|
-
expect(() => new index_1.PerlinNoise({ gridSize: [] })).toThrow();
|
|
29
|
-
expect(() => new index_1.PerlinNoise({ gridSize: Array(11).fill(10) })).toThrow();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe('1D noise', () => {
|
|
33
|
-
it('should generate noise value for 1D coordinates', () => {
|
|
34
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
35
|
-
const value = noise.noise([1.5]);
|
|
36
|
-
expect(typeof value).toBe('number');
|
|
37
|
-
expect(value).toBeGreaterThanOrEqual(-2);
|
|
38
|
-
expect(value).toBeLessThanOrEqual(2);
|
|
39
|
-
});
|
|
40
|
-
it('should produce consistent results for same point', () => {
|
|
41
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
42
|
-
const value1 = noise.noise([2.3]);
|
|
43
|
-
const value2 = noise.noise([2.3]);
|
|
44
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
45
|
-
});
|
|
46
|
-
it('should produce different results for different points', () => {
|
|
47
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
48
|
-
const value1 = noise.noise([1.0]);
|
|
49
|
-
const value2 = noise.noise([5.0]);
|
|
50
|
-
// They might be the same by chance, but very unlikely
|
|
51
|
-
expect(typeof value1).toBe('number');
|
|
52
|
-
expect(typeof value2).toBe('number');
|
|
53
|
-
});
|
|
54
|
-
it('should handle negative coordinates', () => {
|
|
55
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
56
|
-
const value = noise.noise([-1.5]);
|
|
57
|
-
expect(typeof value).toBe('number');
|
|
58
|
-
});
|
|
59
|
-
it('should handle large coordinates (wrapping)', () => {
|
|
60
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
61
|
-
const value1 = noise.noise([1.5]);
|
|
62
|
-
const value2 = noise.noise([11.5]); // Should wrap to 1.5
|
|
63
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
64
|
-
});
|
|
65
|
-
it('should handle coordinates at grid boundaries', () => {
|
|
66
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
67
|
-
const value = noise.noise([10.0]);
|
|
68
|
-
expect(typeof value).toBe('number');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
describe('2D noise', () => {
|
|
72
|
-
it('should generate noise value for 2D coordinates', () => {
|
|
73
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
74
|
-
const value = noise.noise([1.5, 2.3]);
|
|
75
|
-
expect(typeof value).toBe('number');
|
|
76
|
-
expect(value).toBeGreaterThanOrEqual(-2);
|
|
77
|
-
expect(value).toBeLessThanOrEqual(2);
|
|
78
|
-
});
|
|
79
|
-
it('should produce consistent results for same point', () => {
|
|
80
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
81
|
-
const value1 = noise.noise([2.3, 4.7]);
|
|
82
|
-
const value2 = noise.noise([2.3, 4.7]);
|
|
83
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
84
|
-
});
|
|
85
|
-
it('should produce different results for different points', () => {
|
|
86
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
87
|
-
const value1 = noise.noise([1.0, 1.0]);
|
|
88
|
-
const value2 = noise.noise([5.0, 5.0]);
|
|
89
|
-
expect(typeof value1).toBe('number');
|
|
90
|
-
expect(typeof value2).toBe('number');
|
|
91
|
-
});
|
|
92
|
-
it('should handle negative coordinates', () => {
|
|
93
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
94
|
-
const value = noise.noise([-1.5, -2.3]);
|
|
95
|
-
expect(typeof value).toBe('number');
|
|
96
|
-
});
|
|
97
|
-
it('should handle large coordinates (wrapping)', () => {
|
|
98
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
99
|
-
const value1 = noise.noise([1.5, 2.3]);
|
|
100
|
-
const value2 = noise.noise([11.5, 12.3]); // Should wrap
|
|
101
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
102
|
-
});
|
|
103
|
-
it('should produce smooth transitions', () => {
|
|
104
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
105
|
-
const value1 = noise.noise([1.0, 1.0]);
|
|
106
|
-
const value2 = noise.noise([1.1, 1.0]);
|
|
107
|
-
const value3 = noise.noise([1.2, 1.0]);
|
|
108
|
-
// Values should change gradually (not jump dramatically)
|
|
109
|
-
expect(typeof value1).toBe('number');
|
|
110
|
-
expect(typeof value2).toBe('number');
|
|
111
|
-
expect(typeof value3).toBe('number');
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe('3D noise', () => {
|
|
115
|
-
it('should generate noise value for 3D coordinates', () => {
|
|
116
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
117
|
-
const value = noise.noise([1.5, 2.3, 3.7]);
|
|
118
|
-
expect(typeof value).toBe('number');
|
|
119
|
-
expect(value).toBeGreaterThanOrEqual(-2);
|
|
120
|
-
expect(value).toBeLessThanOrEqual(2);
|
|
121
|
-
});
|
|
122
|
-
it('should produce consistent results for same point', () => {
|
|
123
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
124
|
-
const value1 = noise.noise([2.3, 4.7, 1.2]);
|
|
125
|
-
const value2 = noise.noise([2.3, 4.7, 1.2]);
|
|
126
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
127
|
-
});
|
|
128
|
-
it('should produce different results for different points', () => {
|
|
129
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
130
|
-
const value1 = noise.noise([1.0, 1.0, 1.0]);
|
|
131
|
-
const value2 = noise.noise([5.0, 5.0, 5.0]);
|
|
132
|
-
expect(typeof value1).toBe('number');
|
|
133
|
-
expect(typeof value2).toBe('number');
|
|
134
|
-
});
|
|
135
|
-
it('should handle negative coordinates', () => {
|
|
136
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
137
|
-
const value = noise.noise([-1.5, -2.3, -3.7]);
|
|
138
|
-
expect(typeof value).toBe('number');
|
|
139
|
-
});
|
|
140
|
-
it('should handle large coordinates (wrapping)', () => {
|
|
141
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
142
|
-
const value1 = noise.noise([1.5, 2.3, 3.7]);
|
|
143
|
-
const value2 = noise.noise([11.5, 12.3, 13.7]); // Should wrap
|
|
144
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('dimension validation', () => {
|
|
148
|
-
it('should throw error when noise dimension does not match grid dimension', () => {
|
|
149
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
150
|
-
expect(() => noise.noise([1.0])).toThrow(); // 1D noise on 2D grid
|
|
151
|
-
expect(() => noise.noise([1.0, 1.0, 1.0])).toThrow(); // 3D noise on 2D grid
|
|
152
|
-
});
|
|
153
|
-
it('should allow 1D noise on 1D grid', () => {
|
|
154
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10] });
|
|
155
|
-
expect(() => noise.noise([1.0])).not.toThrow();
|
|
156
|
-
});
|
|
157
|
-
it('should allow 2D noise on 2D grid', () => {
|
|
158
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10] });
|
|
159
|
-
expect(() => noise.noise([1.0, 1.0])).not.toThrow();
|
|
160
|
-
});
|
|
161
|
-
it('should allow 3D noise on 3D grid', () => {
|
|
162
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
163
|
-
expect(() => noise.noise([1.0, 1.0, 1.0])).not.toThrow();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
describe('seed behavior', () => {
|
|
167
|
-
it('should produce different results with different seeds', () => {
|
|
168
|
-
const noise1 = new index_1.PerlinNoise({ seed: 100, gridSize: [10, 10, 10] });
|
|
169
|
-
const noise2 = new index_1.PerlinNoise({ seed: 200, gridSize: [10, 10, 10] });
|
|
170
|
-
const value1 = noise1.noise([1.0, 1.0, 1.0]);
|
|
171
|
-
const value2 = noise2.noise([1.0, 1.0, 1.0]);
|
|
172
|
-
// They might be the same by chance, but very unlikely
|
|
173
|
-
expect(typeof value1).toBe('number');
|
|
174
|
-
expect(typeof value2).toBe('number');
|
|
175
|
-
});
|
|
176
|
-
it('should produce same results with same seed', () => {
|
|
177
|
-
const noise1 = new index_1.PerlinNoise({ seed: 500, gridSize: [10, 10, 10] });
|
|
178
|
-
const noise2 = new index_1.PerlinNoise({ seed: 500, gridSize: [10, 10, 10] });
|
|
179
|
-
const value1 = noise1.noise([2.5, 3.7, 1.2]);
|
|
180
|
-
const value2 = noise2.noise([2.5, 3.7, 1.2]);
|
|
181
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
describe('edge cases', () => {
|
|
185
|
-
it('should handle zero coordinates', () => {
|
|
186
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
187
|
-
const value = noise.noise([0.0, 0.0, 0.0]);
|
|
188
|
-
expect(typeof value).toBe('number');
|
|
189
|
-
});
|
|
190
|
-
it('should handle very small coordinates', () => {
|
|
191
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
192
|
-
const value = noise.noise([0.0001, 0.0001, 0.0001]);
|
|
193
|
-
expect(typeof value).toBe('number');
|
|
194
|
-
});
|
|
195
|
-
it('should handle very large coordinates', () => {
|
|
196
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
197
|
-
const value = noise.noise([1000.5, 2000.3, 3000.7]);
|
|
198
|
-
expect(typeof value).toBe('number');
|
|
199
|
-
});
|
|
200
|
-
it('should handle coordinates at exact grid boundaries', () => {
|
|
201
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [10, 10, 10] });
|
|
202
|
-
const value = noise.noise([10.0, 10.0, 10.0]);
|
|
203
|
-
expect(typeof value).toBe('number');
|
|
204
|
-
});
|
|
205
|
-
it('should handle different grid sizes', () => {
|
|
206
|
-
const noise1 = new index_1.PerlinNoise({ seed: 123, gridSize: [5, 5, 5] });
|
|
207
|
-
const noise2 = new index_1.PerlinNoise({ seed: 123, gridSize: [20, 20, 20] });
|
|
208
|
-
const value1 = noise1.noise([1.0, 1.0, 1.0]);
|
|
209
|
-
const value2 = noise2.noise([1.0, 1.0, 1.0]);
|
|
210
|
-
// Different grid sizes with same seed should produce different results
|
|
211
|
-
expect(typeof value1).toBe('number');
|
|
212
|
-
expect(typeof value2).toBe('number');
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
describe('higher dimensions', () => {
|
|
216
|
-
it('should support 4D noise', () => {
|
|
217
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [5, 5, 5, 5] });
|
|
218
|
-
const value = noise.noise([1.0, 1.0, 1.0, 1.0]);
|
|
219
|
-
expect(typeof value).toBe('number');
|
|
220
|
-
expect(value).toBeGreaterThanOrEqual(-2);
|
|
221
|
-
expect(value).toBeLessThanOrEqual(2);
|
|
222
|
-
});
|
|
223
|
-
it('should support 5D noise', () => {
|
|
224
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [5, 5, 5, 5, 5] });
|
|
225
|
-
const value = noise.noise([1.0, 1.0, 1.0, 1.0, 1.0]);
|
|
226
|
-
expect(typeof value).toBe('number');
|
|
227
|
-
});
|
|
228
|
-
it('should support 10D noise (maximum)', () => {
|
|
229
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] });
|
|
230
|
-
const value = noise.noise([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
|
|
231
|
-
expect(typeof value).toBe('number');
|
|
232
|
-
});
|
|
233
|
-
it('should produce consistent results for same point in higher dimensions', () => {
|
|
234
|
-
const noise = new index_1.PerlinNoise({ seed: 123, gridSize: [5, 5, 5, 5] });
|
|
235
|
-
const value1 = noise.noise([2.3, 4.7, 1.2, 3.5]);
|
|
236
|
-
const value2 = noise.noise([2.3, 4.7, 1.2, 3.5]);
|
|
237
|
-
expect(value1).toBeCloseTo(value2, 10);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const interpolation_1 = require("../interpolation");
|
|
4
|
-
describe('smoothstep', () => {
|
|
5
|
-
it('should return 0 for t = 0', () => {
|
|
6
|
-
expect((0, interpolation_1.smoothstep)(0)).toBe(0);
|
|
7
|
-
});
|
|
8
|
-
it('should return 1 for t = 1', () => {
|
|
9
|
-
expect((0, interpolation_1.smoothstep)(1)).toBe(1);
|
|
10
|
-
});
|
|
11
|
-
it('should return 0.5 for t = 0.5', () => {
|
|
12
|
-
expect((0, interpolation_1.smoothstep)(0.5)).toBe(0.5);
|
|
13
|
-
});
|
|
14
|
-
it('should be symmetric around 0.5', () => {
|
|
15
|
-
const t1 = 0.3;
|
|
16
|
-
const t2 = 0.7;
|
|
17
|
-
const s1 = (0, interpolation_1.smoothstep)(t1);
|
|
18
|
-
const s2 = (0, interpolation_1.smoothstep)(t2);
|
|
19
|
-
expect(s1 + s2).toBeCloseTo(1, 10);
|
|
20
|
-
});
|
|
21
|
-
it('should clamp values outside [0, 1]', () => {
|
|
22
|
-
expect((0, interpolation_1.smoothstep)(-1)).toBe(0);
|
|
23
|
-
expect((0, interpolation_1.smoothstep)(2)).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
it('should have zero derivative at endpoints', () => {
|
|
26
|
-
// Numerical test of derivative near 0
|
|
27
|
-
const h = 0.0001;
|
|
28
|
-
const derivativeAt0 = ((0, interpolation_1.smoothstep)(h) - (0, interpolation_1.smoothstep)(0)) / h;
|
|
29
|
-
expect(derivativeAt0).toBeCloseTo(0, 2);
|
|
30
|
-
// Numerical test of derivative near 1
|
|
31
|
-
const derivativeAt1 = ((0, interpolation_1.smoothstep)(1) - (0, interpolation_1.smoothstep)(1 - h)) / h;
|
|
32
|
-
expect(derivativeAt1).toBeCloseTo(0, 2);
|
|
33
|
-
});
|
|
34
|
-
it('should be monotonically increasing', () => {
|
|
35
|
-
const values = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0];
|
|
36
|
-
for (let i = 1; i < values.length; i++) {
|
|
37
|
-
expect((0, interpolation_1.smoothstep)(values[i])).toBeGreaterThanOrEqual((0, interpolation_1.smoothstep)(values[i - 1]));
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('calculateFractionalCoordinates', () => {
|
|
42
|
-
it('should calculate fractional coordinates for a 1D point', () => {
|
|
43
|
-
const point = [2.3];
|
|
44
|
-
const fractional = (0, interpolation_1.calculateFractionalCoordinates)(point);
|
|
45
|
-
expect(fractional).toHaveLength(1);
|
|
46
|
-
expect(fractional[0]).toBeCloseTo(0.3, 10);
|
|
47
|
-
});
|
|
48
|
-
it('should calculate fractional coordinates for a 2D point', () => {
|
|
49
|
-
const point = [1.7, 3.2];
|
|
50
|
-
const fractional = (0, interpolation_1.calculateFractionalCoordinates)(point);
|
|
51
|
-
expect(fractional).toHaveLength(2);
|
|
52
|
-
expect(fractional[0]).toBeCloseTo(0.7, 10);
|
|
53
|
-
expect(fractional[1]).toBeCloseTo(0.2, 10);
|
|
54
|
-
});
|
|
55
|
-
it('should return 0 for a point exactly on a grid node', () => {
|
|
56
|
-
const point = [2.0, 3.0];
|
|
57
|
-
const fractional = (0, interpolation_1.calculateFractionalCoordinates)(point);
|
|
58
|
-
expect(fractional[0]).toBe(0);
|
|
59
|
-
expect(fractional[1]).toBe(0);
|
|
60
|
-
});
|
|
61
|
-
it('should handle negative coordinates', () => {
|
|
62
|
-
const point = [-1.3];
|
|
63
|
-
const fractional = (0, interpolation_1.calculateFractionalCoordinates)(point);
|
|
64
|
-
// -1.3 is in cell [-2], so fractional coordinate is -1.3 - (-2) = 0.7
|
|
65
|
-
expect(fractional[0]).toBeCloseTo(0.7, 10);
|
|
66
|
-
});
|
|
67
|
-
it('should handle fractional coordinates close to 1', () => {
|
|
68
|
-
const point = [2.99];
|
|
69
|
-
const fractional = (0, interpolation_1.calculateFractionalCoordinates)(point);
|
|
70
|
-
expect(fractional[0]).toBeCloseTo(0.99, 10);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('interpolate1D', () => {
|
|
74
|
-
it('should return a0 for t = 0', () => {
|
|
75
|
-
expect((0, interpolation_1.interpolate1D)(5, 10, 0)).toBe(5);
|
|
76
|
-
});
|
|
77
|
-
it('should return a1 for t = 1', () => {
|
|
78
|
-
expect((0, interpolation_1.interpolate1D)(5, 10, 1)).toBe(10);
|
|
79
|
-
});
|
|
80
|
-
it('should return the average for t = 0.5', () => {
|
|
81
|
-
expect((0, interpolation_1.interpolate1D)(0, 10, 0.5)).toBeCloseTo(5, 10);
|
|
82
|
-
});
|
|
83
|
-
it('should interpolate correctly for different values', () => {
|
|
84
|
-
const result = (0, interpolation_1.interpolate1D)(0, 100, 0.3);
|
|
85
|
-
// For t=0.3, smoothstep(0.3) ≈ 0.216, so result ≈ 0 + 0.216 * 100 = 21.6
|
|
86
|
-
expect(result).toBeGreaterThan(0);
|
|
87
|
-
expect(result).toBeLessThan(100);
|
|
88
|
-
});
|
|
89
|
-
it('should handle negative values', () => {
|
|
90
|
-
expect((0, interpolation_1.interpolate1D)(-10, 10, 0.5)).toBeCloseTo(0, 10);
|
|
91
|
-
});
|
|
92
|
-
it('should be symmetric', () => {
|
|
93
|
-
const result1 = (0, interpolation_1.interpolate1D)(0, 10, 0.3);
|
|
94
|
-
const result2 = (0, interpolation_1.interpolate1D)(10, 0, 0.7);
|
|
95
|
-
expect(result1).toBeCloseTo(result2, 10);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
describe('interpolateScalarValues', () => {
|
|
99
|
-
describe('1D interpolation', () => {
|
|
100
|
-
it('should interpolate between 2 scalar values for a 1D point', () => {
|
|
101
|
-
const scalarValues = [5, 10];
|
|
102
|
-
const point = [0.3]; // Fractional coordinate = 0.3
|
|
103
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
104
|
-
// Should be equivalent to interpolate1D(5, 10, 0.3)
|
|
105
|
-
const expected = (0, interpolation_1.interpolate1D)(5, 10, 0.3);
|
|
106
|
-
expect(result).toBeCloseTo(expected, 10);
|
|
107
|
-
});
|
|
108
|
-
it('should return the first value for a point at node 0', () => {
|
|
109
|
-
const scalarValues = [5, 10];
|
|
110
|
-
const point = [2.0]; // Exactly at node
|
|
111
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
112
|
-
expect(result).toBeCloseTo(5, 10);
|
|
113
|
-
});
|
|
114
|
-
it('should return the second value for a point at node 1', () => {
|
|
115
|
-
const scalarValues = [5, 10];
|
|
116
|
-
// Note: for point=[3.0], fractional coordinate is 0, so we're at node of cell [3]
|
|
117
|
-
// But scalar values are for cell [2], so we test with point=[2.999...]
|
|
118
|
-
const point2 = [2.999999];
|
|
119
|
-
const result2 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point2);
|
|
120
|
-
expect(result2).toBeCloseTo(10, 2);
|
|
121
|
-
});
|
|
122
|
-
it('should throw error if number of values does not match', () => {
|
|
123
|
-
const scalarValues = [5, 10, 15]; // 3 values instead of 2
|
|
124
|
-
const point = [0.5];
|
|
125
|
-
expect(() => (0, interpolation_1.interpolateScalarValues)(scalarValues, point)).toThrow();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('2D interpolation', () => {
|
|
129
|
-
it('should interpolate between 4 scalar values for a 2D point', () => {
|
|
130
|
-
const scalarValues = [0, 10, 20, 30];
|
|
131
|
-
const point = [0.5, 0.5]; // Cell center
|
|
132
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
133
|
-
// At center, we should get approximately the average
|
|
134
|
-
expect(result).toBeGreaterThan(0);
|
|
135
|
-
expect(result).toBeLessThan(30);
|
|
136
|
-
});
|
|
137
|
-
it('should return corner value for a point exactly on a corner', () => {
|
|
138
|
-
const scalarValues = [5, 10, 15, 20];
|
|
139
|
-
const point = [2.0, 3.0]; // Exactly at corner [2,3]
|
|
140
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
141
|
-
// Should return the first value (bottom-left corner)
|
|
142
|
-
expect(result).toBeCloseTo(5, 10);
|
|
143
|
-
});
|
|
144
|
-
it('should interpolate correctly for different positions', () => {
|
|
145
|
-
const scalarValues = [0, 1, 2, 3];
|
|
146
|
-
const point = [0.0, 0.0]; // Bottom-left corner
|
|
147
|
-
const result1 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
148
|
-
expect(result1).toBeCloseTo(0, 10);
|
|
149
|
-
const point2 = [0.999, 0.999]; // Close to top-right corner
|
|
150
|
-
const result2 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point2);
|
|
151
|
-
expect(result2).toBeCloseTo(3, 1);
|
|
152
|
-
});
|
|
153
|
-
it('should throw error if number of values does not match', () => {
|
|
154
|
-
const scalarValues = [0, 1, 2]; // 3 values instead of 4
|
|
155
|
-
const point = [0.5, 0.5];
|
|
156
|
-
expect(() => (0, interpolation_1.interpolateScalarValues)(scalarValues, point)).toThrow();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe('3D interpolation', () => {
|
|
160
|
-
it('should interpolate between 8 scalar values for a 3D point', () => {
|
|
161
|
-
const scalarValues = [0, 1, 2, 3, 4, 5, 6, 7];
|
|
162
|
-
const point = [0.5, 0.5, 0.5]; // Cell center
|
|
163
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
164
|
-
expect(result).toBeGreaterThanOrEqual(0);
|
|
165
|
-
expect(result).toBeLessThanOrEqual(7);
|
|
166
|
-
});
|
|
167
|
-
it('should return corner value for a point exactly on a corner', () => {
|
|
168
|
-
const scalarValues = [10, 20, 30, 40, 50, 60, 70, 80];
|
|
169
|
-
const point = [1.0, 2.0, 3.0]; // Exactly at corner
|
|
170
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
171
|
-
// Should return the first value
|
|
172
|
-
expect(result).toBeCloseTo(10, 10);
|
|
173
|
-
});
|
|
174
|
-
it('should throw error if number of values does not match', () => {
|
|
175
|
-
const scalarValues = [0, 1, 2, 3, 4, 5, 6]; // 7 values instead of 8
|
|
176
|
-
const point = [0.5, 0.5, 0.5];
|
|
177
|
-
expect(() => (0, interpolation_1.interpolateScalarValues)(scalarValues, point)).toThrow();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
describe('higher dimensions', () => {
|
|
181
|
-
it('should interpolate between 16 scalar values for a 4D point', () => {
|
|
182
|
-
const scalarValues = Array.from({ length: 16 }, (_, i) => i);
|
|
183
|
-
const point = [0.5, 0.5, 0.5, 0.5];
|
|
184
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
185
|
-
expect(result).toBeGreaterThanOrEqual(0);
|
|
186
|
-
expect(result).toBeLessThanOrEqual(15);
|
|
187
|
-
});
|
|
188
|
-
it('should interpolate between 32 scalar values for a 5D point', () => {
|
|
189
|
-
const scalarValues = Array.from({ length: 32 }, (_, i) => i);
|
|
190
|
-
const point = [0.5, 0.5, 0.5, 0.5, 0.5];
|
|
191
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
192
|
-
expect(result).toBeGreaterThanOrEqual(0);
|
|
193
|
-
expect(result).toBeLessThanOrEqual(31);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
describe('edge cases', () => {
|
|
197
|
-
it('should handle all identical scalar values', () => {
|
|
198
|
-
const scalarValues = [5, 5, 5, 5];
|
|
199
|
-
const point = [0.7, 0.3];
|
|
200
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
201
|
-
expect(result).toBe(5);
|
|
202
|
-
});
|
|
203
|
-
it('should handle negative scalar values', () => {
|
|
204
|
-
const scalarValues = [-10, -5, 5, 10];
|
|
205
|
-
const point = [0.5, 0.5];
|
|
206
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
207
|
-
expect(result).toBeGreaterThan(-10);
|
|
208
|
-
expect(result).toBeLessThan(10);
|
|
209
|
-
});
|
|
210
|
-
it('should handle very large scalar values', () => {
|
|
211
|
-
const scalarValues = [1000, 2000, 3000, 4000];
|
|
212
|
-
const point = [0.5, 0.5];
|
|
213
|
-
const result = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
214
|
-
expect(result).toBeGreaterThan(1000);
|
|
215
|
-
expect(result).toBeLessThan(4000);
|
|
216
|
-
});
|
|
217
|
-
it('should produce consistent results for the same point', () => {
|
|
218
|
-
const scalarValues = [0, 1, 2, 3];
|
|
219
|
-
const point = [0.7, 0.3];
|
|
220
|
-
const result1 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
221
|
-
const result2 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point);
|
|
222
|
-
expect(result1).toBeCloseTo(result2, 10);
|
|
223
|
-
});
|
|
224
|
-
it('should produce different results for different points', () => {
|
|
225
|
-
const scalarValues = [0, 1, 2, 3];
|
|
226
|
-
const point1 = [0.1, 0.1];
|
|
227
|
-
const point2 = [0.9, 0.9];
|
|
228
|
-
const result1 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point1);
|
|
229
|
-
const result2 = (0, interpolation_1.interpolateScalarValues)(scalarValues, point2);
|
|
230
|
-
expect(result1).not.toBeCloseTo(result2, 10);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
describe('scaleNoiseValue', () => {
|
|
235
|
-
it('should return unchanged value with scale factor of 1.0', () => {
|
|
236
|
-
expect((0, interpolation_1.scaleNoiseValue)(0.5)).toBe(0.5);
|
|
237
|
-
expect((0, interpolation_1.scaleNoiseValue)(-0.3)).toBe(-0.3);
|
|
238
|
-
expect((0, interpolation_1.scaleNoiseValue)(1.0)).toBe(1.0);
|
|
239
|
-
});
|
|
240
|
-
it('should scale correctly with custom scale factor', () => {
|
|
241
|
-
expect((0, interpolation_1.scaleNoiseValue)(0.5, 2.0)).toBe(1.0);
|
|
242
|
-
expect((0, interpolation_1.scaleNoiseValue)(0.5, 0.5)).toBe(0.25);
|
|
243
|
-
expect((0, interpolation_1.scaleNoiseValue)(-0.5, 2.0)).toBe(-1.0);
|
|
244
|
-
});
|
|
245
|
-
it('should handle scale factor of 0', () => {
|
|
246
|
-
expect((0, interpolation_1.scaleNoiseValue)(0.5, 0)).toBe(0);
|
|
247
|
-
expect((0, interpolation_1.scaleNoiseValue)(-0.3, 0)).toBeCloseTo(0, 10);
|
|
248
|
-
});
|
|
249
|
-
it('should handle negative values', () => {
|
|
250
|
-
expect((0, interpolation_1.scaleNoiseValue)(-0.5, 2.0)).toBe(-1.0);
|
|
251
|
-
expect((0, interpolation_1.scaleNoiseValue)(-1.0, 0.5)).toBe(-0.5);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const grid_1 = require("../grid");
|
|
4
|
-
const scalar_1 = require("../scalar");
|
|
5
|
-
describe('calculateScalarValues', () => {
|
|
6
|
-
describe('1D grid', () => {
|
|
7
|
-
it('should return 2 scalar values for a point in 1D (2 vertices)', () => {
|
|
8
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
9
|
-
const point = [2.5]; // Point in cell [2]
|
|
10
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
11
|
-
expect(scalarValues).toHaveLength(2); // 2^1 = 2 vertices
|
|
12
|
-
});
|
|
13
|
-
it('should calculate correct dot products for 1D', () => {
|
|
14
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
15
|
-
const point = [1.3]; // Point in cell [1]
|
|
16
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
17
|
-
// Cell [1] has vertices at [1] and [2]
|
|
18
|
-
const gradient1 = grid.get('1');
|
|
19
|
-
const gradient2 = grid.get('2');
|
|
20
|
-
// Distance vectors: point - vertex
|
|
21
|
-
const distance1 = point[0] - 1; // 1.3 - 1 = 0.3
|
|
22
|
-
const distance2 = point[0] - 2; // 1.3 - 2 = -0.7
|
|
23
|
-
// Dot products: gradient * distance
|
|
24
|
-
const expected1 = gradient1 * distance1;
|
|
25
|
-
const expected2 = gradient2 * distance2;
|
|
26
|
-
expect(scalarValues[0]).toBeCloseTo(expected1, 10);
|
|
27
|
-
expect(scalarValues[1]).toBeCloseTo(expected2, 10);
|
|
28
|
-
});
|
|
29
|
-
it('should handle point at cell boundary', () => {
|
|
30
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
31
|
-
const point = [2.0]; // Exactly at cell boundary (cell [2])
|
|
32
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
33
|
-
expect(scalarValues).toHaveLength(2);
|
|
34
|
-
// Cell [2] has vertices at [2] (i=0) and [3] (i=1)
|
|
35
|
-
// Distance to vertex [2] should be 0
|
|
36
|
-
const gradient2 = grid.get('2');
|
|
37
|
-
expect(scalarValues[0]).toBeCloseTo(gradient2 * 0, 10); // First vertex is [2]
|
|
38
|
-
});
|
|
39
|
-
it('should handle negative coordinates', () => {
|
|
40
|
-
// Create a grid that covers negative coordinates by using a larger grid
|
|
41
|
-
// and testing a point that maps to a valid cell
|
|
42
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [10], 123);
|
|
43
|
-
const point = [0.5]; // Cell [0], which is valid
|
|
44
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
45
|
-
expect(scalarValues).toHaveLength(2);
|
|
46
|
-
// Verify vertices are [0] and [1]
|
|
47
|
-
expect(grid.has('0')).toBe(true);
|
|
48
|
-
expect(grid.has('1')).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
it('should throw error when point is outside grid bounds', () => {
|
|
51
|
-
const grid = (0, grid_1.generateGradientGrid)(1, [5], 123);
|
|
52
|
-
const point = [10.0]; // Outside grid (max is 5, so vertices go up to 6)
|
|
53
|
-
expect(() => (0, scalar_1.calculateScalarValues)(grid, point)).toThrow();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe('2D grid', () => {
|
|
57
|
-
it('should return 4 scalar values for a point in 2D (4 vertices)', () => {
|
|
58
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
59
|
-
const point = [2.5, 3.2]; // Point in cell [2, 3]
|
|
60
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
61
|
-
expect(scalarValues).toHaveLength(4); // 2^2 = 4 vertices
|
|
62
|
-
});
|
|
63
|
-
it('should calculate correct dot products for 2D', () => {
|
|
64
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
65
|
-
const point = [1.3, 2.7]; // Point in cell [1, 2]
|
|
66
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
67
|
-
// Cell [1, 2] has vertices in order: [1,2] (i=0), [2,2] (i=1), [1,3] (i=2), [2,3] (i=3)
|
|
68
|
-
const gradient12 = grid.get('1,2');
|
|
69
|
-
const gradient22 = grid.get('2,2');
|
|
70
|
-
const gradient13 = grid.get('1,3');
|
|
71
|
-
const gradient23 = grid.get('2,3');
|
|
72
|
-
// Distance vectors: point - vertex
|
|
73
|
-
const distance12 = [point[0] - 1, point[1] - 2]; // [0.3, 0.7]
|
|
74
|
-
const distance22 = [point[0] - 2, point[1] - 2]; // [-0.7, 0.7]
|
|
75
|
-
const distance13 = [point[0] - 1, point[1] - 3]; // [0.3, -0.3]
|
|
76
|
-
const distance23 = [point[0] - 2, point[1] - 3]; // [-0.7, -0.3]
|
|
77
|
-
// Dot products
|
|
78
|
-
const expected12 = gradient12[0] * distance12[0] + gradient12[1] * distance12[1];
|
|
79
|
-
const expected22 = gradient22[0] * distance22[0] + gradient22[1] * distance22[1];
|
|
80
|
-
const expected13 = gradient13[0] * distance13[0] + gradient13[1] * distance13[1];
|
|
81
|
-
const expected23 = gradient23[0] * distance23[0] + gradient23[1] * distance23[1];
|
|
82
|
-
expect(scalarValues[0]).toBeCloseTo(expected12, 10);
|
|
83
|
-
expect(scalarValues[1]).toBeCloseTo(expected22, 10);
|
|
84
|
-
expect(scalarValues[2]).toBeCloseTo(expected13, 10);
|
|
85
|
-
expect(scalarValues[3]).toBeCloseTo(expected23, 10);
|
|
86
|
-
});
|
|
87
|
-
it('should handle point at cell corner', () => {
|
|
88
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
89
|
-
const point = [2.0, 3.0]; // Exactly at vertex [2, 3] in cell [2, 3]
|
|
90
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
91
|
-
expect(scalarValues).toHaveLength(4);
|
|
92
|
-
// Cell [2, 3] has vertices in order: [2,3] (i=0), [3,3] (i=1), [2,4] (i=2), [3,4] (i=3)
|
|
93
|
-
// Distance to vertex [2, 3] should be [0, 0]
|
|
94
|
-
expect(scalarValues[0]).toBeCloseTo(0, 10); // dot product with [0, 0] is 0
|
|
95
|
-
});
|
|
96
|
-
it('should handle decimal coordinates correctly', () => {
|
|
97
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
98
|
-
const point = [0.1, 0.9]; // Should be in cell [0, 0]
|
|
99
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
100
|
-
expect(scalarValues).toHaveLength(4);
|
|
101
|
-
// All vertices should be in cell [0, 0]: [0,0], [0,1], [1,0], [1,1]
|
|
102
|
-
expect(grid.has('0,0')).toBe(true);
|
|
103
|
-
expect(grid.has('0,1')).toBe(true);
|
|
104
|
-
expect(grid.has('1,0')).toBe(true);
|
|
105
|
-
expect(grid.has('1,1')).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
it('should throw error when point is outside grid bounds', () => {
|
|
108
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [3, 3], 123);
|
|
109
|
-
const point = [10.0, 10.0]; // Outside grid
|
|
110
|
-
expect(() => (0, scalar_1.calculateScalarValues)(grid, point)).toThrow();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe('3D grid', () => {
|
|
114
|
-
it('should return 8 scalar values for a point in 3D (8 vertices)', () => {
|
|
115
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [5, 5, 5], 123);
|
|
116
|
-
const point = [2.5, 3.2, 1.8]; // Point in cell [2, 3, 1]
|
|
117
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
118
|
-
expect(scalarValues).toHaveLength(8); // 2^3 = 8 vertices
|
|
119
|
-
});
|
|
120
|
-
it('should calculate correct dot products for 3D', () => {
|
|
121
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [5, 5, 5], 123);
|
|
122
|
-
const point = [1.0, 1.0, 1.0]; // Point in cell [1, 1, 1]
|
|
123
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
124
|
-
// Verify we get 8 values
|
|
125
|
-
expect(scalarValues).toHaveLength(8);
|
|
126
|
-
// Verify all vertices exist in grid
|
|
127
|
-
const cell = [1, 1, 1];
|
|
128
|
-
for (let i = 0; i < 8; i++) {
|
|
129
|
-
const vertex = [
|
|
130
|
-
cell[0] + ((i >> 0) & 1),
|
|
131
|
-
cell[1] + ((i >> 1) & 1),
|
|
132
|
-
cell[2] + ((i >> 2) & 1),
|
|
133
|
-
];
|
|
134
|
-
const key = vertex.join(',');
|
|
135
|
-
expect(grid.has(key)).toBe(true);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
it('should handle point at cell center', () => {
|
|
139
|
-
const grid = (0, grid_1.generateGradientGrid)(3, [5, 5, 5], 123);
|
|
140
|
-
const point = [1.5, 1.5, 1.5]; // Center of cell [1, 1, 1]
|
|
141
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
142
|
-
expect(scalarValues).toHaveLength(8);
|
|
143
|
-
// All distance vectors should have components of ±0.5
|
|
144
|
-
expect(scalarValues.every(val => typeof val === 'number')).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('higher dimensions', () => {
|
|
148
|
-
it('should return 16 scalar values for a point in 4D (16 vertices)', () => {
|
|
149
|
-
const grid = (0, grid_1.generateGradientGrid)(4, [3, 3, 3, 3], 123);
|
|
150
|
-
const point = [1.0, 1.0, 1.0, 1.0]; // Point in cell [1, 1, 1, 1]
|
|
151
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
152
|
-
expect(scalarValues).toHaveLength(16); // 2^4 = 16 vertices
|
|
153
|
-
});
|
|
154
|
-
it('should return 32 scalar values for a point in 5D (32 vertices)', () => {
|
|
155
|
-
const grid = (0, grid_1.generateGradientGrid)(5, [2, 2, 2, 2, 2], 123);
|
|
156
|
-
const point = [1.0, 1.0, 1.0, 1.0, 1.0]; // Point in cell [1, 1, 1, 1, 1]
|
|
157
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
158
|
-
expect(scalarValues).toHaveLength(32); // 2^5 = 32 vertices
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe('edge cases', () => {
|
|
162
|
-
it('should handle point at origin', () => {
|
|
163
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
164
|
-
const point = [0.0, 0.0]; // Cell [0, 0]
|
|
165
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
166
|
-
expect(scalarValues).toHaveLength(4);
|
|
167
|
-
expect(grid.has('0,0')).toBe(true);
|
|
168
|
-
expect(grid.has('0,1')).toBe(true);
|
|
169
|
-
expect(grid.has('1,0')).toBe(true);
|
|
170
|
-
expect(grid.has('1,1')).toBe(true);
|
|
171
|
-
});
|
|
172
|
-
it('should handle very small coordinates', () => {
|
|
173
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
174
|
-
const point = [0.0001, 0.0001]; // Cell [0, 0]
|
|
175
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
176
|
-
expect(scalarValues).toHaveLength(4);
|
|
177
|
-
});
|
|
178
|
-
it('should handle large coordinates within bounds', () => {
|
|
179
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [10, 10], 123);
|
|
180
|
-
const point = [9.9, 9.9]; // Cell [9, 9], should have vertices at [9,9], [9,10], [10,9], [10,10]
|
|
181
|
-
const scalarValues = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
182
|
-
expect(scalarValues).toHaveLength(4);
|
|
183
|
-
// Grid size is 10, so vertices go up to 10
|
|
184
|
-
expect(grid.has('9,9')).toBe(true);
|
|
185
|
-
expect(grid.has('9,10')).toBe(true);
|
|
186
|
-
expect(grid.has('10,9')).toBe(true);
|
|
187
|
-
expect(grid.has('10,10')).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
it('should produce consistent results for same point', () => {
|
|
190
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
191
|
-
const point = [2.5, 3.2];
|
|
192
|
-
const scalarValues1 = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
193
|
-
const scalarValues2 = (0, scalar_1.calculateScalarValues)(grid, point);
|
|
194
|
-
expect(scalarValues1).toHaveLength(scalarValues2.length);
|
|
195
|
-
for (let i = 0; i < scalarValues1.length; i++) {
|
|
196
|
-
expect(scalarValues1[i]).toBeCloseTo(scalarValues2[i], 10);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
it('should produce different results for different points', () => {
|
|
200
|
-
const grid = (0, grid_1.generateGradientGrid)(2, [5, 5], 123);
|
|
201
|
-
const point1 = [1.0, 1.0];
|
|
202
|
-
const point2 = [2.0, 2.0];
|
|
203
|
-
const scalarValues1 = (0, scalar_1.calculateScalarValues)(grid, point1);
|
|
204
|
-
const scalarValues2 = (0, scalar_1.calculateScalarValues)(grid, point2);
|
|
205
|
-
// They might have some same values, but at least one should be different
|
|
206
|
-
expect(scalarValues1).toHaveLength(4);
|
|
207
|
-
expect(scalarValues2).toHaveLength(4);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|