@tscircuit/core 0.0.191 → 0.0.192

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
@@ -916,6 +916,7 @@ declare class Board extends Group<typeof boardProps> {
916
916
  defaultTraceWidth: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
917
917
  minTraceWidth: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
918
918
  partsEngine: z.ZodOptional<z.ZodType<_tscircuit_props.PartsEngine, z.ZodTypeDef, _tscircuit_props.PartsEngine>>;
919
+ pcbRouteCache: z.ZodOptional<z.ZodType<_tscircuit_props.PcbRouteCache, z.ZodTypeDef, _tscircuit_props.PcbRouteCache>>;
919
920
  }>, {
920
921
  width: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
921
922
  height: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
@@ -947,6 +948,7 @@ declare class Board extends Group<typeof boardProps> {
947
948
  routingDisabled?: boolean | undefined;
948
949
  defaultTraceWidth?: number | undefined;
949
950
  minTraceWidth?: number | undefined;
951
+ pcbRouteCache?: _tscircuit_props.PcbRouteCache | undefined;
950
952
  schAutoLayoutEnabled?: boolean | undefined;
951
953
  partsEngine?: _tscircuit_props.PartsEngine | undefined;
952
954
  outline?: {
@@ -973,6 +975,7 @@ declare class Board extends Group<typeof boardProps> {
973
975
  routingDisabled?: boolean | undefined;
974
976
  defaultTraceWidth?: string | number | undefined;
975
977
  minTraceWidth?: string | number | undefined;
978
+ pcbRouteCache?: _tscircuit_props.PcbRouteCache | undefined;
976
979
  schAutoLayoutEnabled?: boolean | undefined;
977
980
  partsEngine?: _tscircuit_props.PartsEngine | undefined;
978
981
  outline?: {
package/dist/index.js CHANGED
@@ -3566,6 +3566,20 @@ var findPossibleTraceLayerCombinations = (hints, layer_path = []) => {
3566
3566
  return candidates;
3567
3567
  };
3568
3568
 
3569
+ // lib/utils/autorouting/getDominantDirection.ts
3570
+ function getDominantDirection(edge) {
3571
+ const delta = {
3572
+ x: edge.to.x - edge.from.x,
3573
+ y: edge.to.y - edge.from.y
3574
+ };
3575
+ const absX = Math.abs(delta.x);
3576
+ const absY = Math.abs(delta.y);
3577
+ if (absX > absY) {
3578
+ return delta.x > 0 ? "right" : "left";
3579
+ }
3580
+ return delta.y > 0 ? "down" : "up";
3581
+ }
3582
+
3569
3583
  // lib/utils/autorouting/mergeRoutes.ts
3570
3584
  function pdist(a, b) {
3571
3585
  return Math.hypot(a.x - b.x, a.y - b.y);
@@ -3645,31 +3659,15 @@ function getClosest(point, candidates) {
3645
3659
  return closest;
3646
3660
  }
3647
3661
 
3648
- // lib/utils/try-now.ts
3649
- function tryNow(fn) {
3650
- try {
3651
- return [fn(), null];
3652
- } catch (e) {
3653
- return [null, e];
3654
- }
3655
- }
3656
-
3657
- // lib/components/primitive-components/Trace/Trace.ts
3658
- import "zod";
3659
-
3660
- // lib/utils/autorouting/getDominantDirection.ts
3661
- function getDominantDirection(edge) {
3662
- const delta = {
3663
- x: edge.to.x - edge.from.x,
3664
- y: edge.to.y - edge.from.y
3665
- };
3666
- const absX = Math.abs(delta.x);
3667
- const absY = Math.abs(delta.y);
3668
- if (absX > absY) {
3669
- return delta.x > 0 ? "right" : "left";
3670
- }
3671
- return delta.y > 0 ? "down" : "up";
3672
- }
3662
+ // lib/utils/schematic/getEnteringEdgeFromDirection.ts
3663
+ var getEnteringEdgeFromDirection = (direction) => {
3664
+ return {
3665
+ up: "bottom",
3666
+ down: "top",
3667
+ left: "right",
3668
+ right: "left"
3669
+ }[direction] ?? null;
3670
+ };
3673
3671
 
3674
3672
  // lib/utils/schematic/getStubEdges.ts
3675
3673
  import { distance } from "@tscircuit/math-utils";
@@ -3723,11 +3721,20 @@ var getStubEdges = ({
3723
3721
  return edges;
3724
3722
  };
3725
3723
 
3724
+ // lib/utils/try-now.ts
3725
+ function tryNow(fn) {
3726
+ try {
3727
+ return [fn(), null];
3728
+ } catch (e) {
3729
+ return [null, e];
3730
+ }
3731
+ }
3732
+
3726
3733
  // lib/components/primitive-components/Trace/Trace.ts
3727
- import "@tscircuit/math-utils";
3734
+ import "zod";
3728
3735
 
3729
- // lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
3730
- import { doesLineIntersectLine } from "@tscircuit/math-utils";
3736
+ // lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
3737
+ import { distance as distance2, doesLineIntersectLine } from "@tscircuit/math-utils";
3731
3738
 
3732
3739
  // lib/components/primitive-components/Trace/get-other-schematic-traces.ts
3733
3740
  var getOtherSchematicTraces = ({
@@ -3758,49 +3765,7 @@ var getOtherSchematicTraces = ({
3758
3765
  return traces;
3759
3766
  };
3760
3767
 
3761
- // lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
3762
- var pushEdgesOfSchematicTraceToPreventOverlap = ({
3763
- edges,
3764
- db,
3765
- source_trace_id
3766
- }) => {
3767
- const mySourceTrace = db.source_trace.get(source_trace_id);
3768
- const otherEdges = getOtherSchematicTraces({
3769
- db,
3770
- source_trace_id,
3771
- differentNetOnly: true
3772
- }).flatMap((t) => t.edges);
3773
- const edgeOrientation = (edge) => {
3774
- const { from, to } = edge;
3775
- return from.x === to.x ? "vertical" : "horizontal";
3776
- };
3777
- for (const mySegment of edges) {
3778
- const mySegmentOrientation = edgeOrientation(mySegment);
3779
- const findOverlappingParallelSegment = () => otherEdges.find(
3780
- (otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine(
3781
- [mySegment.from, mySegment.to],
3782
- [otherEdge.from, otherEdge.to],
3783
- {
3784
- lineThickness: 0.05
3785
- }
3786
- )
3787
- );
3788
- let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
3789
- while (overlappingParallelSegmentFromOtherTrace) {
3790
- if (mySegmentOrientation === "horizontal") {
3791
- mySegment.from.y += 0.1;
3792
- mySegment.to.y += 0.1;
3793
- } else {
3794
- mySegment.from.x += 0.1;
3795
- mySegment.to.x += 0.1;
3796
- }
3797
- overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
3798
- }
3799
- }
3800
- };
3801
-
3802
3768
  // lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
3803
- import { distance as distance2, doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
3804
3769
  import { getUnitVectorFromPointAToB } from "@tscircuit/math-utils";
3805
3770
  var createSchematicTraceCrossingSegments = ({
3806
3771
  edges,
@@ -3819,7 +3784,7 @@ var createSchematicTraceCrossingSegments = ({
3819
3784
  for (const otherEdge of otherEdges) {
3820
3785
  const otherOrientation = otherEdge.from.x === otherEdge.to.x ? "vertical" : "horizontal";
3821
3786
  if (edgeOrientation === otherOrientation) continue;
3822
- const hasIntersection = doesLineIntersectLine2(
3787
+ const hasIntersection = doesLineIntersectLine(
3823
3788
  [edge.from, edge.to],
3824
3789
  [otherEdge.from, otherEdge.to],
3825
3790
  { lineThickness: 0.01 }
@@ -3914,14 +3879,46 @@ var createSchematicTraceJunctions = ({
3914
3879
  });
3915
3880
  };
3916
3881
 
3917
- // lib/utils/schematic/getEnteringEdgeFromDirection.ts
3918
- var getEnteringEdgeFromDirection = (direction) => {
3919
- return {
3920
- up: "bottom",
3921
- down: "top",
3922
- left: "right",
3923
- right: "left"
3924
- }[direction] ?? null;
3882
+ // lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
3883
+ import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
3884
+ var pushEdgesOfSchematicTraceToPreventOverlap = ({
3885
+ edges,
3886
+ db,
3887
+ source_trace_id
3888
+ }) => {
3889
+ const mySourceTrace = db.source_trace.get(source_trace_id);
3890
+ const otherEdges = getOtherSchematicTraces({
3891
+ db,
3892
+ source_trace_id,
3893
+ differentNetOnly: true
3894
+ }).flatMap((t) => t.edges);
3895
+ const edgeOrientation = (edge) => {
3896
+ const { from, to } = edge;
3897
+ return from.x === to.x ? "vertical" : "horizontal";
3898
+ };
3899
+ for (const mySegment of edges) {
3900
+ const mySegmentOrientation = edgeOrientation(mySegment);
3901
+ const findOverlappingParallelSegment = () => otherEdges.find(
3902
+ (otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine2(
3903
+ [mySegment.from, mySegment.to],
3904
+ [otherEdge.from, otherEdge.to],
3905
+ {
3906
+ lineThickness: 0.05
3907
+ }
3908
+ )
3909
+ );
3910
+ let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
3911
+ while (overlappingParallelSegmentFromOtherTrace) {
3912
+ if (mySegmentOrientation === "horizontal") {
3913
+ mySegment.from.y += 0.1;
3914
+ mySegment.to.y += 0.1;
3915
+ } else {
3916
+ mySegment.from.x += 0.1;
3917
+ mySegment.to.x += 0.1;
3918
+ }
3919
+ overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
3920
+ }
3921
+ }
3925
3922
  };
3926
3923
 
3927
3924
  // lib/components/primitive-components/Trace/Trace.ts
@@ -4076,11 +4073,21 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
4076
4073
  doInitialPcbTraceRender() {
4077
4074
  const { db } = this.root;
4078
4075
  const { _parsedProps: props, parent } = this;
4076
+ const subcircuit = this.getSubcircuit();
4079
4077
  if (!parent) throw new Error("Trace has no parent");
4080
- if (this.getSubcircuit()._parsedProps.routingDisabled) {
4078
+ if (subcircuit._parsedProps.routingDisabled) {
4079
+ return;
4080
+ }
4081
+ const cachedRoute = subcircuit._parsedProps.pcbRouteCache?.pcbTraces;
4082
+ if (cachedRoute) {
4083
+ const pcb_trace2 = db.pcb_trace.insert({
4084
+ route: cachedRoute.flatMap((trace) => trace.route),
4085
+ source_trace_id: this.source_trace_id
4086
+ });
4087
+ this.pcb_trace_id = pcb_trace2.pcb_trace_id;
4081
4088
  return;
4082
4089
  }
4083
- if (!this.getSubcircuit()._shouldUseTraceByTraceRouting()) {
4090
+ if (!subcircuit._shouldUseTraceByTraceRouting()) {
4084
4091
  return;
4085
4092
  }
4086
4093
  const { allPortsFound, ports } = this._findConnectedPorts();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.191",
4
+ "version": "0.0.192",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@tscircuit/footprinter": "^0.0.77",
41
41
  "@tscircuit/infgrid-ijump-astar": "^0.0.24",
42
42
  "@tscircuit/math-utils": "^0.0.5",
43
- "@tscircuit/props": "^0.0.99",
43
+ "@tscircuit/props": "^0.0.101",
44
44
  "@tscircuit/schematic-autolayout": "^0.0.6",
45
45
  "@tscircuit/soup-util": "^0.0.40",
46
46
  "circuit-json": "^0.0.104",