37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
/**
|
|
* applyBooleanOp — 존재하지 않는 출력 폴더로 cut해도 폴더를 만들고 성공해야 한다
|
|
*
|
|
* 사건(2026-09-30): 임시 .scad를 출력 폴더에 쓰는데 그 폴더를 만들기 전에 써서 ENOENT로 죽었다
|
|
* (3018 집진 슈 시험 조각을 새 폴더로 자를 때). OpenSCAD가 없는 환경에서는 건너뛴다.
|
|
*/
|
|
import { test, describe } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'fs';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
import { applyBooleanOp, readStlBBox, OPENSCAD_BIN } from '../src/tools/stl-cad-core';
|
|
|
|
function cubeStl(size: number): Buffer {
|
|
// 12개 삼각형짜리 정육면체(바이너리 STL)
|
|
const v = [[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]].map((p) => p.map((c) => c * size));
|
|
const f = [[0,2,1],[0,3,2],[4,5,6],[4,6,7],[0,1,5],[0,5,4],[1,2,6],[1,6,5],[2,3,7],[2,7,6],[3,0,4],[3,4,7]];
|
|
const b = Buffer.alloc(84 + f.length * 50);
|
|
b.writeUInt32LE(f.length, 80);
|
|
let off = 84;
|
|
for (const t of f) { off += 12; for (const i of t) for (const c of v[i]) { b.writeFloatLE(c, off); off += 4; } off += 2; }
|
|
return b;
|
|
}
|
|
|
|
describe('applyBooleanOp — 새 출력 폴더', { skip: !fs.existsSync(OPENSCAD_BIN) }, () => {
|
|
test('없는 하위 폴더로 cut해도 폴더를 만들고 결과를 쓴다', async () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cutnew-'));
|
|
const src = path.join(dir, 'cube.stl');
|
|
fs.writeFileSync(src, cubeStl(10));
|
|
const out = path.join(dir, '새 폴더', '하위', 'cut.stl');
|
|
const r = await applyBooleanOp({ primaryPath: src, outPath: out, op: 'cut', x: 5, y: 5, z: 10, w: 40, h: 40, d: 10 } as any);
|
|
assert.equal(r.ok, true, r.ok ? '' : (r as any).detail);
|
|
const bb = readStlBBox(out);
|
|
assert.ok(bb.max[2] <= 5.01, `z 5 위쪽이 잘려야 함: ${bb.max[2]}`);
|
|
});
|
|
});
|