@tscircuit/circuit-json-util 0.0.113 → 0.0.115
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/README.md +35 -3
- package/dist/index.d.ts +28 -2
- package/dist/index.js +225 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -54,6 +54,38 @@ It reduces the amount of code to retrieve or join elements from circuit json, it
|
|
|
54
54
|
| `computeGapBetweenCopper` | [`lib/compute-gap-between-copper.ts`](./lib/compute-gap-between-copper.ts) | Computes the minimum copper-to-copper gap between two circuit elements by decomposing them into primitive shapes. |
|
|
55
55
|
| `analyzePcbPin1Location` | [`lib/analyze-pcb-pin1-location.ts`](./lib/analyze-pcb-pin1-location.ts) | Infers a semantic pin 1 location from PCB pad geometry and numeric port hints. |
|
|
56
56
|
| `categorizeErrorOrWarning` | [`lib/categorize-error-or-warning.ts`](./lib/categorize-error-or-warning.ts) | Categorizes DRC error/warning types into `"netlist"`, `"pin_specification"`, `"placement"`, `"routing"`, `"source"`, or `"unknown"`. |
|
|
57
|
+
| `getPourPolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Converts rectangular, polygon, or BRep pours into copper polygons, preserving cutouts and bulge arcs. |
|
|
58
|
+
| `getSmtPadPolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Converts SMT pad outlines into copper polygons. |
|
|
59
|
+
| `getPlatedHolePolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Converts plated pads into copper polygons with drilled holes excluded. |
|
|
60
|
+
| `getViaPolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Creates an annular copper polygon from a center and outer/hole diameters. |
|
|
61
|
+
| `getTraceSegmentPolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Creates the convex hull of two endpoint disks, with equal or differing widths. |
|
|
62
|
+
| `copperPolygonsTouch` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Tests polygon contact or containment while respecting holes. |
|
|
63
|
+
| `placePolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Rotates a polygon counterclockwise, then translates it to its board position. |
|
|
64
|
+
| `circlePolygon` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Creates a circular polygon with analytic arcs. |
|
|
65
|
+
| `roundedRectangle` | [`lib/copper-geometry.ts`](./lib/copper-geometry.ts) | Creates a positioned and optionally rotated rectangle with rounded corners. |
|
|
66
|
+
|
|
67
|
+
## Copper geometry
|
|
68
|
+
|
|
69
|
+
These helpers return `Polygon` objects from `@flatten-js/core`. Coordinates are
|
|
70
|
+
PCB board-world points in millimeters, with +X right, +Y up, and counterclockwise
|
|
71
|
+
rotation in degrees. Polygon plated-pad outlines are footprint-local offsets;
|
|
72
|
+
`getPlatedHolePolygon(pad, componentRotation)` places them in board coordinates
|
|
73
|
+
using the pad's rotation, or the supplied component rotation when omitted.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { copperPolygonsTouch, getPlatedHolePolygon, getPourPolygon } from "@tscircuit/circuit-json-util"
|
|
77
|
+
|
|
78
|
+
const touches = copperPolygonsTouch(
|
|
79
|
+
getPourPolygon(pour),
|
|
80
|
+
getPlatedHolePolygon(platedHole),
|
|
81
|
+
)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Callers must check net membership and shared copper layers themselves: these
|
|
85
|
+
helpers operate only on planar geometry. `copperPolygonsTouch` uses a default
|
|
86
|
+
numerical tolerance of `1e-7` mm, not a manufacturing clearance. If callers scale
|
|
87
|
+
the polygons, they must scale that tolerance by the same factor. The helpers do
|
|
88
|
+
not modify their circuit-json inputs or generate routes.
|
|
57
89
|
|
|
58
90
|
## Standard Usage
|
|
59
91
|
|
|
@@ -84,14 +116,14 @@ const source_traces = su(circuitJson).source_trace.list({
|
|
|
84
116
|
For large circuit json, the library provides an optimized version with indexing for faster lookups:
|
|
85
117
|
|
|
86
118
|
```ts
|
|
87
|
-
import {
|
|
119
|
+
import { cjuIndexed } from "@tscircuit/circuit-json-util"
|
|
88
120
|
|
|
89
121
|
const circuitJson = [
|
|
90
122
|
/* large soup with many elements */
|
|
91
123
|
]
|
|
92
124
|
|
|
93
125
|
// Configure the indexes you want to use
|
|
94
|
-
const indexedSu =
|
|
126
|
+
const indexedSu = cjuIndexed(circuitJson, {
|
|
95
127
|
indexConfig: {
|
|
96
128
|
byId: true, // Index by element ID for fast .get() operations
|
|
97
129
|
byType: true, // Index by element type for fast .list() operations
|
|
@@ -110,7 +142,7 @@ const subcircuitElements = indexedSu.source_component.list({
|
|
|
110
142
|
})
|
|
111
143
|
```
|
|
112
144
|
|
|
113
|
-
The indexed version
|
|
145
|
+
The indexed version supports root-level `insert`, `insertAll`, and `subtree` as well as table operations. Root inserts assign IDs, including when an input supplies an ID, just like `cju`. Subtrees preserve the indexing and validation options and have their own collection; existing element objects are shared with the parent. `list()` returns a new array, so sorting or splicing it cannot modify the store's type index. The elements in that array remain live objects.
|
|
114
146
|
|
|
115
147
|
|
|
116
148
|
## Categorize DRC Errors and Warnings
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as circuit_json from 'circuit-json';
|
|
2
|
-
import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbPin1Location } from 'circuit-json';
|
|
2
|
+
import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad } from 'circuit-json';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import { Matrix } from 'transformation-matrix';
|
|
5
5
|
import * as parsel from 'parsel-js';
|
|
6
6
|
import { FlexBoxOptions } from '@tscircuit/miniflex';
|
|
7
|
+
import { Polygon as Polygon$1 } from '@flatten-js/core';
|
|
7
8
|
|
|
8
9
|
type CircuitJsonElementInsertInput<CircuitElementType extends AnyCircuitElement["type"], CircuitElement extends {
|
|
9
10
|
type: CircuitElementType;
|
|
@@ -19470,4 +19471,29 @@ type DrcLike = {
|
|
|
19470
19471
|
};
|
|
19471
19472
|
declare const categorizeErrorOrWarning: (value: string | DrcLike) => DrcCategory;
|
|
19472
19473
|
|
|
19473
|
-
|
|
19474
|
+
/** All geometry here is PCB world space in mm: +X right, +Y up, right-handed.
|
|
19475
|
+
* Arguments are points (translation applies); rotations are CCW about +Z.
|
|
19476
|
+
* Curves remain analytic arcs, so small contacts do not depend on tessellation.
|
|
19477
|
+
*/
|
|
19478
|
+
declare const placePolygon: (polygon: Polygon$1, center: Point$2, degrees?: number) => Polygon$1;
|
|
19479
|
+
declare const circlePolygon: (center: Point$2, radius: number) => Polygon$1;
|
|
19480
|
+
declare const roundedRectangle: (center: Point$2, width: number, height: number, radius?: number, degrees?: number) => Polygon$1;
|
|
19481
|
+
declare const getPourPolygon: (pour: PcbCopperPour) => Polygon$1;
|
|
19482
|
+
declare const getSmtPadPolygon: (pad: PcbSmtPad) => Polygon$1;
|
|
19483
|
+
declare const getViaPolygon: (center: Point$2, outerDiameter: number, holeDiameter: number) => Polygon$1;
|
|
19484
|
+
/** Polygon plated-hole outlines are footprint-local offsets; all other pad
|
|
19485
|
+
* outlines and hole offsets use the emitted board-world dimensions/rotations.
|
|
19486
|
+
* The polygon placement matches PlatedHole.doInitialPcbComponentRender's local
|
|
19487
|
+
* pad_outline convention, with the owning component's rotation when omitted.
|
|
19488
|
+
*/
|
|
19489
|
+
declare const getPlatedHolePolygon: (pad: PcbPlatedHole, componentRotation?: number) => Polygon$1;
|
|
19490
|
+
/** Copper for a straight trace segment in world mm, with round end caps.
|
|
19491
|
+
* Interpolated traces are the convex hull of their endpoint disks.
|
|
19492
|
+
*/
|
|
19493
|
+
declare const getTraceSegmentPolygon: (start: Point$2, end: Point$2, startWidth: number, endWidth?: number) => Polygon$1;
|
|
19494
|
+
/** Same-layer contact in board-world mm. Holes are excluded from containment.
|
|
19495
|
+
* 1e-7 mm is numerical tolerance, not an electrical/manufacturing clearance.
|
|
19496
|
+
*/
|
|
19497
|
+
declare const copperPolygonsTouch: (a: Polygon$1, b: Polygon$1, tolerance?: number) => boolean;
|
|
19498
|
+
|
|
19499
|
+
export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, copperPolygonsTouch, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
|
package/dist/index.js
CHANGED
|
@@ -401,6 +401,20 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
401
401
|
if (prop === "editCount") {
|
|
402
402
|
return internalStore.editCount;
|
|
403
403
|
}
|
|
404
|
+
if (prop === "insert") {
|
|
405
|
+
return (elm) => {
|
|
406
|
+
const { type, ...props } = elm;
|
|
407
|
+
if (!type) throw new Error("insert requires an element with a type");
|
|
408
|
+
delete props[`${type}_id`];
|
|
409
|
+
return suIndexed[type].insert(props);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (prop === "insertAll") {
|
|
413
|
+
return (elms) => elms.map((elm) => suIndexed.insert(elm));
|
|
414
|
+
}
|
|
415
|
+
if (prop === "subtree") {
|
|
416
|
+
return (opts) => cjuIndexed(buildSubtree(soup, opts), options);
|
|
417
|
+
}
|
|
404
418
|
const component_type = prop;
|
|
405
419
|
return {
|
|
406
420
|
get: (id) => {
|
|
@@ -496,7 +510,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
496
510
|
const indexConfig = options.indexConfig || {};
|
|
497
511
|
const keys = !where ? [] : Object.keys(where);
|
|
498
512
|
if (keys.length === 0 && indexConfig.byType && internalStore.indexes.byType) {
|
|
499
|
-
return internalStore.indexes.byType.get(component_type) || [];
|
|
513
|
+
return (internalStore.indexes.byType.get(component_type) || []).slice();
|
|
500
514
|
}
|
|
501
515
|
if (keys.length === 1 && keys[0] === "subcircuit_id" && indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit) {
|
|
502
516
|
const subcircuitId = where.subcircuit_id;
|
|
@@ -516,7 +530,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
516
530
|
(e) => keys.every((key) => e[key] === where[key])
|
|
517
531
|
);
|
|
518
532
|
}
|
|
519
|
-
return elementsToFilter;
|
|
533
|
+
return elementsToFilter.slice();
|
|
520
534
|
},
|
|
521
535
|
insert: (elm) => {
|
|
522
536
|
internalStore.counts[component_type] ??= -1;
|
|
@@ -2770,16 +2784,218 @@ var categorizeErrorOrWarning = (value) => {
|
|
|
2770
2784
|
if (SOURCE_TYPES.has(drcType)) return "source";
|
|
2771
2785
|
return "unknown";
|
|
2772
2786
|
};
|
|
2787
|
+
|
|
2788
|
+
// lib/copper-geometry.ts
|
|
2789
|
+
import {
|
|
2790
|
+
Arc,
|
|
2791
|
+
Box,
|
|
2792
|
+
Circle,
|
|
2793
|
+
Matrix,
|
|
2794
|
+
ORIENTATION,
|
|
2795
|
+
Point,
|
|
2796
|
+
Polygon,
|
|
2797
|
+
Segment
|
|
2798
|
+
} from "@flatten-js/core";
|
|
2799
|
+
import { compose, rotate, translate as translate5 } from "transformation-matrix";
|
|
2800
|
+
var placePolygon = (polygon, center, degrees = 0) => {
|
|
2801
|
+
const { a, b, c, d, e, f } = compose(
|
|
2802
|
+
translate5(center.x, center.y),
|
|
2803
|
+
rotate(degrees * Math.PI / 180)
|
|
2804
|
+
);
|
|
2805
|
+
return polygon.transform(new Matrix(a, b, c, d, e, f));
|
|
2806
|
+
};
|
|
2807
|
+
var ccw = (polygon) => polygon.orientation() === ORIENTATION.CCW ? polygon : polygon.reverse();
|
|
2808
|
+
var circlePolygon = (center, radius) => ccw(new Polygon(new Circle(new Point(center.x, center.y), radius)));
|
|
2809
|
+
var roundedRectangle = (center, width, height, radius = 0, degrees = 0) => {
|
|
2810
|
+
const x = width / 2;
|
|
2811
|
+
const y = height / 2;
|
|
2812
|
+
const r = Math.max(0, Math.min(radius, x, y));
|
|
2813
|
+
if (r === 0)
|
|
2814
|
+
return placePolygon(
|
|
2815
|
+
ccw(new Polygon(new Box(-x, -y, x, y))),
|
|
2816
|
+
center,
|
|
2817
|
+
degrees
|
|
2818
|
+
);
|
|
2819
|
+
const arcs = [
|
|
2820
|
+
new Arc(new Point(x - r, -y + r), r, -Math.PI / 2, 0, true),
|
|
2821
|
+
new Arc(new Point(x - r, y - r), r, 0, Math.PI / 2, true),
|
|
2822
|
+
new Arc(new Point(-x + r, y - r), r, Math.PI / 2, Math.PI, true),
|
|
2823
|
+
new Arc(new Point(-x + r, -y + r), r, Math.PI, Math.PI * 1.5, true)
|
|
2824
|
+
];
|
|
2825
|
+
const edges = [];
|
|
2826
|
+
for (let i = 0; i < arcs.length; i++) {
|
|
2827
|
+
const arc = arcs[i];
|
|
2828
|
+
const next = arcs[(i + 1) % arcs.length];
|
|
2829
|
+
edges.push(arc);
|
|
2830
|
+
if (arc.end.distanceTo(next.start)[0] > 1e-12)
|
|
2831
|
+
edges.push(new Segment(arc.end, next.start));
|
|
2832
|
+
}
|
|
2833
|
+
return placePolygon(ccw(new Polygon(edges)), center, degrees);
|
|
2834
|
+
};
|
|
2835
|
+
var ringPolygon = (ring) => {
|
|
2836
|
+
const edges = [];
|
|
2837
|
+
for (let i = 0; i < ring.vertices.length; i++) {
|
|
2838
|
+
const start = ring.vertices[i];
|
|
2839
|
+
const end = ring.vertices[(i + 1) % ring.vertices.length];
|
|
2840
|
+
const dx = end.x - start.x;
|
|
2841
|
+
const dy = end.y - start.y;
|
|
2842
|
+
if (dx === 0 && dy === 0) continue;
|
|
2843
|
+
const bulge = start.bulge ?? 0;
|
|
2844
|
+
if (bulge === 0) {
|
|
2845
|
+
edges.push(
|
|
2846
|
+
new Segment(new Point(start.x, start.y), new Point(end.x, end.y))
|
|
2847
|
+
);
|
|
2848
|
+
} else {
|
|
2849
|
+
const offset = (1 - bulge * bulge) / (4 * bulge);
|
|
2850
|
+
const center = new Point(
|
|
2851
|
+
(start.x + end.x) / 2 - dy * offset,
|
|
2852
|
+
(start.y + end.y) / 2 + dx * offset
|
|
2853
|
+
);
|
|
2854
|
+
edges.push(
|
|
2855
|
+
new Arc(
|
|
2856
|
+
center,
|
|
2857
|
+
Math.hypot(dx, dy) * (1 + bulge * bulge) / (4 * Math.abs(bulge)),
|
|
2858
|
+
Math.atan2(start.y - center.y, start.x - center.x),
|
|
2859
|
+
Math.atan2(end.y - center.y, end.x - center.x),
|
|
2860
|
+
bulge > 0
|
|
2861
|
+
)
|
|
2862
|
+
);
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
return ccw(new Polygon(edges));
|
|
2866
|
+
};
|
|
2867
|
+
var subtractHole = (outer, hole) => {
|
|
2868
|
+
for (const face of hole.reverse().faces) outer.addFace(face.shapes);
|
|
2869
|
+
return outer;
|
|
2870
|
+
};
|
|
2871
|
+
var getPourPolygon = (pour) => {
|
|
2872
|
+
if (pour.shape === "rect")
|
|
2873
|
+
return roundedRectangle(
|
|
2874
|
+
pour.center,
|
|
2875
|
+
pour.width,
|
|
2876
|
+
pour.height,
|
|
2877
|
+
0,
|
|
2878
|
+
pour.rotation
|
|
2879
|
+
);
|
|
2880
|
+
if (pour.shape === "polygon")
|
|
2881
|
+
return ccw(new Polygon(pour.points.map((p) => new Point(p.x, p.y))));
|
|
2882
|
+
const polygon = ringPolygon(pour.brep_shape.outer_ring);
|
|
2883
|
+
for (const ring of pour.brep_shape.inner_rings)
|
|
2884
|
+
subtractHole(polygon, ringPolygon(ring));
|
|
2885
|
+
return polygon;
|
|
2886
|
+
};
|
|
2887
|
+
var getSmtPadPolygon = (pad) => {
|
|
2888
|
+
if (pad.shape === "polygon")
|
|
2889
|
+
return ccw(new Polygon(pad.points.map((p) => new Point(p.x, p.y))));
|
|
2890
|
+
if (pad.shape === "circle") return circlePolygon(pad, pad.radius);
|
|
2891
|
+
const radius = pad.shape === "pill" || pad.shape === "rotated_pill" ? pad.radius : pad.corner_radius ?? pad.rect_border_radius ?? 0;
|
|
2892
|
+
return roundedRectangle(
|
|
2893
|
+
pad,
|
|
2894
|
+
pad.width,
|
|
2895
|
+
pad.height,
|
|
2896
|
+
radius,
|
|
2897
|
+
"ccw_rotation" in pad ? pad.ccw_rotation : 0
|
|
2898
|
+
);
|
|
2899
|
+
};
|
|
2900
|
+
var getViaPolygon = (center, outerDiameter, holeDiameter) => subtractHole(
|
|
2901
|
+
circlePolygon(center, outerDiameter / 2),
|
|
2902
|
+
circlePolygon(center, holeDiameter / 2)
|
|
2903
|
+
);
|
|
2904
|
+
var getPlatedHolePolygon = (pad, componentRotation = 0) => {
|
|
2905
|
+
if (pad.shape === "circle")
|
|
2906
|
+
return getViaPolygon(pad, pad.outer_diameter, pad.hole_diameter);
|
|
2907
|
+
if ("outer_width" in pad) {
|
|
2908
|
+
return subtractHole(
|
|
2909
|
+
roundedRectangle(
|
|
2910
|
+
pad,
|
|
2911
|
+
pad.outer_width,
|
|
2912
|
+
pad.outer_height,
|
|
2913
|
+
Math.min(pad.outer_width, pad.outer_height) / 2,
|
|
2914
|
+
pad.ccw_rotation
|
|
2915
|
+
),
|
|
2916
|
+
roundedRectangle(
|
|
2917
|
+
pad,
|
|
2918
|
+
pad.hole_width,
|
|
2919
|
+
pad.hole_height,
|
|
2920
|
+
Math.min(pad.hole_width, pad.hole_height) / 2,
|
|
2921
|
+
pad.ccw_rotation
|
|
2922
|
+
)
|
|
2923
|
+
);
|
|
2924
|
+
}
|
|
2925
|
+
const center = { x: pad.x + pad.hole_offset_x, y: pad.y + pad.hole_offset_y };
|
|
2926
|
+
const outer = pad.shape === "hole_with_polygon_pad" ? placePolygon(
|
|
2927
|
+
ccw(new Polygon(pad.pad_outline.map((p) => new Point(p.x, p.y)))),
|
|
2928
|
+
pad,
|
|
2929
|
+
pad.ccw_rotation ?? componentRotation
|
|
2930
|
+
) : roundedRectangle(
|
|
2931
|
+
pad,
|
|
2932
|
+
pad.rect_pad_width,
|
|
2933
|
+
pad.rect_pad_height,
|
|
2934
|
+
pad.rect_border_radius,
|
|
2935
|
+
"rect_ccw_rotation" in pad ? pad.rect_ccw_rotation : 0
|
|
2936
|
+
);
|
|
2937
|
+
if (pad.shape === "circular_hole_with_rect_pad" || pad.shape === "hole_with_polygon_pad" && pad.hole_shape === "circle") {
|
|
2938
|
+
if (pad.hole_diameter === void 0)
|
|
2939
|
+
throw new Error("Circular plated hole requires hole_diameter");
|
|
2940
|
+
return subtractHole(outer, circlePolygon(center, pad.hole_diameter / 2));
|
|
2941
|
+
}
|
|
2942
|
+
if (!("hole_width" in pad) || pad.hole_width === void 0 || pad.hole_height === void 0)
|
|
2943
|
+
throw new Error("Slotted plated hole requires hole_width and hole_height");
|
|
2944
|
+
return subtractHole(
|
|
2945
|
+
outer,
|
|
2946
|
+
roundedRectangle(
|
|
2947
|
+
center,
|
|
2948
|
+
pad.hole_width,
|
|
2949
|
+
pad.hole_height,
|
|
2950
|
+
Math.min(pad.hole_width, pad.hole_height) / 2,
|
|
2951
|
+
"hole_ccw_rotation" in pad ? pad.hole_ccw_rotation : pad.shape === "hole_with_polygon_pad" ? pad.ccw_rotation ?? componentRotation : 0
|
|
2952
|
+
)
|
|
2953
|
+
);
|
|
2954
|
+
};
|
|
2955
|
+
var getTraceSegmentPolygon = (start, end, startWidth, endWidth = startWidth) => {
|
|
2956
|
+
const length = Math.hypot(end.x - start.x, end.y - start.y);
|
|
2957
|
+
const r1 = startWidth / 2;
|
|
2958
|
+
const r2 = endWidth / 2;
|
|
2959
|
+
if (length <= Math.abs(r2 - r1))
|
|
2960
|
+
return circlePolygon(r1 >= r2 ? start : end, Math.max(r1, r2));
|
|
2961
|
+
const angle = Math.atan2(end.y - start.y, end.x - start.x);
|
|
2962
|
+
const tangent = Math.acos((r1 - r2) / length);
|
|
2963
|
+
const first = new Arc(
|
|
2964
|
+
new Point(start.x, start.y),
|
|
2965
|
+
r1,
|
|
2966
|
+
angle + tangent,
|
|
2967
|
+
angle - tangent,
|
|
2968
|
+
true
|
|
2969
|
+
);
|
|
2970
|
+
const second = new Arc(
|
|
2971
|
+
new Point(end.x, end.y),
|
|
2972
|
+
r2,
|
|
2973
|
+
angle - tangent,
|
|
2974
|
+
angle + tangent,
|
|
2975
|
+
true
|
|
2976
|
+
);
|
|
2977
|
+
return ccw(
|
|
2978
|
+
new Polygon([
|
|
2979
|
+
first,
|
|
2980
|
+
new Segment(first.end, second.start),
|
|
2981
|
+
second,
|
|
2982
|
+
new Segment(second.end, first.start)
|
|
2983
|
+
])
|
|
2984
|
+
);
|
|
2985
|
+
};
|
|
2986
|
+
var copperPolygonsTouch = (a, b, tolerance = 1e-7) => a.vertices.some((p) => b.contains(p)) || b.vertices.some((p) => a.contains(p)) || a.distanceTo(b)[0] <= tolerance;
|
|
2773
2987
|
export {
|
|
2774
2988
|
analyzePcbPin1Location,
|
|
2775
2989
|
applySelector,
|
|
2776
2990
|
applySelectorAST,
|
|
2777
2991
|
buildSubtree,
|
|
2778
2992
|
categorizeErrorOrWarning,
|
|
2993
|
+
circlePolygon,
|
|
2779
2994
|
cju_default as cju,
|
|
2780
2995
|
cju_indexed_default as cjuIndexed,
|
|
2781
2996
|
computeClearanceBetweenElements,
|
|
2782
2997
|
computeGapBetweenCopper,
|
|
2998
|
+
copperPolygonsTouch,
|
|
2783
2999
|
directionToVec,
|
|
2784
3000
|
distanceBetweenCircleAndCircle,
|
|
2785
3001
|
distanceBetweenCircleAndPolygon,
|
|
@@ -2795,15 +3011,21 @@ export {
|
|
|
2795
3011
|
getMinimumFlexContainer,
|
|
2796
3012
|
getPcbElementBounds,
|
|
2797
3013
|
getPcbElementsWithinBounds,
|
|
3014
|
+
getPlatedHolePolygon,
|
|
3015
|
+
getPourPolygon,
|
|
2798
3016
|
getPrimaryId,
|
|
2799
3017
|
getReadableNameForElement,
|
|
2800
3018
|
getReadableNameForPcbPort,
|
|
2801
3019
|
getReadableNameForPcbSmtpad,
|
|
2802
3020
|
getReadableNameForPcbTrace,
|
|
2803
3021
|
getSchematicElementBounds,
|
|
3022
|
+
getSmtPadPolygon,
|
|
2804
3023
|
getStringFromCircuitJsonTree,
|
|
3024
|
+
getTraceSegmentPolygon,
|
|
3025
|
+
getViaPolygon,
|
|
2805
3026
|
oppositeDirection,
|
|
2806
3027
|
oppositeSide,
|
|
3028
|
+
placePolygon,
|
|
2807
3029
|
repositionPcbComponentTo,
|
|
2808
3030
|
repositionPcbGroupTo,
|
|
2809
3031
|
repositionSchematicComponentTo,
|
|
@@ -2811,6 +3033,7 @@ export {
|
|
|
2811
3033
|
rotateClockwise,
|
|
2812
3034
|
rotateCounterClockwise,
|
|
2813
3035
|
rotateDirection,
|
|
3036
|
+
roundedRectangle,
|
|
2814
3037
|
su,
|
|
2815
3038
|
transformInsertionDirection,
|
|
2816
3039
|
transformPCBElement,
|