@tscircuit/copper-pour-solver 0.0.5 → 0.0.6
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 +2 -2
- package/dist/index.js +15 -15
- package/lib/circuit-json/convert-circuit-json-to-input-problem.ts +2 -2
- package/lib/solvers/CopperPourPipelineSolver.ts +1 -1
- package/lib/solvers/copper-pour/get-board-polygon.ts +5 -5
- package/lib/solvers/copper-pour/process-obstacles.ts +14 -10
- package/lib/types.ts +1 -1
- package/package.json +1 -1
- package/tests/board-edge-margin-2.test.ts +1 -1
- package/tests/board-edge-margin.test.ts +1 -1
- package/tests/utils/run-solver-and-render-to-svg.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface InputPourRegion {
|
|
|
10
10
|
connectivityKey: string;
|
|
11
11
|
padMargin: number;
|
|
12
12
|
traceMargin: number;
|
|
13
|
-
|
|
13
|
+
board_edge_margin?: number;
|
|
14
14
|
}
|
|
15
15
|
interface BaseInputPad {
|
|
16
16
|
padId: string;
|
|
@@ -53,7 +53,7 @@ declare const convertCircuitJsonToInputProblem: (circuitJson: AnyCircuitElement[
|
|
|
53
53
|
pour_connectivity_key: string;
|
|
54
54
|
pad_margin: number;
|
|
55
55
|
trace_margin: number;
|
|
56
|
-
|
|
56
|
+
board_edge_margin?: number;
|
|
57
57
|
}) => InputProblem;
|
|
58
58
|
|
|
59
59
|
export { type BaseInputPad, CopperPourPipelineSolver, type InputCircularPad, type InputPad, type InputPourRegion, type InputProblem, type InputRectPad, type InputTracePad, type PipelineOutput, convertCircuitJsonToInputProblem };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { BasePipelineSolver } from "@tscircuit/solver-utils";
|
|
|
4
4
|
// lib/solvers/copper-pour/get-board-polygon.ts
|
|
5
5
|
import Flatten from "@flatten-js/core";
|
|
6
6
|
var getBoardPolygon = (region) => {
|
|
7
|
-
const
|
|
7
|
+
const board_edge_margin = region.board_edge_margin ?? 0;
|
|
8
8
|
if (region.outline && region.outline.length > 0) {
|
|
9
9
|
const polygon = new Flatten.Polygon(
|
|
10
10
|
region.outline.map((p) => Flatten.point(p.x, p.y))
|
|
@@ -13,10 +13,10 @@ var getBoardPolygon = (region) => {
|
|
|
13
13
|
}
|
|
14
14
|
const { bounds } = region;
|
|
15
15
|
const newBounds = {
|
|
16
|
-
minX: bounds.minX +
|
|
17
|
-
minY: bounds.minY +
|
|
18
|
-
maxX: bounds.maxX -
|
|
19
|
-
maxY: bounds.maxY -
|
|
16
|
+
minX: bounds.minX + board_edge_margin,
|
|
17
|
+
minY: bounds.minY + board_edge_margin,
|
|
18
|
+
maxX: bounds.maxX - board_edge_margin,
|
|
19
|
+
maxY: bounds.maxY - board_edge_margin
|
|
20
20
|
};
|
|
21
21
|
if (newBounds.minX >= newBounds.maxX || newBounds.minY >= newBounds.maxY) {
|
|
22
22
|
return new Flatten.Polygon();
|
|
@@ -59,8 +59,8 @@ var isTracePad = (pad) => pad.shape === "trace";
|
|
|
59
59
|
var isCircularPad = (pad) => pad.shape === "circle";
|
|
60
60
|
var processObstaclesForPour = (pads, pourConnectivityKey, margins, boardOutline) => {
|
|
61
61
|
const polygonsToSubtract = [];
|
|
62
|
-
const { padMargin, traceMargin,
|
|
63
|
-
if (boardOutline && boardOutline.length > 0 &&
|
|
62
|
+
const { padMargin, traceMargin, board_edge_margin } = margins;
|
|
63
|
+
if (boardOutline && boardOutline.length > 0 && board_edge_margin && board_edge_margin > 0) {
|
|
64
64
|
const boardPoly = new Flatten3.Polygon(
|
|
65
65
|
boardOutline.map((p) => Flatten3.point(p.x, p.y))
|
|
66
66
|
);
|
|
@@ -76,14 +76,14 @@ var processObstaclesForPour = (pads, pourConnectivityKey, margins, boardOutline)
|
|
|
76
76
|
const v1 = new Flatten3.Vector(p1, p2);
|
|
77
77
|
const v2 = new Flatten3.Vector(p2, p3);
|
|
78
78
|
const crossProduct = v1.cross(v2);
|
|
79
|
-
const circle = new Flatten3.Circle(p2,
|
|
79
|
+
const circle = new Flatten3.Circle(p2, board_edge_margin);
|
|
80
80
|
polygonsToSubtract.push(circleToPolygon(circle));
|
|
81
81
|
if (crossProduct < 0) {
|
|
82
82
|
const box = new Flatten3.Box(
|
|
83
|
-
p2.x -
|
|
84
|
-
p2.y -
|
|
85
|
-
p2.x +
|
|
86
|
-
p2.y +
|
|
83
|
+
p2.x - board_edge_margin,
|
|
84
|
+
p2.y - board_edge_margin,
|
|
85
|
+
p2.x + board_edge_margin,
|
|
86
|
+
p2.y + board_edge_margin
|
|
87
87
|
);
|
|
88
88
|
polygonsToSubtract.push(new Flatten3.Polygon(box.toPoints()));
|
|
89
89
|
}
|
|
@@ -94,7 +94,7 @@ var processObstaclesForPour = (pads, pourConnectivityKey, margins, boardOutline)
|
|
|
94
94
|
if (!p1 || !p2) continue;
|
|
95
95
|
const segmentLength = Math.hypot(p1.x - p2.x, p1.y - p2.y);
|
|
96
96
|
if (segmentLength === 0) continue;
|
|
97
|
-
const enlargedWidth =
|
|
97
|
+
const enlargedWidth = board_edge_margin * 2;
|
|
98
98
|
const centerX = (p1.x + p2.x) / 2;
|
|
99
99
|
const centerY = (p1.y + p2.y) / 2;
|
|
100
100
|
const rotationDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
|
|
@@ -254,7 +254,7 @@ var CopperPourPipelineSolver = class extends BasePipelineSolver {
|
|
|
254
254
|
{
|
|
255
255
|
padMargin: region.padMargin,
|
|
256
256
|
traceMargin: region.traceMargin,
|
|
257
|
-
|
|
257
|
+
board_edge_margin: region.board_edge_margin
|
|
258
258
|
},
|
|
259
259
|
region.outline
|
|
260
260
|
);
|
|
@@ -435,7 +435,7 @@ var convertCircuitJsonToInputProblem = (circuitJson, options) => {
|
|
|
435
435
|
connectivityKey: options.pour_connectivity_key,
|
|
436
436
|
padMargin: options.pad_margin,
|
|
437
437
|
traceMargin: options.trace_margin,
|
|
438
|
-
|
|
438
|
+
board_edge_margin: options.board_edge_margin ?? 0
|
|
439
439
|
}
|
|
440
440
|
];
|
|
441
441
|
return {
|
|
@@ -26,7 +26,7 @@ export const convertCircuitJsonToInputProblem = (
|
|
|
26
26
|
pour_connectivity_key: string
|
|
27
27
|
pad_margin: number
|
|
28
28
|
trace_margin: number
|
|
29
|
-
|
|
29
|
+
board_edge_margin?: number
|
|
30
30
|
},
|
|
31
31
|
): InputProblem => {
|
|
32
32
|
const source_ports = circuitJson.filter(
|
|
@@ -199,7 +199,7 @@ export const convertCircuitJsonToInputProblem = (
|
|
|
199
199
|
connectivityKey: options.pour_connectivity_key,
|
|
200
200
|
padMargin: options.pad_margin,
|
|
201
201
|
traceMargin: options.trace_margin,
|
|
202
|
-
|
|
202
|
+
board_edge_margin: options.board_edge_margin ?? 0,
|
|
203
203
|
},
|
|
204
204
|
]
|
|
205
205
|
|
|
@@ -28,7 +28,7 @@ export class CopperPourPipelineSolver extends BasePipelineSolver<InputProblem> {
|
|
|
28
28
|
{
|
|
29
29
|
padMargin: region.padMargin,
|
|
30
30
|
traceMargin: region.traceMargin,
|
|
31
|
-
|
|
31
|
+
board_edge_margin: region.board_edge_margin,
|
|
32
32
|
},
|
|
33
33
|
region.outline,
|
|
34
34
|
)
|
|
@@ -2,7 +2,7 @@ import type { InputPourRegion } from "lib/types"
|
|
|
2
2
|
import Flatten from "@flatten-js/core"
|
|
3
3
|
|
|
4
4
|
export const getBoardPolygon = (region: InputPourRegion): Flatten.Polygon => {
|
|
5
|
-
const
|
|
5
|
+
const board_edge_margin = region.board_edge_margin ?? 0
|
|
6
6
|
|
|
7
7
|
if (region.outline && region.outline.length > 0) {
|
|
8
8
|
const polygon = new Flatten.Polygon(
|
|
@@ -13,10 +13,10 @@ export const getBoardPolygon = (region: InputPourRegion): Flatten.Polygon => {
|
|
|
13
13
|
|
|
14
14
|
const { bounds } = region
|
|
15
15
|
const newBounds = {
|
|
16
|
-
minX: bounds.minX +
|
|
17
|
-
minY: bounds.minY +
|
|
18
|
-
maxX: bounds.maxX -
|
|
19
|
-
maxY: bounds.maxY -
|
|
16
|
+
minX: bounds.minX + board_edge_margin,
|
|
17
|
+
minY: bounds.minY + board_edge_margin,
|
|
18
|
+
maxX: bounds.maxX - board_edge_margin,
|
|
19
|
+
maxY: bounds.maxY - board_edge_margin,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (newBounds.minX >= newBounds.maxX || newBounds.minY >= newBounds.maxY) {
|
|
@@ -21,18 +21,22 @@ const isCircularPad = (pad: InputPad): pad is InputCircularPad =>
|
|
|
21
21
|
export const processObstaclesForPour = (
|
|
22
22
|
pads: InputPad[],
|
|
23
23
|
pourConnectivityKey: string,
|
|
24
|
-
margins: {
|
|
24
|
+
margins: {
|
|
25
|
+
padMargin: number
|
|
26
|
+
traceMargin: number
|
|
27
|
+
board_edge_margin?: number
|
|
28
|
+
},
|
|
25
29
|
boardOutline?: Point[],
|
|
26
30
|
): ProcessedObstacles => {
|
|
27
31
|
const polygonsToSubtract: Flatten.Polygon[] = []
|
|
28
32
|
|
|
29
|
-
const { padMargin, traceMargin,
|
|
33
|
+
const { padMargin, traceMargin, board_edge_margin } = margins
|
|
30
34
|
|
|
31
35
|
if (
|
|
32
36
|
boardOutline &&
|
|
33
37
|
boardOutline.length > 0 &&
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
board_edge_margin &&
|
|
39
|
+
board_edge_margin > 0
|
|
36
40
|
) {
|
|
37
41
|
const boardPoly = new Flatten.Polygon(
|
|
38
42
|
boardOutline.map((p) => Flatten.point(p.x, p.y)),
|
|
@@ -54,15 +58,15 @@ export const processObstaclesForPour = (
|
|
|
54
58
|
const v2 = new Flatten.Vector(p2, p3)
|
|
55
59
|
const crossProduct = v1.cross(v2)
|
|
56
60
|
|
|
57
|
-
const circle = new Flatten.Circle(p2,
|
|
61
|
+
const circle = new Flatten.Circle(p2, board_edge_margin)
|
|
58
62
|
polygonsToSubtract.push(circleToPolygon(circle))
|
|
59
63
|
|
|
60
64
|
if (crossProduct < 0) {
|
|
61
65
|
const box = new Flatten.Box(
|
|
62
|
-
p2.x -
|
|
63
|
-
p2.y -
|
|
64
|
-
p2.x +
|
|
65
|
-
p2.y +
|
|
66
|
+
p2.x - board_edge_margin,
|
|
67
|
+
p2.y - board_edge_margin,
|
|
68
|
+
p2.x + board_edge_margin,
|
|
69
|
+
p2.y + board_edge_margin,
|
|
66
70
|
)
|
|
67
71
|
polygonsToSubtract.push(new Flatten.Polygon(box.toPoints()))
|
|
68
72
|
}
|
|
@@ -78,7 +82,7 @@ export const processObstaclesForPour = (
|
|
|
78
82
|
const segmentLength = Math.hypot(p1.x - p2.x, p1.y - p2.y)
|
|
79
83
|
if (segmentLength === 0) continue
|
|
80
84
|
|
|
81
|
-
const enlargedWidth =
|
|
85
|
+
const enlargedWidth = board_edge_margin * 2
|
|
82
86
|
|
|
83
87
|
const centerX = (p1.x + p2.x) / 2
|
|
84
88
|
const centerY = (p1.y + p2.y) / 2
|
package/lib/types.ts
CHANGED
package/package.json
CHANGED