-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shapes.html
More file actions
478 lines (425 loc) · 14.9 KB
/
test_shapes.html
File metadata and controls
478 lines (425 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<!DOCTYPE html>
<html>
<head>
<title>Core Shapes Test</title>
<style>
body { font-family: monospace; padding: 20px; background: #1e1e1e; color: #d4d4d4; }
#log { white-space: pre-wrap; line-height: 1.5; }
.pass { color: #4ec9b0; }
.fail { color: #f14c4c; }
.info { color: #569cd6; }
a { color: #569cd6; display: block; margin: 5px 0; }
</style>
</head>
<body>
<h1>Core Shapes Test</h1>
<div id="log"></div>
<div id="downloads"></div>
<script type="module">
import opencascade from 'replicad-opencascadejs/src/replicad_single.js';
import opencascadeWasm from 'replicad-opencascadejs/src/replicad_single.wasm?url';
import { setOC } from 'replicad';
import * as replicadModule from 'replicad';
import { ReplicadBuilder, exportToSTL, exportToMesh } from './src/replicadBuilder.js';
import { getShapeBuilder, getCore, getSupportedFamilies } from './src/coreShapes.js';
import { flattenDimensions } from './src/types.js';
// Scale factor for export (meters to mm)
const SCALE = 1000;
const logDiv = document.getElementById('log');
const downloadsDiv = document.getElementById('downloads');
window.stlFiles = [];
function log(msg, className = '') {
const span = document.createElement('span');
span.className = className;
span.textContent = msg + '\n';
logDiv.appendChild(span);
console.log(msg);
}
function addDownload(filename, blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.textContent = `Download ${filename}`;
downloadsDiv.appendChild(a);
window.stlFiles.push({ filename, blob });
}
// Test shape data for each family
const testShapes = {
t: {
name: "T 22/14/13",
family: "t",
familySubtype: "1",
dimensions: { A: 0.0220, B: 0.0140, C: 0.0130 }
},
e: {
name: "E 25/13/7",
family: "e",
familySubtype: "1",
// Real E 25/13/7 dimensions from MAS data
dimensions: { A: 0.0251, B: 0.0126, C: 0.0072, D: 0.00895, E: 0.0179, F: 0.00725 }
},
etd: {
name: "ETD 29/16/10",
family: "etd",
familySubtype: "1",
dimensions: { A: 0.0290, B: 0.0160, C: 0.0100, D: 0.0100, E: 0.0210, F: 0.0100 }
},
er: {
name: "ER 28/14/11",
family: "er",
familySubtype: "1",
dimensions: { A: 0.0280, B: 0.0140, C: 0.0110, D: 0.0090, E: 0.0220, F: 0.0100, G: 0.0150 }
},
pq: {
name: "PQ 20/16",
family: "pq",
familySubtype: "1",
dimensions: { A: 0.0200, B: 0.0160, C: 0.0100, D: 0.0120, E: 0.0140, F: 0.0080, G: 0.0110 }
},
rm: {
name: "RM 10",
family: "rm",
familySubtype: "3",
dimensions: { A: 0.0270, B: 0.0093, C: 0.0130, D: 0.0065, E: 0.0210, F: 0.0100, G: 0.0100, H: 0.0055, J: 0.0240 }
},
p: {
name: "P 14/8",
family: "p",
familySubtype: "1",
dimensions: { A: 0.0140, B: 0.0080, C: 0.0070, D: 0.0055, E: 0.0110, F: 0.0055, G: 0.0040, H: 0.0030 }
},
c: {
name: "C Test",
family: "c",
familySubtype: "1",
dimensions: { A: 0.0200, B: 0.0120, C: 0.0080, D: 0.0070, E: 0.0100 }
},
u: {
name: "U Test",
family: "u",
familySubtype: "1",
dimensions: { A: 0.0200, B: 0.0120, C: 0.0080, D: 0.0070, E: 0.0100 }
},
ep: {
name: "EP 7",
family: "ep",
familySubtype: "1",
dimensions: { A: 0.0075, B: 0.0046, C: 0.0052, D: 0.0030, E: 0.0057, F: 0.0035, G: 0.0040, K: 0.0010 }
},
efd: {
name: "EFD 15/8/5",
family: "efd",
familySubtype: "1",
dimensions: { A: 0.0150, B: 0.0050, C: 0.0080, D: 0.0035, E: 0.0100, F: 0.0055, F2: 0.0035, K: 0.0010, q: 0.0005 }
},
ec: {
name: "EC 35",
family: "ec",
familySubtype: "1",
dimensions: { A: 0.0350, B: 0.0150, C: 0.0170, D: 0.0095, E: 0.0230, F: 0.0110, T: 0.0080, s: 0.0050 }
},
eq: {
name: "EQ 25",
family: "eq",
familySubtype: "1",
dimensions: { A: 0.0250, B: 0.0070, C: 0.0080, D: 0.0050, E: 0.0180, F: 0.0085, G: 0.0100 }
},
lp: {
name: "LP 22/13",
family: "lp",
familySubtype: "1",
dimensions: { A: 0.0220, B: 0.0050, C: 0.0130, D: 0.0030, E: 0.0160, F: 0.0070, G: 0.0100 }
},
pm: {
name: "PM 50/39",
family: "pm",
familySubtype: "1",
dimensions: { A: 0.0500, B: 0.0100, C: 0.0200, D: 0.0060, E: 0.0350, F: 0.0200, G: 0.0080, H: 0.0050, b: 0.0040, t: 0.0050, alpha: 120 }
}
};
// Test geometrical descriptions (simulating PyMKF output)
// MKF coordinates: {radial, height, depth}
// MKF uses:
// - Top piece: rotation = [π, π, 0], coordinates = {0, height, depth}
// - Bottom piece: rotation = [0, 0, 0], coordinates = {0, -height, depth}
// For a simple two-piece set with no spacer and single stack:
// - height = 0 (no spacer)
// - depth = 0 (first stack)
function createGeometricalDescription(shapeData) {
const isToroidal = shapeData.family === 't';
if (isToroidal) {
return [{
type: 'toroidal',
shape: shapeData,
coordinates: [0, 0, 0],
rotation: [0, 0, 0],
machining: null
}];
} else {
// Two-piece set: top and bottom halves (matching MKF format)
// MKF coordinates are [radial, height, depth]
// For no-spacer case, both pieces are at height=0
return [
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0], // MKF format: [radial, height, depth]
rotation: [Math.PI, Math.PI, 0], // Top piece rotates 180° around X and Y
machining: null
},
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0], // Same position, rotation differentiates them
rotation: [0, 0, 0],
machining: null
}
];
}
}
async function runTests() {
log('Initializing OpenCASCADE.js...', 'info');
log('Loading WASM (takes 10-20 seconds)...', 'info');
const oc = await opencascade({
locateFile: () => opencascadeWasm
});
setOC(oc);
log('✓ OpenCASCADE.js loaded!', 'pass');
// Get supported families
const supportedFamilies = getSupportedFamilies();
log(`Supported shape families: ${supportedFamilies.join(', ')}`, 'info');
let passed = 0;
let failed = 0;
const results = [];
log('\n========================================', 'info');
log('Shape Piece Tests', 'info');
log('========================================\n', 'info');
// Test each shape piece
for (const [family, shapeData] of Object.entries(testShapes)) {
const testName = `test_shape_${family}`;
log(`\n${testName}`);
try {
const builder = new ReplicadBuilder(replicadModule);
// Pass the replicad module to the shape builder
const shapeBuilder = getShapeBuilder(replicadModule, shapeData.family);
// Flatten dimensions and prepare data (dimensions are in meters)
const data = { ...shapeData };
data.dimensions = flattenDimensions(data);
// Build the piece (in meters)
let piece = shapeBuilder.getPiece(data);
// Scale from meters to mm for STL export
piece = piece.scale(SCALE);
// Generate STL using blobSTL method (as used in test_magnetic.html)
const stl = piece.blobSTL({ tolerance: 1.0, angularTolerance: 0.8, binary: true });
const blob = stl;
log(` STL size: ${stl.size} bytes`);
if (stl.size > 100) {
log(' ✓ PASSED', 'pass');
passed++;
addDownload(`shape_${family}.stl`, blob);
} else {
log(' ✗ FAILED: STL too small', 'fail');
failed++;
}
} catch (err) {
log(` ✗ FAILED: ${err.message}`, 'fail');
console.error(err);
failed++;
}
}
log('\n========================================', 'info');
log('Core Assembly Tests', 'info');
log('========================================\n', 'info');
// Test complete core assembly for a few shapes
const coreTestShapes = ['t', 'e', 'etd', 'rm', 'pq'];
for (const family of coreTestShapes) {
const testName = `test_core_${family}`;
log(`\n${testName}`);
try {
const shapeData = testShapes[family];
const geometricalDescription = createGeometricalDescription(shapeData);
const builder = new ReplicadBuilder(replicadModule);
// Pass the replicad module to getCore
const core = getCore(replicadModule, geometricalDescription);
if (core) {
// Generate STL using blobSTL method
const stl = core.blobSTL({ tolerance: 1.0, angularTolerance: 0.8, binary: true });
const blob = stl;
log(` STL size: ${stl.size} bytes`);
if (stl.size > 100) {
log(' ✓ PASSED', 'pass');
passed++;
addDownload(`core_${family}.stl`, blob);
} else {
log(' ✗ FAILED: STL too small', 'fail');
failed++;
}
} else {
log(' ✗ FAILED: Core is null', 'fail');
failed++;
}
} catch (err) {
log(` ✗ FAILED: ${err.message}`, 'fail');
console.error(err);
failed++;
}
}
log('\n========================================', 'info');
log('Gapped Core Tests (Central Gap)', 'info');
log('========================================\n', 'info');
// Test gapping with central column gap (subtractive gapping)
// Machining format: { coordinates: [radial, height, depth], length: gapLength }
// For central column: radial = 0
const centralGapTestShapes = ['e', 'etd', 'pq'];
for (const family of centralGapTestShapes) {
const testName = `test_gapped_core_central_${family}`;
log(`\n${testName}`);
try {
const shapeData = testShapes[family];
const gapLength = 0.001; // 1mm gap
// Create geometrical description with central column gap
// The gap is centered at height=0 (middle of core)
// Coordinates are [radial, height, depth]
const geometricalDescription = [
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0],
rotation: [Math.PI, Math.PI, 0],
// Machining for top half: gap at height = gapLength/2 (from the split plane)
machining: [{
coordinates: [0, gapLength / 2, 0], // [radial=0 for central, height, depth]
length: gapLength / 2 // Half the gap in each piece
}]
},
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0],
rotation: [0, 0, 0],
// Machining for bottom half: gap at height = -gapLength/2
machining: [{
coordinates: [0, -gapLength / 2, 0],
length: gapLength / 2
}]
}
];
const core = getCore(replicadModule, geometricalDescription);
if (core) {
const stl = core.blobSTL({ tolerance: 1.0, angularTolerance: 0.8, binary: true });
const blob = stl;
log(` STL size: ${stl.size} bytes`);
if (stl.size > 100) {
log(' ✓ PASSED', 'pass');
passed++;
addDownload(`gapped_central_${family}.stl`, blob);
} else {
log(' ✗ FAILED: STL too small', 'fail');
failed++;
}
} else {
log(' ✗ FAILED: Core is null', 'fail');
failed++;
}
} catch (err) {
log(` ✗ FAILED: ${err.message}`, 'fail');
console.error(err);
failed++;
}
}
log('\n========================================', 'info');
log('Gapped Core Tests (Distributed Gap)', 'info');
log('========================================\n', 'info');
// Test distributed gapping (gaps on lateral columns)
// Machining format: { coordinates: [radial, height, depth], length: gapLength }
// For lateral columns: radial = ±(distance from center)
const distributedGapTestShapes = ['e', 'etd'];
for (const family of distributedGapTestShapes) {
const testName = `test_gapped_core_distributed_${family}`;
log(`\n${testName}`);
try {
const shapeData = testShapes[family];
const dims = flattenDimensions(shapeData);
const gapLength = 0.0005; // 0.5mm gap per column
// Distance to lateral columns (approximately E/2 or half of winding window width)
const lateralDistance = dims.E / 2;
// Create geometrical description with distributed gaps
const geometricalDescription = [
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0],
rotation: [Math.PI, Math.PI, 0],
// Machining for top half: gaps on both lateral columns
machining: [
{
coordinates: [lateralDistance, gapLength / 2, 0], // Right lateral column
length: gapLength / 2
},
{
coordinates: [-lateralDistance, gapLength / 2, 0], // Left lateral column
length: gapLength / 2
}
]
},
{
type: 'half set',
shape: shapeData,
coordinates: [0, 0, 0],
rotation: [0, 0, 0],
// Machining for bottom half
machining: [
{
coordinates: [lateralDistance, -gapLength / 2, 0],
length: gapLength / 2
},
{
coordinates: [-lateralDistance, -gapLength / 2, 0],
length: gapLength / 2
}
]
}
];
const core = getCore(replicadModule, geometricalDescription);
if (core) {
const stl = core.blobSTL({ tolerance: 1.0, angularTolerance: 0.8, binary: true });
const blob = stl;
log(` STL size: ${stl.size} bytes`);
if (stl.size > 100) {
log(' ✓ PASSED', 'pass');
passed++;
addDownload(`gapped_distributed_${family}.stl`, blob);
} else {
log(' ✗ FAILED: STL too small', 'fail');
failed++;
}
} else {
log(' ✗ FAILED: Core is null', 'fail');
failed++;
}
} catch (err) {
log(` ✗ FAILED: ${err.message}`, 'fail');
console.error(err);
failed++;
}
}
log('\n========================================', 'info');
log('Test Summary', 'info');
log('========================================', 'info');
log(`Total: ${passed + failed}, Passed: ${passed}, Failed: ${failed}`);
if (failed === 0) {
log('✓ All tests PASSED!', 'pass');
} else {
log(`✗ ${failed} tests FAILED!`, 'fail');
}
window.testsDone = true;
}
runTests().catch(err => {
log('FATAL ERROR: ' + err.message, 'fail');
console.error(err);
window.testsDone = true;
});
</script>
</body>
</html>