@tscircuit/circuit-json-util 0.0.135 → 0.0.137

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
@@ -1,5 +1,5 @@
1
1
  import * as circuit_json from 'circuit-json';
2
- import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbSolderPastePill, PcbSolderPasteRotatedPill, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, Point as Point$2, PcbPlatedHole, PcbCopperPour, PcbSmtPad, SchematicLengthUnit } from 'circuit-json';
2
+ import { AnyCircuitElementInput, AnyCircuitElement, InsertionDirection, PcbSolderPasteRect, PcbSolderPasteRotatedRect, PcbSolderPastePill, PcbSolderPasteRotatedPill, PcbTrace, PcbDifferentialPairPhaseSkewTrace, LayerRef, Point as Point$2, PcbBoard, SchematicComponent, SchematicNetLabel, SchematicTrace, SourceGroup, SourceComponentBase, PcbRenderLayer, PcbVia, PcbPin1Location, PcbPlatedHole, PcbCopperPour, PcbSmtPad, SchematicLengthUnit } 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';
@@ -2266,6 +2266,45 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
2266
2266
  maximum_length_skew: number;
2267
2267
  subcircuit_id?: string | undefined;
2268
2268
  is_fatal?: boolean | undefined;
2269
+ } | {
2270
+ type: "pcb_differential_pair_phase_skew";
2271
+ source_bus_id: string;
2272
+ pcb_differential_pair_phase_skew_id: string;
2273
+ positive_trace: {
2274
+ pcb_trace_id: string;
2275
+ segments: {
2276
+ width: number;
2277
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
2278
+ start: {
2279
+ x: number;
2280
+ y: number;
2281
+ };
2282
+ end: {
2283
+ x: number;
2284
+ y: number;
2285
+ };
2286
+ start_length_difference_mm: number;
2287
+ end_length_difference_mm: number;
2288
+ }[];
2289
+ };
2290
+ negative_trace: {
2291
+ pcb_trace_id: string;
2292
+ segments: {
2293
+ width: number;
2294
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
2295
+ start: {
2296
+ x: number;
2297
+ y: number;
2298
+ };
2299
+ end: {
2300
+ x: number;
2301
+ y: number;
2302
+ };
2303
+ start_length_difference_mm: number;
2304
+ end_length_difference_mm: number;
2305
+ }[];
2306
+ };
2307
+ subcircuit_id?: string | undefined;
2269
2308
  } | {
2270
2309
  message: string;
2271
2310
  type: "pcb_trace_too_many_vias_warning";
@@ -3798,6 +3837,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
3798
3837
  schematic_component_id: string;
3799
3838
  is_box_with_pins: boolean;
3800
3839
  source_component_id?: string | undefined;
3840
+ do_not_place?: boolean | undefined;
3801
3841
  subcircuit_id?: string | undefined;
3802
3842
  metadata?: zod.objectOutputType<{
3803
3843
  kicad_symbol: zod.ZodOptional<zod.ZodObject<{
@@ -5749,6 +5789,7 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
5749
5789
  y: number;
5750
5790
  } | undefined;
5751
5791
  source_trace_id?: string | undefined;
5792
+ font_size?: number | undefined;
5752
5793
  schematic_length_unit?: "9.236363636363636mm" | "mm" | "in" | undefined;
5753
5794
  schematic_sheet_id?: string | undefined;
5754
5795
  symbol_name?: string | undefined;
@@ -6306,6 +6347,8 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
6306
6347
  allow_unrouted_traces: boolean;
6307
6348
  name?: string | undefined;
6308
6349
  duration_ms?: number | undefined;
6350
+ aggressor_pattern?: string | undefined;
6351
+ aggressor_disabled?: boolean | undefined;
6309
6352
  } | {
6310
6353
  type: "simulation_pcb_driver_receiver_channel";
6311
6354
  name: string;
@@ -8911,6 +8954,45 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
8911
8954
  maximum_length_skew: number;
8912
8955
  subcircuit_id?: string | undefined;
8913
8956
  is_fatal?: boolean | undefined;
8957
+ } | {
8958
+ type: "pcb_differential_pair_phase_skew";
8959
+ source_bus_id: string;
8960
+ pcb_differential_pair_phase_skew_id: string;
8961
+ positive_trace: {
8962
+ pcb_trace_id: string;
8963
+ segments: {
8964
+ width: number;
8965
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
8966
+ start: {
8967
+ x: number;
8968
+ y: number;
8969
+ };
8970
+ end: {
8971
+ x: number;
8972
+ y: number;
8973
+ };
8974
+ start_length_difference_mm: number;
8975
+ end_length_difference_mm: number;
8976
+ }[];
8977
+ };
8978
+ negative_trace: {
8979
+ pcb_trace_id: string;
8980
+ segments: {
8981
+ width: number;
8982
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
8983
+ start: {
8984
+ x: number;
8985
+ y: number;
8986
+ };
8987
+ end: {
8988
+ x: number;
8989
+ y: number;
8990
+ };
8991
+ start_length_difference_mm: number;
8992
+ end_length_difference_mm: number;
8993
+ }[];
8994
+ };
8995
+ subcircuit_id?: string | undefined;
8914
8996
  } | {
8915
8997
  message: string;
8916
8998
  type: "pcb_trace_too_many_vias_warning";
@@ -10443,6 +10525,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
10443
10525
  schematic_component_id: string;
10444
10526
  is_box_with_pins: boolean;
10445
10527
  source_component_id?: string | undefined;
10528
+ do_not_place?: boolean | undefined;
10446
10529
  subcircuit_id?: string | undefined;
10447
10530
  metadata?: zod.objectOutputType<{
10448
10531
  kicad_symbol: zod.ZodOptional<zod.ZodObject<{
@@ -12394,6 +12477,7 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
12394
12477
  y: number;
12395
12478
  } | undefined;
12396
12479
  source_trace_id?: string | undefined;
12480
+ font_size?: number | undefined;
12397
12481
  schematic_length_unit?: "9.236363636363636mm" | "mm" | "in" | undefined;
12398
12482
  schematic_sheet_id?: string | undefined;
12399
12483
  symbol_name?: string | undefined;
@@ -12951,6 +13035,8 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
12951
13035
  allow_unrouted_traces: boolean;
12952
13036
  name?: string | undefined;
12953
13037
  duration_ms?: number | undefined;
13038
+ aggressor_pattern?: string | undefined;
13039
+ aggressor_disabled?: boolean | undefined;
12954
13040
  } | {
12955
13041
  type: "simulation_pcb_driver_receiver_channel";
12956
13042
  name: string;
@@ -15195,6 +15281,45 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
15195
15281
  maximum_length_skew: number;
15196
15282
  subcircuit_id?: string | undefined;
15197
15283
  is_fatal?: boolean | undefined;
15284
+ } | {
15285
+ type: "pcb_differential_pair_phase_skew";
15286
+ source_bus_id: string;
15287
+ pcb_differential_pair_phase_skew_id: string;
15288
+ positive_trace: {
15289
+ pcb_trace_id: string;
15290
+ segments: {
15291
+ width: number;
15292
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
15293
+ start: {
15294
+ x: number;
15295
+ y: number;
15296
+ };
15297
+ end: {
15298
+ x: number;
15299
+ y: number;
15300
+ };
15301
+ start_length_difference_mm: number;
15302
+ end_length_difference_mm: number;
15303
+ }[];
15304
+ };
15305
+ negative_trace: {
15306
+ pcb_trace_id: string;
15307
+ segments: {
15308
+ width: number;
15309
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
15310
+ start: {
15311
+ x: number;
15312
+ y: number;
15313
+ };
15314
+ end: {
15315
+ x: number;
15316
+ y: number;
15317
+ };
15318
+ start_length_difference_mm: number;
15319
+ end_length_difference_mm: number;
15320
+ }[];
15321
+ };
15322
+ subcircuit_id?: string | undefined;
15198
15323
  } | {
15199
15324
  message: string;
15200
15325
  type: "pcb_trace_too_many_vias_warning";
@@ -16623,6 +16748,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
16623
16748
  schematic_component_id: string;
16624
16749
  is_box_with_pins: boolean;
16625
16750
  source_component_id?: string | undefined;
16751
+ do_not_place?: boolean | undefined;
16626
16752
  subcircuit_id?: string | undefined;
16627
16753
  metadata?: zod.objectOutputType<{
16628
16754
  kicad_symbol: zod.ZodOptional<zod.ZodObject<{
@@ -18574,6 +18700,7 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
18574
18700
  y: number;
18575
18701
  } | undefined;
18576
18702
  source_trace_id?: string | undefined;
18703
+ font_size?: number | undefined;
18577
18704
  schematic_length_unit?: "9.236363636363636mm" | "mm" | "in" | undefined;
18578
18705
  schematic_sheet_id?: string | undefined;
18579
18706
  symbol_name?: string | undefined;
@@ -19131,6 +19258,8 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
19131
19258
  allow_unrouted_traces: boolean;
19132
19259
  name?: string | undefined;
19133
19260
  duration_ms?: number | undefined;
19261
+ aggressor_pattern?: string | undefined;
19262
+ aggressor_disabled?: boolean | undefined;
19134
19263
  } | {
19135
19264
  type: "simulation_pcb_driver_receiver_channel";
19136
19265
  name: string;
@@ -21375,6 +21504,45 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
21375
21504
  maximum_length_skew: number;
21376
21505
  subcircuit_id?: string | undefined;
21377
21506
  is_fatal?: boolean | undefined;
21507
+ } | {
21508
+ type: "pcb_differential_pair_phase_skew";
21509
+ source_bus_id: string;
21510
+ pcb_differential_pair_phase_skew_id: string;
21511
+ positive_trace: {
21512
+ pcb_trace_id: string;
21513
+ segments: {
21514
+ width: number;
21515
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
21516
+ start: {
21517
+ x: number;
21518
+ y: number;
21519
+ };
21520
+ end: {
21521
+ x: number;
21522
+ y: number;
21523
+ };
21524
+ start_length_difference_mm: number;
21525
+ end_length_difference_mm: number;
21526
+ }[];
21527
+ };
21528
+ negative_trace: {
21529
+ pcb_trace_id: string;
21530
+ segments: {
21531
+ width: number;
21532
+ layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
21533
+ start: {
21534
+ x: number;
21535
+ y: number;
21536
+ };
21537
+ end: {
21538
+ x: number;
21539
+ y: number;
21540
+ };
21541
+ start_length_difference_mm: number;
21542
+ end_length_difference_mm: number;
21543
+ }[];
21544
+ };
21545
+ subcircuit_id?: string | undefined;
21378
21546
  } | {
21379
21547
  message: string;
21380
21548
  type: "pcb_trace_too_many_vias_warning";
@@ -22803,6 +22971,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
22803
22971
  schematic_component_id: string;
22804
22972
  is_box_with_pins: boolean;
22805
22973
  source_component_id?: string | undefined;
22974
+ do_not_place?: boolean | undefined;
22806
22975
  subcircuit_id?: string | undefined;
22807
22976
  metadata?: zod.objectOutputType<{
22808
22977
  kicad_symbol: zod.ZodOptional<zod.ZodObject<{
@@ -24754,6 +24923,7 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
24754
24923
  y: number;
24755
24924
  } | undefined;
24756
24925
  source_trace_id?: string | undefined;
24926
+ font_size?: number | undefined;
24757
24927
  schematic_length_unit?: "9.236363636363636mm" | "mm" | "in" | undefined;
24758
24928
  schematic_sheet_id?: string | undefined;
24759
24929
  symbol_name?: string | undefined;
@@ -25311,6 +25481,8 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
25311
25481
  allow_unrouted_traces: boolean;
25312
25482
  name?: string | undefined;
25313
25483
  duration_ms?: number | undefined;
25484
+ aggressor_pattern?: string | undefined;
25485
+ aggressor_disabled?: boolean | undefined;
25314
25486
  } | {
25315
25487
  type: "simulation_pcb_driver_receiver_channel";
25316
25488
  name: string;
@@ -25757,6 +25929,36 @@ declare const getElementById: (soup: AnyCircuitElement[], id: string) => AnyCirc
25757
25929
 
25758
25930
  declare const getElementId: (elm: AnyCircuitElement) => string;
25759
25931
 
25932
+ type TraceId = PcbTrace["pcb_trace_id"];
25933
+ type MeasuredTrace = {
25934
+ trace: PcbDifferentialPairPhaseSkewTrace;
25935
+ maxLengthSkew?: number;
25936
+ };
25937
+ type PcbPhaseSkewIndex = ReadonlyMap<TraceId, MeasuredTrace>;
25938
+ /** Resolve measurements against the copper in this scene, in any element order. */
25939
+ declare function createPcbPhaseSkewIndex(elements: readonly AnyCircuitElement[]): PcbPhaseSkewIndex;
25940
+ type Segment = {
25941
+ start: Point$2;
25942
+ end: Point$2;
25943
+ };
25944
+ /**
25945
+ * Sample the measured copper under a pick. Candidates are the caller's copper
25946
+ * hits on this layer. Supply the centerline for a wire picked with a mouse
25947
+ * tolerance, or just the trace ID for a point already inside a copper shape.
25948
+ */
25949
+ declare function getPcbPhaseSkewAtPoint({ index, layer, point, candidates, }: {
25950
+ index: PcbPhaseSkewIndex;
25951
+ layer: LayerRef;
25952
+ point: Point$2;
25953
+ candidates: Iterable<{
25954
+ pcbTraceId: TraceId;
25955
+ centerline?: Segment;
25956
+ }>;
25957
+ }): {
25958
+ pcbTraceId: TraceId;
25959
+ differenceMm: number;
25960
+ } | undefined;
25961
+
25760
25962
  declare const getReadableNameForPcbPort: (soup: AnyCircuitElement[], pcb_port_id: string) => string;
25761
25963
 
25762
25964
  declare function getReadableNameForPcbSmtpad(soup: AnyCircuitElement[], pcb_smtpad_id: string): string;
@@ -26012,4 +26214,4 @@ declare function convertSchematicLengthUnit(element: AnyCircuitElement, unit: Sc
26012
26214
  /** Read geometry in one coordinate system before layout, bounds, or rendering. */
26013
26215
  declare function convertSchematicLengthUnits(circuit: AnyCircuitElement[], unit: SchematicLengthUnit): AnyCircuitElement[];
26014
26216
 
26015
- export { type AnyCircuitJsonId, 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, convertSchematicLengthUnit, convertSchematicLengthUnits, copperPolygonsTouch, createBoardOwnerMap, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSchematicLengthUnitScale, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, isRouteViaCoveredByPhysicalVia, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
26217
+ export { type AnyCircuitJsonId, type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPhaseSkewIndex, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, convertSchematicLengthUnit, convertSchematicLengthUnits, copperPolygonsTouch, createBoardOwnerMap, createPcbPhaseSkewIndex, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPcbPhaseSkewAtPoint, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSchematicLengthUnitScale, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, isRouteViaCoveredByPhysicalVia, 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
@@ -1437,6 +1437,158 @@ var getElementById = (soup, id) => {
1437
1437
  return soup.find((elm) => getElementId(elm) === id) ?? null;
1438
1438
  };
1439
1439
 
1440
+ // lib/shape-distances/geometry.ts
1441
+ var EPSILON = 1e-9;
1442
+ var toRadians = (degrees) => degrees * Math.PI / 180;
1443
+ var clamp = (value, min, max) => Math.max(min, Math.min(max, value));
1444
+ var distanceBetweenPoints = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
1445
+ var distanceBetweenPointAndSegment = (point, a, b) => {
1446
+ const abX = b.x - a.x;
1447
+ const abY = b.y - a.y;
1448
+ const lengthSquared = abX * abX + abY * abY;
1449
+ if (lengthSquared <= EPSILON) return distanceBetweenPoints(point, a);
1450
+ const t = clamp(
1451
+ ((point.x - a.x) * abX + (point.y - a.y) * abY) / lengthSquared,
1452
+ 0,
1453
+ 1
1454
+ );
1455
+ return Math.hypot(point.x - (a.x + t * abX), point.y - (a.y + t * abY));
1456
+ };
1457
+ var cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
1458
+ var isPointOnSegment = (point, a, b) => {
1459
+ if (Math.abs(cross(a, b, point)) > EPSILON) return false;
1460
+ return point.x >= Math.min(a.x, b.x) - EPSILON && point.x <= Math.max(a.x, b.x) + EPSILON && point.y >= Math.min(a.y, b.y) - EPSILON && point.y <= Math.max(a.y, b.y) + EPSILON;
1461
+ };
1462
+ var segmentsIntersect = (a1, a2, b1, b2) => {
1463
+ const c1 = cross(a1, a2, b1);
1464
+ const c2 = cross(a1, a2, b2);
1465
+ const c3 = cross(b1, b2, a1);
1466
+ const c4 = cross(b1, b2, a2);
1467
+ if ((c1 > EPSILON && c2 < -EPSILON || c1 < -EPSILON && c2 > EPSILON) && (c3 > EPSILON && c4 < -EPSILON || c3 < -EPSILON && c4 > EPSILON)) {
1468
+ return true;
1469
+ }
1470
+ return isPointOnSegment(b1, a1, a2) || isPointOnSegment(b2, a1, a2) || isPointOnSegment(a1, b1, b2) || isPointOnSegment(a2, b1, b2);
1471
+ };
1472
+ var getPolygonEdges = (polygon) => {
1473
+ const edges = [];
1474
+ if (polygon.points.length < 2) return edges;
1475
+ for (let i = 0; i < polygon.points.length; i += 1) {
1476
+ const a = polygon.points[i];
1477
+ const b = polygon.points[(i + 1) % polygon.points.length];
1478
+ if (!a || !b) continue;
1479
+ edges.push([a, b]);
1480
+ }
1481
+ return edges;
1482
+ };
1483
+ var isPointInPolygon = (point, polygon) => {
1484
+ for (const [a, b] of getPolygonEdges(polygon)) {
1485
+ if (isPointOnSegment(point, a, b)) return true;
1486
+ }
1487
+ let inside = false;
1488
+ for (let i = 0, j = polygon.points.length - 1; i < polygon.points.length; j = i++) {
1489
+ const pi = polygon.points[i];
1490
+ const pj = polygon.points[j];
1491
+ if (!pi || !pj) continue;
1492
+ const intersects = pi.y > point.y !== pj.y > point.y && point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x;
1493
+ if (intersects) inside = !inside;
1494
+ }
1495
+ return inside;
1496
+ };
1497
+ var rotatePoint = (point, angleRadians) => ({
1498
+ x: point.x * Math.cos(angleRadians) - point.y * Math.sin(angleRadians),
1499
+ y: point.x * Math.sin(angleRadians) + point.y * Math.cos(angleRadians)
1500
+ });
1501
+ var rectToPolygon = (rect) => {
1502
+ const halfWidth = rect.width / 2;
1503
+ const halfHeight = rect.height / 2;
1504
+ const angle = toRadians(rect.rotationDegrees);
1505
+ return {
1506
+ kind: "polygon",
1507
+ points: [
1508
+ { x: -halfWidth, y: -halfHeight },
1509
+ { x: halfWidth, y: -halfHeight },
1510
+ { x: halfWidth, y: halfHeight },
1511
+ { x: -halfWidth, y: halfHeight }
1512
+ ].map((localPoint) => {
1513
+ const rotated = rotatePoint(localPoint, angle);
1514
+ return { x: rect.centerX + rotated.x, y: rect.centerY + rotated.y };
1515
+ })
1516
+ };
1517
+ };
1518
+
1519
+ // lib/pcb-phase-skew.ts
1520
+ function createPcbPhaseSkewIndex(elements) {
1521
+ const traceIds = /* @__PURE__ */ new Set();
1522
+ const limits = /* @__PURE__ */ new Map();
1523
+ const pairs = [];
1524
+ for (const element of elements) {
1525
+ if (element.type === "pcb_trace") traceIds.add(element.pcb_trace_id);
1526
+ if (element.type === "source_bus")
1527
+ limits.set(element.source_bus_id, element.max_length_skew);
1528
+ if (element.type === "pcb_differential_pair_phase_skew") pairs.push(element);
1529
+ }
1530
+ const index = /* @__PURE__ */ new Map();
1531
+ for (const pair of pairs) {
1532
+ const { positive_trace, negative_trace } = pair;
1533
+ if (!Array.isArray(positive_trace?.segments) || !Array.isArray(negative_trace?.segments) || !traceIds.has(positive_trace.pcb_trace_id) || !traceIds.has(negative_trace.pcb_trace_id))
1534
+ continue;
1535
+ const maxLengthSkew = limits.get(pair.source_bus_id);
1536
+ for (const trace of [positive_trace, negative_trace]) {
1537
+ index.set(trace.pcb_trace_id, { trace, maxLengthSkew });
1538
+ }
1539
+ }
1540
+ return index;
1541
+ }
1542
+ function project(point, { start, end }) {
1543
+ const dx = end.x - start.x;
1544
+ const dy = end.y - start.y;
1545
+ const lengthSquared = dx * dx + dy * dy;
1546
+ const fraction = lengthSquared === 0 ? 0 : clamp(
1547
+ ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared,
1548
+ 0,
1549
+ 1
1550
+ );
1551
+ const x = start.x + fraction * dx;
1552
+ const y = start.y + fraction * dy;
1553
+ return { x, y, fraction, distance: Math.hypot(point.x - x, point.y - y) };
1554
+ }
1555
+ function getPcbPhaseSkewAtPoint({
1556
+ index,
1557
+ layer,
1558
+ point,
1559
+ candidates
1560
+ }) {
1561
+ let nearestDistance = Infinity;
1562
+ let pickedPoint = point;
1563
+ let traceId;
1564
+ for (const { pcbTraceId, centerline } of candidates) {
1565
+ const projection = centerline && project(point, centerline);
1566
+ const distance = projection?.distance ?? 0;
1567
+ if (distance >= nearestDistance) continue;
1568
+ nearestDistance = distance;
1569
+ pickedPoint = projection ?? point;
1570
+ traceId = pcbTraceId;
1571
+ }
1572
+ if (traceId === void 0) return;
1573
+ const entry = index.get(traceId);
1574
+ if (!entry) return;
1575
+ let nearestSegmentDistance = Infinity;
1576
+ let hit;
1577
+ for (const segment of entry.trace.segments) {
1578
+ if (segment.layer !== layer || segment.width <= 0) continue;
1579
+ if (segment.start.x === segment.end.x && segment.start.y === segment.end.y)
1580
+ continue;
1581
+ const { fraction, distance } = project(pickedPoint, segment);
1582
+ if (!(distance <= segment.width / 2 && distance < nearestSegmentDistance))
1583
+ continue;
1584
+ const differenceMm = segment.start_length_difference_mm + fraction * (segment.end_length_difference_mm - segment.start_length_difference_mm);
1585
+ if (!Number.isFinite(differenceMm)) continue;
1586
+ nearestSegmentDistance = distance;
1587
+ hit = { pcbTraceId: traceId, differenceMm };
1588
+ }
1589
+ return hit;
1590
+ }
1591
+
1440
1592
  // lib/readable-name-functions/get-readable-name-for-pcb-port.ts
1441
1593
  var getReadableNameForPcbPort = (soup, pcb_port_id) => {
1442
1594
  const pcbPort = cju(soup).pcb_port.get(pcb_port_id);
@@ -1938,18 +2090,15 @@ var createBounds = ({
1938
2090
  }
1939
2091
  };
1940
2092
  };
1941
- var getSchematicNetLabelTextWidth = (text) => {
1942
- const characterWidth = 0.12 * (SCHEMATIC_NET_LABEL_FONT_SIZE / 0.18);
1943
- const horizontalPadding = 0.12 * (SCHEMATIC_NET_LABEL_FONT_SIZE / 0.18);
1944
- return text.length * characterWidth + horizontalPadding;
1945
- };
1946
2093
  var getSchematicNetLabelBounds = (netLabel) => {
1947
- const labelLength = getSchematicNetLabelTextWidth(netLabel.text);
2094
+ const scale2 = (netLabel.font_size ?? SCHEMATIC_NET_LABEL_FONT_SIZE) / SCHEMATIC_NET_LABEL_FONT_SIZE;
2095
+ const labelLength = (netLabel.text.length + 1) * 0.12 * scale2;
2096
+ const labelHeight = SCHEMATIC_NET_LABEL_HEIGHT * scale2;
1948
2097
  const anchor = netLabel.anchor_position;
1949
2098
  if (!anchor) {
1950
2099
  const isVertical = netLabel.anchor_side === "top" || netLabel.anchor_side === "bottom";
1951
- const width = isVertical ? SCHEMATIC_NET_LABEL_HEIGHT : labelLength;
1952
- const height = isVertical ? labelLength : SCHEMATIC_NET_LABEL_HEIGHT;
2100
+ const width = isVertical ? labelHeight : labelLength;
2101
+ const height = isVertical ? labelLength : labelHeight;
1953
2102
  return createBounds({
1954
2103
  minX: netLabel.center.x - width / 2,
1955
2104
  minY: netLabel.center.y - height / 2,
@@ -1961,29 +2110,29 @@ var getSchematicNetLabelBounds = (netLabel) => {
1961
2110
  case "left":
1962
2111
  return createBounds({
1963
2112
  minX: anchor.x,
1964
- minY: anchor.y - SCHEMATIC_NET_LABEL_HEIGHT / 2,
2113
+ minY: anchor.y - labelHeight / 2,
1965
2114
  maxX: anchor.x + labelLength,
1966
- maxY: anchor.y + SCHEMATIC_NET_LABEL_HEIGHT / 2
2115
+ maxY: anchor.y + labelHeight / 2
1967
2116
  });
1968
2117
  case "right":
1969
2118
  return createBounds({
1970
2119
  minX: anchor.x - labelLength,
1971
- minY: anchor.y - SCHEMATIC_NET_LABEL_HEIGHT / 2,
2120
+ minY: anchor.y - labelHeight / 2,
1972
2121
  maxX: anchor.x,
1973
- maxY: anchor.y + SCHEMATIC_NET_LABEL_HEIGHT / 2
2122
+ maxY: anchor.y + labelHeight / 2
1974
2123
  });
1975
2124
  case "top":
1976
2125
  return createBounds({
1977
- minX: anchor.x - SCHEMATIC_NET_LABEL_HEIGHT / 2,
2126
+ minX: anchor.x - labelHeight / 2,
1978
2127
  minY: anchor.y - labelLength,
1979
- maxX: anchor.x + SCHEMATIC_NET_LABEL_HEIGHT / 2,
2128
+ maxX: anchor.x + labelHeight / 2,
1980
2129
  maxY: anchor.y
1981
2130
  });
1982
2131
  case "bottom":
1983
2132
  return createBounds({
1984
- minX: anchor.x - SCHEMATIC_NET_LABEL_HEIGHT / 2,
2133
+ minX: anchor.x - labelHeight / 2,
1985
2134
  minY: anchor.y,
1986
- maxX: anchor.x + SCHEMATIC_NET_LABEL_HEIGHT / 2,
2135
+ maxX: anchor.x + labelHeight / 2,
1987
2136
  maxY: anchor.y + labelLength
1988
2137
  });
1989
2138
  }
@@ -2627,85 +2776,6 @@ function isRouteViaCoveredByPhysicalVia(viaWithLayersOrOptions, legacyRouteVia)
2627
2776
  return viaTopDepth < viaBottomDepth && fromLayerDepth !== toLayerDepth && viaTopDepth <= Math.min(fromLayerDepth, toLayerDepth) && viaBottomDepth >= Math.max(fromLayerDepth, toLayerDepth);
2628
2777
  }
2629
2778
 
2630
- // lib/shape-distances/geometry.ts
2631
- var EPSILON = 1e-9;
2632
- var toRadians = (degrees) => degrees * Math.PI / 180;
2633
- var clamp = (value, min, max) => Math.max(min, Math.min(max, value));
2634
- var distanceBetweenPoints = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
2635
- var distanceBetweenPointAndSegment = (point, a, b) => {
2636
- const abX = b.x - a.x;
2637
- const abY = b.y - a.y;
2638
- const lengthSquared = abX * abX + abY * abY;
2639
- if (lengthSquared <= EPSILON) return distanceBetweenPoints(point, a);
2640
- const t = clamp(
2641
- ((point.x - a.x) * abX + (point.y - a.y) * abY) / lengthSquared,
2642
- 0,
2643
- 1
2644
- );
2645
- return Math.hypot(point.x - (a.x + t * abX), point.y - (a.y + t * abY));
2646
- };
2647
- var cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
2648
- var isPointOnSegment = (point, a, b) => {
2649
- if (Math.abs(cross(a, b, point)) > EPSILON) return false;
2650
- return point.x >= Math.min(a.x, b.x) - EPSILON && point.x <= Math.max(a.x, b.x) + EPSILON && point.y >= Math.min(a.y, b.y) - EPSILON && point.y <= Math.max(a.y, b.y) + EPSILON;
2651
- };
2652
- var segmentsIntersect = (a1, a2, b1, b2) => {
2653
- const c1 = cross(a1, a2, b1);
2654
- const c2 = cross(a1, a2, b2);
2655
- const c3 = cross(b1, b2, a1);
2656
- const c4 = cross(b1, b2, a2);
2657
- if ((c1 > EPSILON && c2 < -EPSILON || c1 < -EPSILON && c2 > EPSILON) && (c3 > EPSILON && c4 < -EPSILON || c3 < -EPSILON && c4 > EPSILON)) {
2658
- return true;
2659
- }
2660
- return isPointOnSegment(b1, a1, a2) || isPointOnSegment(b2, a1, a2) || isPointOnSegment(a1, b1, b2) || isPointOnSegment(a2, b1, b2);
2661
- };
2662
- var getPolygonEdges = (polygon) => {
2663
- const edges = [];
2664
- if (polygon.points.length < 2) return edges;
2665
- for (let i = 0; i < polygon.points.length; i += 1) {
2666
- const a = polygon.points[i];
2667
- const b = polygon.points[(i + 1) % polygon.points.length];
2668
- if (!a || !b) continue;
2669
- edges.push([a, b]);
2670
- }
2671
- return edges;
2672
- };
2673
- var isPointInPolygon = (point, polygon) => {
2674
- for (const [a, b] of getPolygonEdges(polygon)) {
2675
- if (isPointOnSegment(point, a, b)) return true;
2676
- }
2677
- let inside = false;
2678
- for (let i = 0, j = polygon.points.length - 1; i < polygon.points.length; j = i++) {
2679
- const pi = polygon.points[i];
2680
- const pj = polygon.points[j];
2681
- if (!pi || !pj) continue;
2682
- const intersects = pi.y > point.y !== pj.y > point.y && point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x;
2683
- if (intersects) inside = !inside;
2684
- }
2685
- return inside;
2686
- };
2687
- var rotatePoint = (point, angleRadians) => ({
2688
- x: point.x * Math.cos(angleRadians) - point.y * Math.sin(angleRadians),
2689
- y: point.x * Math.sin(angleRadians) + point.y * Math.cos(angleRadians)
2690
- });
2691
- var rectToPolygon = (rect) => {
2692
- const halfWidth = rect.width / 2;
2693
- const halfHeight = rect.height / 2;
2694
- const angle = toRadians(rect.rotationDegrees);
2695
- return {
2696
- kind: "polygon",
2697
- points: [
2698
- { x: -halfWidth, y: -halfHeight },
2699
- { x: halfWidth, y: -halfHeight },
2700
- { x: halfWidth, y: halfHeight },
2701
- { x: -halfWidth, y: halfHeight }
2702
- ].map((localPoint) => {
2703
- const rotated = rotatePoint(localPoint, angle);
2704
- return { x: rect.centerX + rotated.x, y: rect.centerY + rotated.y };
2705
- })
2706
- };
2707
- };
2708
-
2709
2779
  // lib/shape-distances/decompose-copper-into-shapes.ts
2710
2780
  var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
2711
2781
  var createWireSegmentRect = (start, end, width) => ({
@@ -3426,7 +3496,7 @@ function convertSchematicLengthUnit(element, unit) {
3426
3496
  };
3427
3497
  case "schematic_net_label":
3428
3498
  return {
3429
- ...element,
3499
+ ...lengths(element, "font_size"),
3430
3500
  ...tag,
3431
3501
  center: point(element.center),
3432
3502
  ...element.anchor_position && {
@@ -3596,6 +3666,7 @@ export {
3596
3666
  convertSchematicLengthUnits,
3597
3667
  copperPolygonsTouch,
3598
3668
  createBoardOwnerMap,
3669
+ createPcbPhaseSkewIndex,
3599
3670
  directionToVec,
3600
3671
  distanceBetweenCircleAndCircle,
3601
3672
  distanceBetweenCircleAndPolygon,
@@ -3611,6 +3682,7 @@ export {
3611
3682
  getMinimumFlexContainer,
3612
3683
  getPcbElementBounds,
3613
3684
  getPcbElementsWithinBounds,
3685
+ getPcbPhaseSkewAtPoint,
3614
3686
  getPlatedHolePolygon,
3615
3687
  getPourPolygon,
3616
3688
  getPrimaryId,