circuit-to-canvas 0.0.97 → 0.0.99

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/dist/index.js CHANGED
@@ -209,10 +209,6 @@ function drawPolygon(params) {
209
209
  function layerToColor(layer, colorMap) {
210
210
  return colorMap.copper[layer] ?? colorMap.copper.top;
211
211
  }
212
- function layerToPourOpacity(layer) {
213
- if (layer === "top" || layer === "bottom") return 0.5;
214
- return 1;
215
- }
216
212
  function computeArcFromBulge(startX, startY, endX, endY, bulge) {
217
213
  if (Math.abs(bulge) < 1e-10) {
218
214
  return null;
@@ -338,7 +334,7 @@ function drawRing(ctx, ring, realToCanvasMat) {
338
334
  function drawPcbCopperPour(params) {
339
335
  const { ctx, pour, realToCanvasMat, colorMap } = params;
340
336
  const color = layerToColor(pour.layer, colorMap);
341
- const opacity = layerToPourOpacity(pour.layer);
337
+ const opacity = 0.5;
342
338
  ctx.save();
343
339
  ctx.globalAlpha = opacity;
344
340
  if (pour.shape === "rect") {
@@ -20,11 +20,6 @@ function layerToColor(layer: string, colorMap: PcbColorMap): string {
20
20
  )
21
21
  }
22
22
 
23
- function layerToPourOpacity(layer: string): number {
24
- if (layer === "top" || layer === "bottom") return 0.5
25
- return 1
26
- }
27
-
28
23
  /**
29
24
  * Compute arc center and radius from two points and a bulge value.
30
25
  * Bulge is the tangent of 1/4 of the included angle.
@@ -242,7 +237,7 @@ export function drawPcbCopperPour(params: DrawPcbCopperPourParams): void {
242
237
  const { ctx, pour, realToCanvasMat, colorMap } = params
243
238
 
244
239
  const color = layerToColor(pour.layer, colorMap)
245
- const opacity = layerToPourOpacity(pour.layer)
240
+ const opacity = 0.5
246
241
 
247
242
  // Save context to apply opacity
248
243
  ctx.save()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-canvas",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",
@@ -0,0 +1,92 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { AnyCircuitElement } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ function renderCopperPourScene(elements: AnyCircuitElement[]): Buffer {
7
+ const canvas = createCanvas(100, 100)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 100, 100)
13
+
14
+ drawer.drawElements(elements)
15
+
16
+ return canvas.toBuffer("image/png")
17
+ }
18
+
19
+ const INNER_LAYERS = [
20
+ "inner1",
21
+ "inner2",
22
+ "inner3",
23
+ "inner4",
24
+ "inner5",
25
+ "inner6",
26
+ ] as const
27
+
28
+ function createCopperPourWithTraceScene(
29
+ layer: (typeof INNER_LAYERS)[number],
30
+ ): AnyCircuitElement[] {
31
+ return [
32
+ {
33
+ type: "pcb_copper_pour" as const,
34
+ pcb_copper_pour_id: `pour_${layer}`,
35
+ shape: "polygon" as const,
36
+ layer,
37
+ points: [
38
+ { x: 10, y: 10 },
39
+ { x: 90, y: 10 },
40
+ { x: 90, y: 90 },
41
+ { x: 10, y: 90 },
42
+ ],
43
+ covered_with_solder_mask: false,
44
+ },
45
+ {
46
+ type: "pcb_trace" as const,
47
+ pcb_trace_id: `trace_${layer}`,
48
+ route: [
49
+ {
50
+ route_type: "wire" as const,
51
+ x: 20,
52
+ y: 50,
53
+ width: 5,
54
+ layer,
55
+ },
56
+ {
57
+ route_type: "wire" as const,
58
+ x: 80,
59
+ y: 50,
60
+ width: 5,
61
+ layer,
62
+ },
63
+ ],
64
+ },
65
+ {
66
+ type: "pcb_via" as const,
67
+ pcb_via_id: `via_${layer}`,
68
+ x: 50,
69
+ y: 50,
70
+ outer_diameter: 15,
71
+ hole_diameter: 8,
72
+ layers: ["top", ...INNER_LAYERS, "bottom"],
73
+ },
74
+ ]
75
+ }
76
+
77
+ for (const layer of INNER_LAYERS) {
78
+ test(`draw ${layer} copper pour with trace`, async () => {
79
+ const elements = createCopperPourWithTraceScene(layer)
80
+
81
+ const withTrace = renderCopperPourScene(elements)
82
+ const withoutTrace = renderCopperPourScene(
83
+ elements.filter((element) => element.type !== "pcb_trace"),
84
+ )
85
+
86
+ expect(Buffer.compare(withTrace, withoutTrace)).not.toBe(0)
87
+ await expect(withTrace).toMatchPngSnapshot(
88
+ import.meta.path,
89
+ `${layer}-copper-pour-with-trace`,
90
+ )
91
+ })
92
+ }