import { build } from 'esbuild' const bundled = await build({ bundle: true, stdin: { contents: "export { fieldFalloff, vortexAcceleration } from './src/core/particleMath.ts'", resolveDir: process.cwd(), sourcefile: 'vortex-test-entry.ts', }, format: 'esm', platform: 'node', write: false, }) const source = bundled.outputFiles[0].text const api = await import(`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`) if (api.fieldFalloff('constant', 50, 100) !== 1) throw new Error('恒定衰减计算错误') if (api.fieldFalloff('linear', 50, 100) !== 0.5) throw new Error('线性衰减计算错误') if (api.fieldFalloff('inverse', 5, 100) !== 10) throw new Error('距离反比衰减计算错误') if (api.fieldFalloff('constant', 101, 100) !== 0) throw new Error('漩涡范围外不应有力') const counterclockwise = api.vortexAcceleration(10, 0, 0, 0, 2, 100, 'constant') if (counterclockwise.x !== 0 || counterclockwise.y !== 20) throw new Error('正强度应产生逆时针切向力') const clockwise = api.vortexAcceleration(10, 0, 0, 0, -2, 100, 'constant') if (clockwise.x !== 0 || clockwise.y !== -20) throw new Error('负强度应产生顺时针切向力') console.log('漩涡力方向、半径与三种衰减模式校验通过')