verify-eda-layout-webgl.mjs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { existsSync } from 'node:fs'
  2. import { dirname, resolve } from 'node:path'
  3. import { fileURLToPath, pathToFileURL } from 'node:url'
  4. const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
  5. const distEntry = resolve(root, 'packages/renderers/eda-layout/dist/index.js')
  6. function assert(condition, message) {
  7. if (!condition) {
  8. throw new Error(message)
  9. }
  10. }
  11. assert(
  12. existsSync(distEntry),
  13. 'packages/renderers/eda-layout/dist/index.js is missing; run pnpm --filter @file-viewer/eda-layout build first.'
  14. )
  15. const { createEdaLayoutWebglBatch } = await import(`${pathToFileURL(distEntry).href}?t=${Date.now()}`)
  16. const batch = createEdaLayoutWebglBatch({
  17. format: 'gdsii',
  18. libraryName: 'smoke',
  19. structureCount: 1,
  20. structures: ['TOP'],
  21. bounds: { minX: 0, minY: 0, maxX: 100, maxY: 100 },
  22. warnings: [],
  23. elements: [
  24. {
  25. kind: 'boundary',
  26. structure: 'TOP',
  27. layer: 1,
  28. xy: [
  29. { x: 0, y: 0 },
  30. { x: 100, y: 0 },
  31. { x: 100, y: 100 },
  32. { x: 0, y: 100 },
  33. { x: 0, y: 0 }
  34. ]
  35. },
  36. {
  37. kind: 'path',
  38. structure: 'TOP',
  39. layer: 2,
  40. xy: [
  41. { x: 10, y: 10 },
  42. { x: 90, y: 90 }
  43. ]
  44. },
  45. {
  46. kind: 'text',
  47. structure: 'TOP',
  48. layer: 3,
  49. text: 'LABEL',
  50. xy: [{ x: 50, y: 50 }]
  51. }
  52. ]
  53. })
  54. assert(batch.format === 'gdsii', 'WebGL batch should keep the GDSII format marker.')
  55. assert(batch.triangleVertices instanceof Float32Array, 'triangleVertices must be a Float32Array.')
  56. assert(batch.lineVertices instanceof Float32Array, 'lineVertices must be a Float32Array.')
  57. assert(batch.pointVertices instanceof Float32Array, 'pointVertices must be a Float32Array.')
  58. assert(batch.triangleVertices.length === 30, `expected two polygon triangles, got ${batch.triangleVertices.length} floats.`)
  59. assert(batch.lineVertices.length >= 50, `expected boundary/path line vertices, got ${batch.lineVertices.length} floats.`)
  60. assert(batch.pointVertices.length === 5, `expected one label anchor point, got ${batch.pointVertices.length} floats.`)
  61. assert(batch.labels.length === 1 && batch.labels[0].text === 'LABEL', 'expected one text label in the WebGL overlay.')
  62. console.log('[eda-layout-webgl] Verified GDSII WebGL triangle, line, point, and label batches.')