circuit-to-canvas 0.0.64 → 0.0.65

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
@@ -687,6 +687,21 @@ function drawPcbCourtyardCircle(params) {
687
687
  });
688
688
  }
689
689
 
690
+ // lib/drawer/elements/pcb-courtyard-rect.ts
691
+ function drawPcbCourtyardRect(params) {
692
+ const { ctx, rect, realToCanvasMat, colorMap } = params;
693
+ drawRect({
694
+ ctx,
695
+ center: rect.center,
696
+ width: rect.width,
697
+ height: rect.height,
698
+ stroke: colorMap.courtyard,
699
+ strokeWidth: 0.05,
700
+ // Default thin line for courtyard info
701
+ realToCanvasMat
702
+ });
703
+ }
704
+
690
705
  // lib/drawer/elements/pcb-cutout.ts
691
706
  function drawPcbCutout(params) {
692
707
  const { ctx, cutout, realToCanvasMat, colorMap } = params;
@@ -3679,6 +3694,14 @@ var CircuitToCanvasDrawer = class {
3679
3694
  colorMap: this.colorMap
3680
3695
  });
3681
3696
  }
3697
+ if (element.type === "pcb_courtyard_rect") {
3698
+ drawPcbCourtyardRect({
3699
+ ctx: this.ctx,
3700
+ rect: element,
3701
+ realToCanvasMat: this.realToCanvasMat,
3702
+ colorMap: this.colorMap
3703
+ });
3704
+ }
3682
3705
  }
3683
3706
  }
3684
3707
  };
@@ -5,6 +5,7 @@ import type {
5
5
  PcbCopperPour,
6
6
  PcbCopperText,
7
7
  PcbCourtyardCircle,
8
+ PcbCourtyardRect,
8
9
  PcbCutout,
9
10
  PcbFabricationNoteDimension,
10
11
  PcbFabricationNotePath,
@@ -42,6 +43,7 @@ import { drawPcbBoard } from "./elements/pcb-board"
42
43
  import { drawPcbCopperPour } from "./elements/pcb-copper-pour"
43
44
  import { drawPcbCopperText } from "./elements/pcb-copper-text"
44
45
  import { drawPcbCourtyardCircle } from "./elements/pcb-courtyard-circle"
46
+ import { drawPcbCourtyardRect } from "./elements/pcb-courtyard-rect"
45
47
  import { drawPcbCutout } from "./elements/pcb-cutout"
46
48
  import { drawPcbFabricationNoteDimension } from "./elements/pcb-fabrication-note-dimension"
47
49
  import { drawPcbFabricationNotePath } from "./elements/pcb-fabrication-note-path"
@@ -501,6 +503,15 @@ export class CircuitToCanvasDrawer {
501
503
  colorMap: this.colorMap,
502
504
  })
503
505
  }
506
+
507
+ if (element.type === "pcb_courtyard_rect") {
508
+ drawPcbCourtyardRect({
509
+ ctx: this.ctx,
510
+ rect: element as PcbCourtyardRect,
511
+ realToCanvasMat: this.realToCanvasMat,
512
+ colorMap: this.colorMap,
513
+ })
514
+ }
504
515
  }
505
516
  }
506
517
  }
@@ -0,0 +1,25 @@
1
+ import type { PcbCourtyardRect } from "circuit-json"
2
+ import type { Matrix } from "transformation-matrix"
3
+ import type { PcbColorMap, CanvasContext } from "../types"
4
+ import { drawRect } from "../shapes/rect"
5
+
6
+ export interface DrawPcbCourtyardRectParams {
7
+ ctx: CanvasContext
8
+ rect: PcbCourtyardRect
9
+ realToCanvasMat: Matrix
10
+ colorMap: PcbColorMap
11
+ }
12
+
13
+ export function drawPcbCourtyardRect(params: DrawPcbCourtyardRectParams): void {
14
+ const { ctx, rect, realToCanvasMat, colorMap } = params
15
+
16
+ drawRect({
17
+ ctx,
18
+ center: rect.center,
19
+ width: rect.width,
20
+ height: rect.height,
21
+ stroke: colorMap.courtyard,
22
+ strokeWidth: 0.05, // Default thin line for courtyard info
23
+ realToCanvasMat,
24
+ })
25
+ }
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.64",
4
+ "version": "0.0.65",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",
@@ -0,0 +1,46 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import type { PcbCourtyardRect } from "circuit-json"
4
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
5
+
6
+ test("draw courtyard rect", async () => {
7
+ const canvas = createCanvas(1000, 1000)
8
+ const ctx = canvas.getContext("2d")
9
+ const drawer = new CircuitToCanvasDrawer(ctx)
10
+
11
+ ctx.fillStyle = "#1a1a1a"
12
+ ctx.fillRect(0, 0, 1000, 1000)
13
+
14
+ const rect1: PcbCourtyardRect = {
15
+ type: "pcb_courtyard_rect",
16
+ pcb_courtyard_rect_id: "courtyard_rect1",
17
+ pcb_component_id: "component1",
18
+ layer: "top",
19
+ center: { x: 0, y: 0 },
20
+ width: 4,
21
+ height: 2,
22
+ }
23
+
24
+ const rect2: PcbCourtyardRect = {
25
+ type: "pcb_courtyard_rect",
26
+ pcb_courtyard_rect_id: "courtyard_rect2",
27
+ pcb_component_id: "component2",
28
+ layer: "bottom",
29
+ center: { x: 3, y: 3 },
30
+ width: 2,
31
+ height: 4,
32
+ }
33
+
34
+ drawer.setCameraBounds({
35
+ minX: -5,
36
+ maxX: 5,
37
+ minY: -5,
38
+ maxY: 5,
39
+ })
40
+
41
+ drawer.drawElements([rect1, rect2])
42
+
43
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
44
+ import.meta.path,
45
+ )
46
+ })