circuit-to-canvas 0.0.57 → 0.0.58
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.d.ts +4 -1
- package/dist/index.js +27 -4
- package/lib/drawer/elements/pcb-silkscreen-circle.ts +2 -1
- package/lib/drawer/shapes/circle.ts +34 -4
- package/package.json +1 -1
- package/tests/elements/__snapshots__/pcb-silkscreen-circle.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-silkscreen-on-component.snap.png +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -115,8 +115,11 @@ interface DrawCircleParams {
|
|
|
115
115
|
y: number;
|
|
116
116
|
};
|
|
117
117
|
radius: number;
|
|
118
|
-
fill
|
|
118
|
+
fill?: string;
|
|
119
119
|
realToCanvasMat: Matrix;
|
|
120
|
+
stroke?: string;
|
|
121
|
+
strokeWidth?: number;
|
|
122
|
+
isStrokeDashed?: boolean;
|
|
120
123
|
}
|
|
121
124
|
declare function drawCircle(params: DrawCircleParams): void;
|
|
122
125
|
|
package/dist/index.js
CHANGED
|
@@ -642,13 +642,35 @@ function drawPcbCopperText(params) {
|
|
|
642
642
|
// lib/drawer/shapes/circle.ts
|
|
643
643
|
import { applyToPoint as applyToPoint7 } from "transformation-matrix";
|
|
644
644
|
function drawCircle(params) {
|
|
645
|
-
const {
|
|
645
|
+
const {
|
|
646
|
+
ctx,
|
|
647
|
+
center,
|
|
648
|
+
radius,
|
|
649
|
+
fill,
|
|
650
|
+
realToCanvasMat,
|
|
651
|
+
stroke,
|
|
652
|
+
strokeWidth,
|
|
653
|
+
isStrokeDashed = false
|
|
654
|
+
} = params;
|
|
646
655
|
const [cx, cy] = applyToPoint7(realToCanvasMat, [center.x, center.y]);
|
|
647
656
|
const scaledRadius = radius * Math.abs(realToCanvasMat.a);
|
|
657
|
+
const scaledStrokeWidth = strokeWidth ? strokeWidth * Math.abs(realToCanvasMat.a) : void 0;
|
|
648
658
|
ctx.beginPath();
|
|
649
659
|
ctx.arc(cx, cy, scaledRadius, 0, Math.PI * 2);
|
|
650
|
-
|
|
651
|
-
|
|
660
|
+
if (fill) {
|
|
661
|
+
ctx.fillStyle = fill;
|
|
662
|
+
ctx.fill();
|
|
663
|
+
}
|
|
664
|
+
if (stroke && scaledStrokeWidth) {
|
|
665
|
+
if (isStrokeDashed) {
|
|
666
|
+
ctx.setLineDash([scaledStrokeWidth * 3, scaledStrokeWidth * 2]);
|
|
667
|
+
} else {
|
|
668
|
+
ctx.setLineDash([]);
|
|
669
|
+
}
|
|
670
|
+
ctx.strokeStyle = stroke;
|
|
671
|
+
ctx.lineWidth = scaledStrokeWidth;
|
|
672
|
+
ctx.stroke();
|
|
673
|
+
}
|
|
652
674
|
}
|
|
653
675
|
|
|
654
676
|
// lib/drawer/elements/pcb-cutout.ts
|
|
@@ -1850,7 +1872,8 @@ function drawPcbSilkscreenCircle(params) {
|
|
|
1850
1872
|
ctx,
|
|
1851
1873
|
center: circle.center,
|
|
1852
1874
|
radius: circle.radius,
|
|
1853
|
-
|
|
1875
|
+
stroke: color,
|
|
1876
|
+
strokeWidth: circle.stroke_width,
|
|
1854
1877
|
realToCanvasMat
|
|
1855
1878
|
});
|
|
1856
1879
|
}
|
|
@@ -6,18 +6,48 @@ export interface DrawCircleParams {
|
|
|
6
6
|
ctx: CanvasContext
|
|
7
7
|
center: { x: number; y: number }
|
|
8
8
|
radius: number
|
|
9
|
-
fill
|
|
9
|
+
fill?: string
|
|
10
10
|
realToCanvasMat: Matrix
|
|
11
|
+
stroke?: string
|
|
12
|
+
strokeWidth?: number
|
|
13
|
+
isStrokeDashed?: boolean
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export function drawCircle(params: DrawCircleParams): void {
|
|
14
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
ctx,
|
|
19
|
+
center,
|
|
20
|
+
radius,
|
|
21
|
+
fill,
|
|
22
|
+
realToCanvasMat,
|
|
23
|
+
stroke,
|
|
24
|
+
strokeWidth,
|
|
25
|
+
isStrokeDashed = false,
|
|
26
|
+
} = params
|
|
15
27
|
|
|
16
28
|
const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
|
|
17
29
|
const scaledRadius = radius * Math.abs(realToCanvasMat.a)
|
|
30
|
+
const scaledStrokeWidth = strokeWidth
|
|
31
|
+
? strokeWidth * Math.abs(realToCanvasMat.a)
|
|
32
|
+
: undefined
|
|
18
33
|
|
|
19
34
|
ctx.beginPath()
|
|
20
35
|
ctx.arc(cx, cy, scaledRadius, 0, Math.PI * 2)
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
|
|
37
|
+
if (fill) {
|
|
38
|
+
ctx.fillStyle = fill
|
|
39
|
+
ctx.fill()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (stroke && scaledStrokeWidth) {
|
|
43
|
+
// Set up dashed line if needed (after path is drawn, before stroke)
|
|
44
|
+
if (isStrokeDashed) {
|
|
45
|
+
ctx.setLineDash([scaledStrokeWidth * 3, scaledStrokeWidth * 2])
|
|
46
|
+
} else {
|
|
47
|
+
ctx.setLineDash([])
|
|
48
|
+
}
|
|
49
|
+
ctx.strokeStyle = stroke
|
|
50
|
+
ctx.lineWidth = scaledStrokeWidth
|
|
51
|
+
ctx.stroke()
|
|
52
|
+
}
|
|
23
53
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|