circuit-to-canvas 0.0.14 → 0.0.15

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.
Files changed (34) hide show
  1. package/dist/index.d.ts +29 -29
  2. package/dist/index.js +157 -138
  3. package/lib/drawer/CircuitToCanvasDrawer.ts +21 -21
  4. package/lib/drawer/elements/pcb-board.ts +5 -5
  5. package/lib/drawer/elements/pcb-copper-pour.ts +13 -10
  6. package/lib/drawer/elements/pcb-copper-text.ts +4 -4
  7. package/lib/drawer/elements/pcb-cutout.ts +5 -5
  8. package/lib/drawer/elements/pcb-fabrication-note-path.ts +3 -3
  9. package/lib/drawer/elements/pcb-fabrication-note-rect.ts +3 -3
  10. package/lib/drawer/elements/pcb-fabrication-note-text.ts +4 -4
  11. package/lib/drawer/elements/pcb-hole.ts +8 -8
  12. package/lib/drawer/elements/pcb-note-line.ts +5 -5
  13. package/lib/drawer/elements/pcb-note-path.ts +3 -3
  14. package/lib/drawer/elements/pcb-note-rect.ts +3 -3
  15. package/lib/drawer/elements/pcb-note-text.ts +4 -4
  16. package/lib/drawer/elements/pcb-plated-hole.ts +14 -14
  17. package/lib/drawer/elements/pcb-silkscreen.ts +16 -16
  18. package/lib/drawer/elements/pcb-smtpad.ts +8 -8
  19. package/lib/drawer/elements/pcb-trace.ts +3 -3
  20. package/lib/drawer/elements/pcb-via.ts +4 -4
  21. package/lib/drawer/shapes/circle.ts +4 -4
  22. package/lib/drawer/shapes/line.ts +5 -5
  23. package/lib/drawer/shapes/oval.ts +13 -5
  24. package/lib/drawer/shapes/path.ts +8 -8
  25. package/lib/drawer/shapes/pill.ts +13 -5
  26. package/lib/drawer/shapes/polygon.ts +7 -7
  27. package/lib/drawer/shapes/rect.ts +7 -7
  28. package/lib/drawer/shapes/text.ts +5 -5
  29. package/lib/drawer/types.ts +1 -1
  30. package/package.json +1 -1
  31. package/tests/shapes/circle.test.ts +1 -1
  32. package/tests/shapes/oval.test.ts +1 -1
  33. package/tests/shapes/pill.test.ts +2 -2
  34. package/tests/shapes/rect.test.ts +2 -2
@@ -9,12 +9,12 @@ import { drawPill } from "../shapes/pill"
9
9
  export interface DrawPcbPlatedHoleParams {
10
10
  ctx: CanvasContext
11
11
  hole: PcbPlatedHole
12
- transform: Matrix
12
+ realToCanvasMat: Matrix
13
13
  colorMap: PcbColorMap
14
14
  }
15
15
 
16
16
  export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
17
- const { ctx, hole, transform, colorMap } = params
17
+ const { ctx, hole, realToCanvasMat, colorMap } = params
18
18
 
19
19
  if (hole.shape === "circle") {
20
20
  // Draw outer copper ring
@@ -23,7 +23,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
23
23
  center: { x: hole.x, y: hole.y },
24
24
  radius: hole.outer_diameter / 2,
25
25
  fill: colorMap.copper.top,
26
- transform,
26
+ realToCanvasMat,
27
27
  })
28
28
 
29
29
  // Draw inner drill hole
@@ -32,7 +32,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
32
32
  center: { x: hole.x, y: hole.y },
33
33
  radius: hole.hole_diameter / 2,
34
34
  fill: colorMap.drill,
35
- transform,
35
+ realToCanvasMat,
36
36
  })
37
37
  return
38
38
  }
@@ -45,7 +45,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
45
45
  width: hole.outer_width,
46
46
  height: hole.outer_height,
47
47
  fill: colorMap.copper.top,
48
- transform,
48
+ realToCanvasMat,
49
49
  rotation: hole.ccw_rotation,
50
50
  })
51
51
 
@@ -56,7 +56,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
56
56
  width: hole.hole_width,
57
57
  height: hole.hole_height,
58
58
  fill: colorMap.drill,
59
- transform,
59
+ realToCanvasMat,
60
60
  rotation: hole.ccw_rotation,
61
61
  })
62
62
  return
@@ -70,7 +70,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
70
70
  width: hole.outer_width,
71
71
  height: hole.outer_height,
72
72
  fill: colorMap.copper.top,
73
- transform,
73
+ realToCanvasMat,
74
74
  rotation: hole.ccw_rotation,
75
75
  })
76
76
 
@@ -81,7 +81,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
81
81
  width: hole.hole_width,
82
82
  height: hole.hole_height,
83
83
  fill: colorMap.drill,
84
- transform,
84
+ realToCanvasMat,
85
85
  rotation: hole.ccw_rotation,
86
86
  })
87
87
  return
@@ -95,7 +95,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
95
95
  width: hole.rect_pad_width,
96
96
  height: hole.rect_pad_height,
97
97
  fill: colorMap.copper.top,
98
- transform,
98
+ realToCanvasMat,
99
99
  borderRadius: (hole as any).rect_border_radius ?? 0,
100
100
  })
101
101
 
@@ -107,7 +107,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
107
107
  center: { x: holeX, y: holeY },
108
108
  radius: hole.hole_diameter / 2,
109
109
  fill: colorMap.drill,
110
- transform,
110
+ realToCanvasMat,
111
111
  })
112
112
  return
113
113
  }
@@ -120,7 +120,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
120
120
  width: hole.rect_pad_width,
121
121
  height: hole.rect_pad_height,
122
122
  fill: colorMap.copper.top,
123
- transform,
123
+ realToCanvasMat,
124
124
  borderRadius: (hole as any).rect_border_radius ?? 0,
125
125
  })
126
126
 
@@ -133,7 +133,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
133
133
  width: hole.hole_width,
134
134
  height: hole.hole_height,
135
135
  fill: colorMap.drill,
136
- transform,
136
+ realToCanvasMat,
137
137
  })
138
138
  return
139
139
  }
@@ -146,7 +146,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
146
146
  width: hole.rect_pad_width,
147
147
  height: hole.rect_pad_height,
148
148
  fill: colorMap.copper.top,
149
- transform,
149
+ realToCanvasMat,
150
150
  borderRadius: (hole as any).rect_border_radius ?? 0,
151
151
  rotation: hole.rect_ccw_rotation,
152
152
  })
@@ -160,7 +160,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
160
160
  width: hole.hole_width,
161
161
  height: hole.hole_height,
162
162
  fill: colorMap.drill,
163
- transform,
163
+ realToCanvasMat,
164
164
  rotation: hole.hole_ccw_rotation,
165
165
  })
166
166
  return
@@ -16,35 +16,35 @@ import { drawPath } from "../shapes/path"
16
16
  export interface DrawPcbSilkscreenTextParams {
17
17
  ctx: CanvasContext
18
18
  text: PcbSilkscreenText
19
- transform: Matrix
19
+ realToCanvasMat: Matrix
20
20
  colorMap: PcbColorMap
21
21
  }
22
22
 
23
23
  export interface DrawPcbSilkscreenRectParams {
24
24
  ctx: CanvasContext
25
25
  rect: PcbSilkscreenRect
26
- transform: Matrix
26
+ realToCanvasMat: Matrix
27
27
  colorMap: PcbColorMap
28
28
  }
29
29
 
30
30
  export interface DrawPcbSilkscreenCircleParams {
31
31
  ctx: CanvasContext
32
32
  circle: PcbSilkscreenCircle
33
- transform: Matrix
33
+ realToCanvasMat: Matrix
34
34
  colorMap: PcbColorMap
35
35
  }
36
36
 
37
37
  export interface DrawPcbSilkscreenLineParams {
38
38
  ctx: CanvasContext
39
39
  line: PcbSilkscreenLine
40
- transform: Matrix
40
+ realToCanvasMat: Matrix
41
41
  colorMap: PcbColorMap
42
42
  }
43
43
 
44
44
  export interface DrawPcbSilkscreenPathParams {
45
45
  ctx: CanvasContext
46
46
  path: PcbSilkscreenPath
47
- transform: Matrix
47
+ realToCanvasMat: Matrix
48
48
  colorMap: PcbColorMap
49
49
  }
50
50
 
@@ -66,15 +66,15 @@ function mapAnchorAlignment(
66
66
  export function drawPcbSilkscreenText(
67
67
  params: DrawPcbSilkscreenTextParams,
68
68
  ): void {
69
- const { ctx, text, transform, colorMap } = params
69
+ const { ctx, text, realToCanvasMat, colorMap } = params
70
70
 
71
71
  const color = layerToSilkscreenColor(text.layer, colorMap)
72
- const [x, y] = applyToPoint(transform, [
72
+ const [x, y] = applyToPoint(realToCanvasMat, [
73
73
  text.anchor_position.x,
74
74
  text.anchor_position.y,
75
75
  ])
76
76
 
77
- const fontSize = (text.font_size ?? 1) * Math.abs(transform.a)
77
+ const fontSize = (text.font_size ?? 1) * Math.abs(realToCanvasMat.a)
78
78
  const rotation = text.ccw_rotation ?? 0
79
79
 
80
80
  ctx.save()
@@ -95,7 +95,7 @@ export function drawPcbSilkscreenText(
95
95
  export function drawPcbSilkscreenRect(
96
96
  params: DrawPcbSilkscreenRectParams,
97
97
  ): void {
98
- const { ctx, rect, transform, colorMap } = params
98
+ const { ctx, rect, realToCanvasMat, colorMap } = params
99
99
 
100
100
  const color = layerToSilkscreenColor(rect.layer, colorMap)
101
101
 
@@ -105,14 +105,14 @@ export function drawPcbSilkscreenRect(
105
105
  width: rect.width,
106
106
  height: rect.height,
107
107
  fill: color,
108
- transform,
108
+ realToCanvasMat,
109
109
  })
110
110
  }
111
111
 
112
112
  export function drawPcbSilkscreenCircle(
113
113
  params: DrawPcbSilkscreenCircleParams,
114
114
  ): void {
115
- const { ctx, circle, transform, colorMap } = params
115
+ const { ctx, circle, realToCanvasMat, colorMap } = params
116
116
 
117
117
  const color = layerToSilkscreenColor(circle.layer, colorMap)
118
118
 
@@ -121,14 +121,14 @@ export function drawPcbSilkscreenCircle(
121
121
  center: circle.center,
122
122
  radius: circle.radius,
123
123
  fill: color,
124
- transform,
124
+ realToCanvasMat,
125
125
  })
126
126
  }
127
127
 
128
128
  export function drawPcbSilkscreenLine(
129
129
  params: DrawPcbSilkscreenLineParams,
130
130
  ): void {
131
- const { ctx, line, transform, colorMap } = params
131
+ const { ctx, line, realToCanvasMat, colorMap } = params
132
132
 
133
133
  const color = layerToSilkscreenColor(line.layer, colorMap)
134
134
 
@@ -138,14 +138,14 @@ export function drawPcbSilkscreenLine(
138
138
  end: { x: line.x2, y: line.y2 },
139
139
  strokeWidth: line.stroke_width ?? 0.1,
140
140
  stroke: color,
141
- transform,
141
+ realToCanvasMat,
142
142
  })
143
143
  }
144
144
 
145
145
  export function drawPcbSilkscreenPath(
146
146
  params: DrawPcbSilkscreenPathParams,
147
147
  ): void {
148
- const { ctx, path, transform, colorMap } = params
148
+ const { ctx, path, realToCanvasMat, colorMap } = params
149
149
 
150
150
  const color = layerToSilkscreenColor(path.layer, colorMap)
151
151
 
@@ -164,7 +164,7 @@ export function drawPcbSilkscreenPath(
164
164
  end: { x: end.x, y: end.y },
165
165
  strokeWidth: path.stroke_width ?? 0.1,
166
166
  stroke: color,
167
- transform,
167
+ realToCanvasMat,
168
168
  })
169
169
  }
170
170
  }
@@ -9,7 +9,7 @@ import { drawPolygon } from "../shapes/polygon"
9
9
  export interface DrawPcbSmtPadParams {
10
10
  ctx: CanvasContext
11
11
  pad: PcbSmtPad
12
- transform: Matrix
12
+ realToCanvasMat: Matrix
13
13
  colorMap: PcbColorMap
14
14
  }
15
15
 
@@ -21,7 +21,7 @@ function layerToColor(layer: string, colorMap: PcbColorMap): string {
21
21
  }
22
22
 
23
23
  export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
24
- const { ctx, pad, transform, colorMap } = params
24
+ const { ctx, pad, realToCanvasMat, colorMap } = params
25
25
 
26
26
  const color = layerToColor(pad.layer, colorMap)
27
27
 
@@ -32,7 +32,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
32
32
  width: pad.width,
33
33
  height: pad.height,
34
34
  fill: color,
35
- transform,
35
+ realToCanvasMat,
36
36
  borderRadius:
37
37
  (pad as { corner_radius?: number }).corner_radius ??
38
38
  pad.rect_border_radius ??
@@ -48,7 +48,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
48
48
  width: pad.width,
49
49
  height: pad.height,
50
50
  fill: color,
51
- transform,
51
+ realToCanvasMat,
52
52
  borderRadius:
53
53
  (pad as { corner_radius?: number }).corner_radius ??
54
54
  pad.rect_border_radius ??
@@ -64,7 +64,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
64
64
  center: { x: pad.x, y: pad.y },
65
65
  radius: pad.radius,
66
66
  fill: color,
67
- transform,
67
+ realToCanvasMat,
68
68
  })
69
69
  return
70
70
  }
@@ -76,7 +76,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
76
76
  width: pad.width,
77
77
  height: pad.height,
78
78
  fill: color,
79
- transform,
79
+ realToCanvasMat,
80
80
  })
81
81
  return
82
82
  }
@@ -88,7 +88,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
88
88
  width: pad.width,
89
89
  height: pad.height,
90
90
  fill: color,
91
- transform,
91
+ realToCanvasMat,
92
92
  rotation: pad.ccw_rotation ?? 0,
93
93
  })
94
94
  return
@@ -100,7 +100,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
100
100
  ctx,
101
101
  points: pad.points,
102
102
  fill: color,
103
- transform,
103
+ realToCanvasMat,
104
104
  })
105
105
  }
106
106
  return
@@ -6,7 +6,7 @@ import { drawLine } from "../shapes/line"
6
6
  export interface DrawPcbTraceParams {
7
7
  ctx: CanvasContext
8
8
  trace: PCBTrace
9
- transform: Matrix
9
+ realToCanvasMat: Matrix
10
10
  colorMap: PcbColorMap
11
11
  }
12
12
 
@@ -18,7 +18,7 @@ function layerToColor(layer: string, colorMap: PcbColorMap): string {
18
18
  }
19
19
 
20
20
  export function drawPcbTrace(params: DrawPcbTraceParams): void {
21
- const { ctx, trace, transform, colorMap } = params
21
+ const { ctx, trace, realToCanvasMat, colorMap } = params
22
22
 
23
23
  if (!trace.route || !Array.isArray(trace.route) || trace.route.length < 2) {
24
24
  return
@@ -52,7 +52,7 @@ export function drawPcbTrace(params: DrawPcbTraceParams): void {
52
52
  end: { x: end.x, y: end.y },
53
53
  strokeWidth: traceWidth,
54
54
  stroke: color,
55
- transform,
55
+ realToCanvasMat,
56
56
  lineCap: "round",
57
57
  })
58
58
  }
@@ -6,12 +6,12 @@ import { drawCircle } from "../shapes/circle"
6
6
  export interface DrawPcbViaParams {
7
7
  ctx: CanvasContext
8
8
  via: PCBVia
9
- transform: Matrix
9
+ realToCanvasMat: Matrix
10
10
  colorMap: PcbColorMap
11
11
  }
12
12
 
13
13
  export function drawPcbVia(params: DrawPcbViaParams): void {
14
- const { ctx, via, transform, colorMap } = params
14
+ const { ctx, via, realToCanvasMat, colorMap } = params
15
15
 
16
16
  // Draw outer copper ring
17
17
  drawCircle({
@@ -19,7 +19,7 @@ export function drawPcbVia(params: DrawPcbViaParams): void {
19
19
  center: { x: via.x, y: via.y },
20
20
  radius: via.outer_diameter / 2,
21
21
  fill: colorMap.copper.top,
22
- transform,
22
+ realToCanvasMat,
23
23
  })
24
24
 
25
25
  // Draw inner drill hole
@@ -28,6 +28,6 @@ export function drawPcbVia(params: DrawPcbViaParams): void {
28
28
  center: { x: via.x, y: via.y },
29
29
  radius: via.hole_diameter / 2,
30
30
  fill: colorMap.drill,
31
- transform,
31
+ realToCanvasMat,
32
32
  })
33
33
  }
@@ -7,14 +7,14 @@ export interface DrawCircleParams {
7
7
  center: { x: number; y: number }
8
8
  radius: number
9
9
  fill: string
10
- transform: Matrix
10
+ realToCanvasMat: Matrix
11
11
  }
12
12
 
13
13
  export function drawCircle(params: DrawCircleParams): void {
14
- const { ctx, center, radius, fill, transform } = params
14
+ const { ctx, center, radius, fill, realToCanvasMat } = params
15
15
 
16
- const [cx, cy] = applyToPoint(transform, [center.x, center.y])
17
- const scaledRadius = radius * Math.abs(transform.a)
16
+ const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
17
+ const scaledRadius = radius * Math.abs(realToCanvasMat.a)
18
18
 
19
19
  ctx.beginPath()
20
20
  ctx.arc(cx, cy, scaledRadius, 0, Math.PI * 2)
@@ -8,7 +8,7 @@ export interface DrawLineParams {
8
8
  end: { x: number; y: number }
9
9
  strokeWidth: number
10
10
  stroke: string
11
- transform: Matrix
11
+ realToCanvasMat: Matrix
12
12
  lineCap?: "butt" | "round" | "square"
13
13
  }
14
14
 
@@ -19,13 +19,13 @@ export function drawLine(params: DrawLineParams): void {
19
19
  end,
20
20
  strokeWidth,
21
21
  stroke,
22
- transform,
22
+ realToCanvasMat,
23
23
  lineCap = "round",
24
24
  } = params
25
25
 
26
- const [x1, y1] = applyToPoint(transform, [start.x, start.y])
27
- const [x2, y2] = applyToPoint(transform, [end.x, end.y])
28
- const scaledStrokeWidth = strokeWidth * Math.abs(transform.a)
26
+ const [x1, y1] = applyToPoint(realToCanvasMat, [start.x, start.y])
27
+ const [x2, y2] = applyToPoint(realToCanvasMat, [end.x, end.y])
28
+ const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a)
29
29
 
30
30
  ctx.beginPath()
31
31
  ctx.moveTo(x1, y1)
@@ -8,16 +8,24 @@ export interface DrawOvalParams {
8
8
  width: number
9
9
  height: number
10
10
  fill: string
11
- transform: Matrix
11
+ realToCanvasMat: Matrix
12
12
  rotation?: number
13
13
  }
14
14
 
15
15
  export function drawOval(params: DrawOvalParams): void {
16
- const { ctx, center, width, height, fill, transform, rotation = 0 } = params
16
+ const {
17
+ ctx,
18
+ center,
19
+ width,
20
+ height,
21
+ fill,
22
+ realToCanvasMat,
23
+ rotation = 0,
24
+ } = params
17
25
 
18
- const [cx, cy] = applyToPoint(transform, [center.x, center.y])
19
- const scaledWidth = width * Math.abs(transform.a)
20
- const scaledHeight = height * Math.abs(transform.a)
26
+ const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
27
+ const scaledWidth = width * Math.abs(realToCanvasMat.a)
28
+ const scaledHeight = height * Math.abs(realToCanvasMat.a)
21
29
 
22
30
  ctx.save()
23
31
  ctx.translate(cx, cy)
@@ -8,7 +8,7 @@ export interface DrawPathParams {
8
8
  fill?: string
9
9
  stroke?: string
10
10
  strokeWidth?: number
11
- transform: Matrix
11
+ realToCanvasMat: Matrix
12
12
  closePath?: boolean
13
13
  }
14
14
 
@@ -19,7 +19,7 @@ export function drawPath(params: DrawPathParams): void {
19
19
  fill,
20
20
  stroke,
21
21
  strokeWidth = 1,
22
- transform,
22
+ realToCanvasMat,
23
23
  closePath = false,
24
24
  } = params
25
25
 
@@ -27,17 +27,17 @@ export function drawPath(params: DrawPathParams): void {
27
27
 
28
28
  ctx.beginPath()
29
29
 
30
- const transformedPoints = points.map((p) =>
31
- applyToPoint(transform, [p.x, p.y]),
30
+ const canvasPoints = points.map((p) =>
31
+ applyToPoint(realToCanvasMat, [p.x, p.y]),
32
32
  )
33
33
 
34
- const firstPoint = transformedPoints[0]
34
+ const firstPoint = canvasPoints[0]
35
35
  if (!firstPoint) return
36
36
  const [firstX, firstY] = firstPoint
37
37
  ctx.moveTo(firstX, firstY)
38
38
 
39
- for (let i = 1; i < transformedPoints.length; i++) {
40
- const point = transformedPoints[i]
39
+ for (let i = 1; i < canvasPoints.length; i++) {
40
+ const point = canvasPoints[i]
41
41
  if (!point) continue
42
42
  const [x, y] = point
43
43
  ctx.lineTo(x, y)
@@ -53,7 +53,7 @@ export function drawPath(params: DrawPathParams): void {
53
53
  }
54
54
 
55
55
  if (stroke) {
56
- const scaledStrokeWidth = strokeWidth * Math.abs(transform.a)
56
+ const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a)
57
57
  ctx.strokeStyle = stroke
58
58
  ctx.lineWidth = scaledStrokeWidth
59
59
  ctx.stroke()
@@ -8,16 +8,24 @@ export interface DrawPillParams {
8
8
  width: number
9
9
  height: number
10
10
  fill: string
11
- transform: Matrix
11
+ realToCanvasMat: Matrix
12
12
  rotation?: number
13
13
  }
14
14
 
15
15
  export function drawPill(params: DrawPillParams): void {
16
- const { ctx, center, width, height, fill, transform, rotation = 0 } = params
16
+ const {
17
+ ctx,
18
+ center,
19
+ width,
20
+ height,
21
+ fill,
22
+ realToCanvasMat,
23
+ rotation = 0,
24
+ } = params
17
25
 
18
- const [cx, cy] = applyToPoint(transform, [center.x, center.y])
19
- const scaledWidth = width * Math.abs(transform.a)
20
- const scaledHeight = height * Math.abs(transform.a)
26
+ const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
27
+ const scaledWidth = width * Math.abs(realToCanvasMat.a)
28
+ const scaledHeight = height * Math.abs(realToCanvasMat.a)
21
29
 
22
30
  ctx.save()
23
31
  ctx.translate(cx, cy)
@@ -6,27 +6,27 @@ export interface DrawPolygonParams {
6
6
  ctx: CanvasContext
7
7
  points: Array<{ x: number; y: number }>
8
8
  fill: string
9
- transform: Matrix
9
+ realToCanvasMat: Matrix
10
10
  }
11
11
 
12
12
  export function drawPolygon(params: DrawPolygonParams): void {
13
- const { ctx, points, fill, transform } = params
13
+ const { ctx, points, fill, realToCanvasMat } = params
14
14
 
15
15
  if (points.length < 3) return
16
16
 
17
17
  ctx.beginPath()
18
18
 
19
- const transformedPoints = points.map((p) =>
20
- applyToPoint(transform, [p.x, p.y]),
19
+ const canvasPoints = points.map((p) =>
20
+ applyToPoint(realToCanvasMat, [p.x, p.y]),
21
21
  )
22
22
 
23
- const firstPoint = transformedPoints[0]
23
+ const firstPoint = canvasPoints[0]
24
24
  if (!firstPoint) return
25
25
  const [firstX, firstY] = firstPoint
26
26
  ctx.moveTo(firstX, firstY)
27
27
 
28
- for (let i = 1; i < transformedPoints.length; i++) {
29
- const point = transformedPoints[i]
28
+ for (let i = 1; i < canvasPoints.length; i++) {
29
+ const point = canvasPoints[i]
30
30
  if (!point) continue
31
31
  const [x, y] = point
32
32
  ctx.lineTo(x, y)
@@ -8,7 +8,7 @@ export interface DrawRectParams {
8
8
  width: number
9
9
  height: number
10
10
  fill?: string
11
- transform: Matrix
11
+ realToCanvasMat: Matrix
12
12
  borderRadius?: number
13
13
  rotation?: number
14
14
  stroke?: string
@@ -23,7 +23,7 @@ export function drawRect(params: DrawRectParams): void {
23
23
  width,
24
24
  height,
25
25
  fill,
26
- transform,
26
+ realToCanvasMat,
27
27
  borderRadius = 0,
28
28
  rotation = 0,
29
29
  stroke,
@@ -31,12 +31,12 @@ export function drawRect(params: DrawRectParams): void {
31
31
  isStrokeDashed = false,
32
32
  } = params
33
33
 
34
- const [cx, cy] = applyToPoint(transform, [center.x, center.y])
35
- const scaledWidth = width * Math.abs(transform.a)
36
- const scaledHeight = height * Math.abs(transform.a)
37
- const scaledRadius = borderRadius * Math.abs(transform.a)
34
+ const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
35
+ const scaledWidth = width * Math.abs(realToCanvasMat.a)
36
+ const scaledHeight = height * Math.abs(realToCanvasMat.a)
37
+ const scaledRadius = borderRadius * Math.abs(realToCanvasMat.a)
38
38
  const scaledStrokeWidth = strokeWidth
39
- ? strokeWidth * Math.abs(transform.a)
39
+ ? strokeWidth * Math.abs(realToCanvasMat.a)
40
40
  : undefined
41
41
 
42
42
  ctx.save()
@@ -153,7 +153,7 @@ export interface DrawTextParams {
153
153
  y: number
154
154
  fontSize: number
155
155
  color: string
156
- transform: Matrix
156
+ realToCanvasMat: Matrix
157
157
  anchorAlignment: AnchorAlignment
158
158
  rotation?: number
159
159
  }
@@ -166,21 +166,21 @@ export function drawText(params: DrawTextParams): void {
166
166
  y,
167
167
  fontSize,
168
168
  color,
169
- transform,
169
+ realToCanvasMat,
170
170
  anchorAlignment,
171
171
  rotation = 0,
172
172
  } = params
173
173
 
174
174
  if (!text) return
175
175
 
176
- const [transformedX, transformedY] = applyToPoint(transform, [x, y])
177
- const scale = Math.abs(transform.a)
176
+ const [canvasX, canvasY] = applyToPoint(realToCanvasMat, [x, y])
177
+ const scale = Math.abs(realToCanvasMat.a)
178
178
  const scaledFontSize = fontSize * scale
179
179
  const layout = getAlphabetLayout(text, scaledFontSize)
180
180
  const startPos = getTextStartPosition(anchorAlignment, layout)
181
181
 
182
182
  ctx.save()
183
- ctx.translate(transformedX, transformedY)
183
+ ctx.translate(canvasX, canvasY)
184
184
 
185
185
  if (rotation !== 0) {
186
186
  ctx.rotate(-rotation * (Math.PI / 180))
@@ -137,6 +137,6 @@ export interface CameraBounds {
137
137
 
138
138
  export interface DrawContext {
139
139
  ctx: CanvasRenderingContext2D
140
- transform: Matrix
140
+ realToCanvasMat: Matrix
141
141
  colorMap: PcbColorMap
142
142
  }
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.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",
@@ -15,7 +15,7 @@ test("draw circle", async () => {
15
15
  center: { x: 50, y: 50 },
16
16
  radius: 30,
17
17
  fill: "#ff0000",
18
- transform: identity(),
18
+ realToCanvasMat: identity(),
19
19
  })
20
20
 
21
21
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
@@ -16,7 +16,7 @@ test("draw oval", async () => {
16
16
  width: 70,
17
17
  height: 40,
18
18
  fill: "#0000ff",
19
- transform: identity(),
19
+ realToCanvasMat: identity(),
20
20
  })
21
21
 
22
22
  await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(