@tscircuit/core 0.0.844 → 0.0.846

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 CHANGED
@@ -340,6 +340,7 @@ declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extend
340
340
  _parsedProps: z.infer<ZodProps>;
341
341
  get componentName(): string;
342
342
  getInheritedProperty(propertyName: string): any;
343
+ getInheritedMergedProperty(propertyName: string): any;
343
344
  get lowercaseComponentName(): string;
344
345
  externallyAddedAliases: string[];
345
346
  /**
@@ -24653,20 +24654,26 @@ declare class CopperPour extends PrimitiveComponent<typeof copperPourProps> {
24653
24654
  connectsTo: zod.ZodString;
24654
24655
  padMargin: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
24655
24656
  traceMargin: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
24657
+ clearance: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
24658
+ coveredWithSolderMask: zod.ZodDefault<zod.ZodOptional<zod.ZodBoolean>>;
24656
24659
  }, "strip", zod.ZodTypeAny, {
24657
24660
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
24658
24661
  connectsTo: string;
24662
+ coveredWithSolderMask: boolean;
24659
24663
  name?: string | undefined;
24660
24664
  padMargin?: number | undefined;
24661
24665
  traceMargin?: number | undefined;
24666
+ clearance?: number | undefined;
24662
24667
  }, {
24663
24668
  layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | {
24664
24669
  name: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6";
24665
24670
  };
24666
24671
  connectsTo: string;
24667
24672
  name?: string | undefined;
24673
+ coveredWithSolderMask?: boolean | undefined;
24668
24674
  padMargin?: string | number | undefined;
24669
24675
  traceMargin?: string | number | undefined;
24676
+ clearance?: string | number | undefined;
24670
24677
  }>;
24671
24678
  };
24672
24679
  getPcbSize(): {
package/dist/index.js CHANGED
@@ -669,6 +669,11 @@ var PrimitiveComponent2 = class extends Renderable {
669
669
  }
670
670
  return void 0;
671
671
  }
672
+ getInheritedMergedProperty(propertyName) {
673
+ const parentPropertyObject = this.parent?.getInheritedMergedProperty?.(propertyName);
674
+ const myPropertyObject = this._parsedProps?.[propertyName];
675
+ return { ...parentPropertyObject, ...myPropertyObject };
676
+ }
672
677
  get lowercaseComponentName() {
673
678
  return this.componentName.toLowerCase();
674
679
  }
@@ -7479,9 +7484,12 @@ function NormalComponent_doInitialPcbFootprintStringRender(component, queueAsync
7479
7484
  resolverFn = libMap;
7480
7485
  }
7481
7486
  if (!resolverFn) return;
7487
+ const resolvedPcbStyle = component.getInheritedMergedProperty("pcbStyle");
7482
7488
  queueAsyncEffect("load-lib-footprint", async () => {
7483
7489
  try {
7484
- const result = await resolverFn(libRef.footprintName);
7490
+ const result = await resolverFn(libRef.footprintName, {
7491
+ resolvedPcbStyle
7492
+ });
7485
7493
  let circuitJson = null;
7486
7494
  if (Array.isArray(result)) {
7487
7495
  circuitJson = result;
@@ -16316,216 +16324,10 @@ var Via = class extends PrimitiveComponent2 {
16316
16324
 
16317
16325
  // lib/components/primitive-components/CopperPour/CopperPour.ts
16318
16326
  import { copperPourProps } from "@tscircuit/props";
16319
- import { getFullConnectivityMapFromCircuitJson as getFullConnectivityMapFromCircuitJson4 } from "circuit-json-to-connectivity-map";
16320
- import Flatten4 from "@flatten-js/core";
16321
-
16322
- // lib/components/primitive-components/CopperPour/utils/get-board-polygon.ts
16323
- import Flatten from "@flatten-js/core";
16324
- var getBoardPolygon = (board) => {
16325
- if (board.outline && board.outline.length > 0) {
16326
- return new Flatten.Polygon(
16327
- board.outline.map((p) => Flatten.point(p.x, p.y))
16328
- );
16329
- }
16330
- return new Flatten.Polygon(
16331
- new Flatten.Box(
16332
- board.center.x - board.width / 2,
16333
- board.center.y - board.height / 2,
16334
- board.center.x + board.width / 2,
16335
- board.center.y + board.height / 2
16336
- ).toPoints()
16337
- );
16338
- };
16339
-
16340
- // lib/components/primitive-components/CopperPour/utils/get-trace-obstacles.ts
16341
- var getTraceObstacles = (db, layer) => {
16342
- const traceObstacles = [];
16343
- for (const pcb_trace of db.pcb_trace.list()) {
16344
- if (!pcb_trace.route) continue;
16345
- const source_trace = pcb_trace.source_trace_id ? db.source_trace.get(pcb_trace.source_trace_id) : null;
16346
- const connectedToIds = /* @__PURE__ */ new Set();
16347
- if (pcb_trace.source_trace_id) {
16348
- connectedToIds.add(pcb_trace.source_trace_id);
16349
- }
16350
- if (source_trace) {
16351
- for (const id of source_trace.connected_source_net_ids)
16352
- connectedToIds.add(id);
16353
- for (const id of source_trace.connected_source_port_ids)
16354
- connectedToIds.add(id);
16355
- }
16356
- for (const pt of pcb_trace.route) {
16357
- if (pt.route_type === "wire") {
16358
- if (pt.start_pcb_port_id) {
16359
- const pcb_port = db.pcb_port.get(pt.start_pcb_port_id);
16360
- if (pcb_port?.source_port_id)
16361
- connectedToIds.add(pcb_port.source_port_id);
16362
- }
16363
- if (pt.end_pcb_port_id) {
16364
- const pcb_port = db.pcb_port.get(pt.end_pcb_port_id);
16365
- if (pcb_port?.source_port_id)
16366
- connectedToIds.add(pcb_port.source_port_id);
16367
- }
16368
- }
16369
- }
16370
- const connectedTo = Array.from(connectedToIds);
16371
- for (let i = 0; i < pcb_trace.route.length - 1; i++) {
16372
- const p1 = pcb_trace.route[i];
16373
- const p2 = pcb_trace.route[i + 1];
16374
- if (p1.route_type !== "wire" || p2.route_type !== "wire") continue;
16375
- if (p1.layer !== layer) continue;
16376
- const segmentWidth = p1.width;
16377
- if (segmentWidth === 0) continue;
16378
- const segmentLength = Math.hypot(p1.x - p2.x, p1.y - p2.y);
16379
- if (segmentLength === 0) continue;
16380
- const centerX = (p1.x + p2.x) / 2;
16381
- const centerY = (p1.y + p2.y) / 2;
16382
- const rotationDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
16383
- const rotatedRect = {
16384
- center: { x: centerX, y: centerY },
16385
- width: segmentLength,
16386
- height: segmentWidth,
16387
- rotation: rotationDeg
16388
- };
16389
- const approximatingRects = generateApproximatingRects(rotatedRect);
16390
- for (const rect of approximatingRects) {
16391
- traceObstacles.push({
16392
- type: "rect",
16393
- layers: [p1.layer],
16394
- center: rect.center,
16395
- width: rect.width,
16396
- height: rect.height,
16397
- connectedTo,
16398
- obstacle_type: "trace"
16399
- });
16400
- }
16401
- }
16402
- }
16403
- return traceObstacles;
16404
- };
16405
-
16406
- // lib/components/primitive-components/CopperPour/utils/process-obstacles.ts
16407
- import Flatten2 from "@flatten-js/core";
16408
- var processObstaclesForPour = (obstacles, connMap, net, margins) => {
16409
- const rectObstaclesToSubtract = [];
16410
- const circularObstacles = [];
16411
- const { traceMargin, padMargin } = margins;
16412
- for (const obs of obstacles) {
16413
- const isOnNet = obs.connectedTo.some(
16414
- (id) => connMap.areIdsConnected(id, net.source_net_id)
16415
- );
16416
- if (isOnNet) {
16417
- continue;
16418
- }
16419
- if (obs.type === "oval" && obs.width === obs.height) {
16420
- const radius = obs.width / 2 + padMargin;
16421
- circularObstacles.push({
16422
- center: obs.center,
16423
- radius
16424
- });
16425
- continue;
16426
- }
16427
- if (obs.type === "rect" && obs.width === obs.height && obs.connectedTo.length === 0) {
16428
- const radius = obs.width / 2;
16429
- circularObstacles.push({
16430
- center: obs.center,
16431
- radius
16432
- });
16433
- continue;
16434
- }
16435
- const margin = traceMargin;
16436
- const b = new Flatten2.Box(
16437
- obs.center.x - obs.width / 2 - margin,
16438
- obs.center.y - obs.height / 2 - margin,
16439
- obs.center.x + obs.width / 2 + margin,
16440
- obs.center.y + obs.height / 2 + margin
16441
- );
16442
- rectObstaclesToSubtract.push(new Flatten2.Polygon(b.toPoints()));
16443
- }
16444
- return { rectObstaclesToSubtract, circularObstacles };
16445
- };
16446
-
16447
- // lib/components/primitive-components/CopperPour/utils/generate-and-insert-brep.ts
16448
- import Flatten3 from "@flatten-js/core";
16449
- var faceToVertices = (face) => face.edges.map((e) => {
16450
- const pt = {
16451
- x: e.start.x,
16452
- y: e.start.y
16453
- };
16454
- if (e.isArc) {
16455
- const bulge = Math.tan(e.shape.sweep / 4);
16456
- if (Math.abs(bulge) > 1e-9) {
16457
- pt.bulge = bulge;
16458
- }
16459
- }
16460
- return pt;
16461
- });
16462
- var generateAndInsertBRep = (pourPolygons, circularObstacles, {
16463
- db,
16464
- copperPour
16465
- }) => {
16466
- const props = copperPour._parsedProps;
16467
- const net = copperPour.getSubcircuit().selectOne(props.connectsTo);
16468
- const subcircuit = copperPour.getSubcircuit();
16469
- const polygons = Array.isArray(pourPolygons) ? pourPolygons : [pourPolygons];
16470
- for (const p of polygons) {
16471
- const islands = p.splitToIslands();
16472
- for (const island of islands) {
16473
- if (island.isEmpty()) continue;
16474
- const faces = [...island.faces];
16475
- const outer_face_ccw = faces.find(
16476
- (f) => f.orientation() === Flatten3.ORIENTATION.CCW
16477
- );
16478
- const inner_faces_cw = faces.filter(
16479
- (f) => f.orientation() === Flatten3.ORIENTATION.CW
16480
- );
16481
- if (!outer_face_ccw) continue;
16482
- if (!db.pcb_copper_pour) {
16483
- copperPour.renderError(
16484
- "db.pcb_copper_pour not found. The database schema may be outdated."
16485
- );
16486
- return;
16487
- }
16488
- outer_face_ccw.reverse();
16489
- const outer_ring_vertices = faceToVertices(outer_face_ccw);
16490
- const inner_rings = inner_faces_cw.map((f) => {
16491
- f.reverse();
16492
- return { vertices: faceToVertices(f) };
16493
- });
16494
- for (const circle of circularObstacles) {
16495
- const centerPoint = Flatten3.point(circle.center.x, circle.center.y);
16496
- const isContained = island.contains(centerPoint);
16497
- if (isContained) {
16498
- inner_rings.push({
16499
- vertices: [
16500
- {
16501
- x: circle.center.x,
16502
- y: circle.center.y - circle.radius,
16503
- bulge: 1
16504
- },
16505
- {
16506
- x: circle.center.x,
16507
- y: circle.center.y + circle.radius,
16508
- bulge: 1
16509
- }
16510
- ]
16511
- });
16512
- }
16513
- }
16514
- db.pcb_copper_pour.insert({
16515
- shape: "brep",
16516
- layer: props.layer,
16517
- brep_shape: {
16518
- outer_ring: { vertices: outer_ring_vertices },
16519
- inner_rings
16520
- },
16521
- source_net_id: net.source_net_id,
16522
- subcircuit_id: subcircuit?.subcircuit_id ?? void 0
16523
- });
16524
- }
16525
- }
16526
- };
16527
-
16528
- // lib/components/primitive-components/CopperPour/CopperPour.ts
16327
+ import {
16328
+ CopperPourPipelineSolver,
16329
+ convertCircuitJsonToInputProblem
16330
+ } from "@tscircuit/copper-pour-solver";
16529
16331
  var CopperPour = class extends PrimitiveComponent2 {
16530
16332
  isPcbPrimitive = true;
16531
16333
  get config() {
@@ -16547,38 +16349,27 @@ var CopperPour = class extends PrimitiveComponent2 {
16547
16349
  this.renderError(`Net "${props.connectsTo}" not found for copper pour`);
16548
16350
  return;
16549
16351
  }
16550
- const board = db.pcb_board.list()[0];
16551
- if (!board) {
16552
- this.renderError("No board found for copper pour");
16553
- return;
16554
- }
16555
- const boardPolygon = getBoardPolygon(board);
16556
- const connMap = getFullConnectivityMapFromCircuitJson4(db.toArray());
16557
- const obstaclesRaw = getObstaclesFromCircuitJson(
16558
- db.toArray(),
16559
- connMap
16560
- ).filter((o) => o.layers.includes(props.layer));
16561
- obstaclesRaw.push(...getTraceObstacles(db, props.layer));
16562
- const { rectObstaclesToSubtract, circularObstacles } = processObstaclesForPour(obstaclesRaw, connMap, net, {
16563
- traceMargin: props.traceMargin ?? 0.2,
16564
- padMargin: props.padMargin ?? 0.2
16352
+ const subcircuit = this.getSubcircuit();
16353
+ const sourceNet = db.toArray().filter(
16354
+ (elm) => elm.type === "source_net" && elm.name === net.name
16355
+ )[0] || "";
16356
+ const inputProblem = convertCircuitJsonToInputProblem(db.toArray(), {
16357
+ layer: props.layer,
16358
+ pour_connectivity_key: sourceNet.subcircuit_connectivity_map_key || "",
16359
+ pad_margin: props.padMargin ?? 0.2,
16360
+ trace_margin: props.traceMargin ?? 0.2
16565
16361
  });
16566
- let pourPolygons = boardPolygon;
16567
- if (rectObstaclesToSubtract.length > 0) {
16568
- const obstacleUnion = rectObstaclesToSubtract.reduce(
16569
- (acc, p) => Flatten4.BooleanOperations.unify(acc, p)
16570
- );
16571
- if (obstacleUnion && !obstacleUnion.isEmpty()) {
16572
- pourPolygons = Flatten4.BooleanOperations.subtract(
16573
- boardPolygon,
16574
- obstacleUnion
16575
- );
16576
- }
16362
+ const solver = new CopperPourPipelineSolver(inputProblem);
16363
+ const { brep_shapes } = solver.getOutput();
16364
+ for (const brep_shape of brep_shapes) {
16365
+ db.pcb_copper_pour.insert({
16366
+ shape: "brep",
16367
+ layer: props.layer,
16368
+ brep_shape,
16369
+ source_net_id: net.source_net_id,
16370
+ subcircuit_id: subcircuit?.subcircuit_id ?? void 0
16371
+ });
16577
16372
  }
16578
- generateAndInsertBRep(pourPolygons, circularObstacles, {
16579
- db,
16580
- copperPour: this
16581
- });
16582
16373
  });
16583
16374
  }
16584
16375
  };
@@ -17821,7 +17612,7 @@ import { identity as identity6 } from "transformation-matrix";
17821
17612
  var package_default = {
17822
17613
  name: "@tscircuit/core",
17823
17614
  type: "module",
17824
- version: "0.0.843",
17615
+ version: "0.0.845",
17825
17616
  types: "dist/index.d.ts",
17826
17617
  main: "dist/index.js",
17827
17618
  module: "dist/index.js",
@@ -17856,6 +17647,7 @@ var package_default = {
17856
17647
  "@tscircuit/checks": "^0.0.85",
17857
17648
  "@tscircuit/circuit-json-util": "^0.0.72",
17858
17649
  "@tscircuit/common": "^0.0.20",
17650
+ "@tscircuit/copper-pour-solver": "^0.0.2",
17859
17651
  "@tscircuit/footprinter": "^0.0.236",
17860
17652
  "@tscircuit/import-snippet": "^0.0.4",
17861
17653
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -17864,10 +17656,11 @@ var package_default = {
17864
17656
  "@tscircuit/math-utils": "^0.0.29",
17865
17657
  "@tscircuit/miniflex": "^0.0.4",
17866
17658
  "@tscircuit/ngspice-spice-engine": "^0.0.2",
17867
- "@tscircuit/props": "^0.0.390",
17659
+ "@tscircuit/props": "^0.0.393",
17868
17660
  "@tscircuit/schematic-autolayout": "^0.0.6",
17869
17661
  "@tscircuit/schematic-match-adapt": "^0.0.16",
17870
17662
  "@tscircuit/schematic-trace-solver": "^0.0.43",
17663
+ "@tscircuit/solver-utils": "^0.0.3",
17871
17664
  "@types/bun": "^1.2.16",
17872
17665
  "@types/debug": "^4.1.12",
17873
17666
  "@types/react": "^19.1.8",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.844",
4
+ "version": "0.0.846",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -36,6 +36,7 @@
36
36
  "@tscircuit/checks": "^0.0.85",
37
37
  "@tscircuit/circuit-json-util": "^0.0.72",
38
38
  "@tscircuit/common": "^0.0.20",
39
+ "@tscircuit/copper-pour-solver": "^0.0.2",
39
40
  "@tscircuit/footprinter": "^0.0.236",
40
41
  "@tscircuit/import-snippet": "^0.0.4",
41
42
  "@tscircuit/infgrid-ijump-astar": "^0.0.33",
@@ -44,10 +45,11 @@
44
45
  "@tscircuit/math-utils": "^0.0.29",
45
46
  "@tscircuit/miniflex": "^0.0.4",
46
47
  "@tscircuit/ngspice-spice-engine": "^0.0.2",
47
- "@tscircuit/props": "^0.0.390",
48
+ "@tscircuit/props": "^0.0.393",
48
49
  "@tscircuit/schematic-autolayout": "^0.0.6",
49
50
  "@tscircuit/schematic-match-adapt": "^0.0.16",
50
51
  "@tscircuit/schematic-trace-solver": "^0.0.43",
52
+ "@tscircuit/solver-utils": "^0.0.3",
51
53
  "@types/bun": "^1.2.16",
52
54
  "@types/debug": "^4.1.12",
53
55
  "@types/react": "^19.1.8",