@tscircuit/circuit-json-util 0.0.135 → 0.0.136
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 +196 -2
- package/dist/index.js +154 -79
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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,
|
|
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";
|
|
@@ -6306,6 +6345,8 @@ declare const transformSchematicElement: (elm: AnyCircuitElement, matrix: Matrix
|
|
|
6306
6345
|
allow_unrouted_traces: boolean;
|
|
6307
6346
|
name?: string | undefined;
|
|
6308
6347
|
duration_ms?: number | undefined;
|
|
6348
|
+
aggressor_pattern?: string | undefined;
|
|
6349
|
+
aggressor_disabled?: boolean | undefined;
|
|
6309
6350
|
} | {
|
|
6310
6351
|
type: "simulation_pcb_driver_receiver_channel";
|
|
6311
6352
|
name: string;
|
|
@@ -8911,6 +8952,45 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
|
|
|
8911
8952
|
maximum_length_skew: number;
|
|
8912
8953
|
subcircuit_id?: string | undefined;
|
|
8913
8954
|
is_fatal?: boolean | undefined;
|
|
8955
|
+
} | {
|
|
8956
|
+
type: "pcb_differential_pair_phase_skew";
|
|
8957
|
+
source_bus_id: string;
|
|
8958
|
+
pcb_differential_pair_phase_skew_id: string;
|
|
8959
|
+
positive_trace: {
|
|
8960
|
+
pcb_trace_id: string;
|
|
8961
|
+
segments: {
|
|
8962
|
+
width: number;
|
|
8963
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
8964
|
+
start: {
|
|
8965
|
+
x: number;
|
|
8966
|
+
y: number;
|
|
8967
|
+
};
|
|
8968
|
+
end: {
|
|
8969
|
+
x: number;
|
|
8970
|
+
y: number;
|
|
8971
|
+
};
|
|
8972
|
+
start_length_difference_mm: number;
|
|
8973
|
+
end_length_difference_mm: number;
|
|
8974
|
+
}[];
|
|
8975
|
+
};
|
|
8976
|
+
negative_trace: {
|
|
8977
|
+
pcb_trace_id: string;
|
|
8978
|
+
segments: {
|
|
8979
|
+
width: number;
|
|
8980
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
8981
|
+
start: {
|
|
8982
|
+
x: number;
|
|
8983
|
+
y: number;
|
|
8984
|
+
};
|
|
8985
|
+
end: {
|
|
8986
|
+
x: number;
|
|
8987
|
+
y: number;
|
|
8988
|
+
};
|
|
8989
|
+
start_length_difference_mm: number;
|
|
8990
|
+
end_length_difference_mm: number;
|
|
8991
|
+
}[];
|
|
8992
|
+
};
|
|
8993
|
+
subcircuit_id?: string | undefined;
|
|
8914
8994
|
} | {
|
|
8915
8995
|
message: string;
|
|
8916
8996
|
type: "pcb_trace_too_many_vias_warning";
|
|
@@ -12951,6 +13031,8 @@ declare const transformSchematicElements: (elms: AnyCircuitElement[], matrix: Ma
|
|
|
12951
13031
|
allow_unrouted_traces: boolean;
|
|
12952
13032
|
name?: string | undefined;
|
|
12953
13033
|
duration_ms?: number | undefined;
|
|
13034
|
+
aggressor_pattern?: string | undefined;
|
|
13035
|
+
aggressor_disabled?: boolean | undefined;
|
|
12954
13036
|
} | {
|
|
12955
13037
|
type: "simulation_pcb_driver_receiver_channel";
|
|
12956
13038
|
name: string;
|
|
@@ -15195,6 +15277,45 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
|
|
|
15195
15277
|
maximum_length_skew: number;
|
|
15196
15278
|
subcircuit_id?: string | undefined;
|
|
15197
15279
|
is_fatal?: boolean | undefined;
|
|
15280
|
+
} | {
|
|
15281
|
+
type: "pcb_differential_pair_phase_skew";
|
|
15282
|
+
source_bus_id: string;
|
|
15283
|
+
pcb_differential_pair_phase_skew_id: string;
|
|
15284
|
+
positive_trace: {
|
|
15285
|
+
pcb_trace_id: string;
|
|
15286
|
+
segments: {
|
|
15287
|
+
width: number;
|
|
15288
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
15289
|
+
start: {
|
|
15290
|
+
x: number;
|
|
15291
|
+
y: number;
|
|
15292
|
+
};
|
|
15293
|
+
end: {
|
|
15294
|
+
x: number;
|
|
15295
|
+
y: number;
|
|
15296
|
+
};
|
|
15297
|
+
start_length_difference_mm: number;
|
|
15298
|
+
end_length_difference_mm: number;
|
|
15299
|
+
}[];
|
|
15300
|
+
};
|
|
15301
|
+
negative_trace: {
|
|
15302
|
+
pcb_trace_id: string;
|
|
15303
|
+
segments: {
|
|
15304
|
+
width: number;
|
|
15305
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
15306
|
+
start: {
|
|
15307
|
+
x: number;
|
|
15308
|
+
y: number;
|
|
15309
|
+
};
|
|
15310
|
+
end: {
|
|
15311
|
+
x: number;
|
|
15312
|
+
y: number;
|
|
15313
|
+
};
|
|
15314
|
+
start_length_difference_mm: number;
|
|
15315
|
+
end_length_difference_mm: number;
|
|
15316
|
+
}[];
|
|
15317
|
+
};
|
|
15318
|
+
subcircuit_id?: string | undefined;
|
|
15198
15319
|
} | {
|
|
15199
15320
|
message: string;
|
|
15200
15321
|
type: "pcb_trace_too_many_vias_warning";
|
|
@@ -19131,6 +19252,8 @@ declare const transformPCBElement: (elm: AnyCircuitElement, matrix: Matrix) => {
|
|
|
19131
19252
|
allow_unrouted_traces: boolean;
|
|
19132
19253
|
name?: string | undefined;
|
|
19133
19254
|
duration_ms?: number | undefined;
|
|
19255
|
+
aggressor_pattern?: string | undefined;
|
|
19256
|
+
aggressor_disabled?: boolean | undefined;
|
|
19134
19257
|
} | {
|
|
19135
19258
|
type: "simulation_pcb_driver_receiver_channel";
|
|
19136
19259
|
name: string;
|
|
@@ -21375,6 +21498,45 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
|
|
|
21375
21498
|
maximum_length_skew: number;
|
|
21376
21499
|
subcircuit_id?: string | undefined;
|
|
21377
21500
|
is_fatal?: boolean | undefined;
|
|
21501
|
+
} | {
|
|
21502
|
+
type: "pcb_differential_pair_phase_skew";
|
|
21503
|
+
source_bus_id: string;
|
|
21504
|
+
pcb_differential_pair_phase_skew_id: string;
|
|
21505
|
+
positive_trace: {
|
|
21506
|
+
pcb_trace_id: string;
|
|
21507
|
+
segments: {
|
|
21508
|
+
width: number;
|
|
21509
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
21510
|
+
start: {
|
|
21511
|
+
x: number;
|
|
21512
|
+
y: number;
|
|
21513
|
+
};
|
|
21514
|
+
end: {
|
|
21515
|
+
x: number;
|
|
21516
|
+
y: number;
|
|
21517
|
+
};
|
|
21518
|
+
start_length_difference_mm: number;
|
|
21519
|
+
end_length_difference_mm: number;
|
|
21520
|
+
}[];
|
|
21521
|
+
};
|
|
21522
|
+
negative_trace: {
|
|
21523
|
+
pcb_trace_id: string;
|
|
21524
|
+
segments: {
|
|
21525
|
+
width: number;
|
|
21526
|
+
layer: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | "inner7" | "inner8";
|
|
21527
|
+
start: {
|
|
21528
|
+
x: number;
|
|
21529
|
+
y: number;
|
|
21530
|
+
};
|
|
21531
|
+
end: {
|
|
21532
|
+
x: number;
|
|
21533
|
+
y: number;
|
|
21534
|
+
};
|
|
21535
|
+
start_length_difference_mm: number;
|
|
21536
|
+
end_length_difference_mm: number;
|
|
21537
|
+
}[];
|
|
21538
|
+
};
|
|
21539
|
+
subcircuit_id?: string | undefined;
|
|
21378
21540
|
} | {
|
|
21379
21541
|
message: string;
|
|
21380
21542
|
type: "pcb_trace_too_many_vias_warning";
|
|
@@ -25311,6 +25473,8 @@ declare const transformPCBElements: (elms: AnyCircuitElement[], matrix: Matrix)
|
|
|
25311
25473
|
allow_unrouted_traces: boolean;
|
|
25312
25474
|
name?: string | undefined;
|
|
25313
25475
|
duration_ms?: number | undefined;
|
|
25476
|
+
aggressor_pattern?: string | undefined;
|
|
25477
|
+
aggressor_disabled?: boolean | undefined;
|
|
25314
25478
|
} | {
|
|
25315
25479
|
type: "simulation_pcb_driver_receiver_channel";
|
|
25316
25480
|
name: string;
|
|
@@ -25757,6 +25921,36 @@ declare const getElementById: (soup: AnyCircuitElement[], id: string) => AnyCirc
|
|
|
25757
25921
|
|
|
25758
25922
|
declare const getElementId: (elm: AnyCircuitElement) => string;
|
|
25759
25923
|
|
|
25924
|
+
type TraceId = PcbTrace["pcb_trace_id"];
|
|
25925
|
+
type MeasuredTrace = {
|
|
25926
|
+
trace: PcbDifferentialPairPhaseSkewTrace;
|
|
25927
|
+
maxLengthSkew?: number;
|
|
25928
|
+
};
|
|
25929
|
+
type PcbPhaseSkewIndex = ReadonlyMap<TraceId, MeasuredTrace>;
|
|
25930
|
+
/** Resolve measurements against the copper in this scene, in any element order. */
|
|
25931
|
+
declare function createPcbPhaseSkewIndex(elements: readonly AnyCircuitElement[]): PcbPhaseSkewIndex;
|
|
25932
|
+
type Segment = {
|
|
25933
|
+
start: Point$2;
|
|
25934
|
+
end: Point$2;
|
|
25935
|
+
};
|
|
25936
|
+
/**
|
|
25937
|
+
* Sample the measured copper under a pick. Candidates are the caller's copper
|
|
25938
|
+
* hits on this layer. Supply the centerline for a wire picked with a mouse
|
|
25939
|
+
* tolerance, or just the trace ID for a point already inside a copper shape.
|
|
25940
|
+
*/
|
|
25941
|
+
declare function getPcbPhaseSkewAtPoint({ index, layer, point, candidates, }: {
|
|
25942
|
+
index: PcbPhaseSkewIndex;
|
|
25943
|
+
layer: LayerRef;
|
|
25944
|
+
point: Point$2;
|
|
25945
|
+
candidates: Iterable<{
|
|
25946
|
+
pcbTraceId: TraceId;
|
|
25947
|
+
centerline?: Segment;
|
|
25948
|
+
}>;
|
|
25949
|
+
}): {
|
|
25950
|
+
pcbTraceId: TraceId;
|
|
25951
|
+
differenceMm: number;
|
|
25952
|
+
} | undefined;
|
|
25953
|
+
|
|
25760
25954
|
declare const getReadableNameForPcbPort: (soup: AnyCircuitElement[], pcb_port_id: string) => string;
|
|
25761
25955
|
|
|
25762
25956
|
declare function getReadableNameForPcbSmtpad(soup: AnyCircuitElement[], pcb_smtpad_id: string): string;
|
|
@@ -26012,4 +26206,4 @@ declare function convertSchematicLengthUnit(element: AnyCircuitElement, unit: Sc
|
|
|
26012
26206
|
/** Read geometry in one coordinate system before layout, bounds, or rendering. */
|
|
26013
26207
|
declare function convertSchematicLengthUnits(circuit: AnyCircuitElement[], unit: SchematicLengthUnit): AnyCircuitElement[];
|
|
26014
26208
|
|
|
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 };
|
|
26209
|
+
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);
|
|
@@ -2627,85 +2779,6 @@ function isRouteViaCoveredByPhysicalVia(viaWithLayersOrOptions, legacyRouteVia)
|
|
|
2627
2779
|
return viaTopDepth < viaBottomDepth && fromLayerDepth !== toLayerDepth && viaTopDepth <= Math.min(fromLayerDepth, toLayerDepth) && viaBottomDepth >= Math.max(fromLayerDepth, toLayerDepth);
|
|
2628
2780
|
}
|
|
2629
2781
|
|
|
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
2782
|
// lib/shape-distances/decompose-copper-into-shapes.ts
|
|
2710
2783
|
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
2711
2784
|
var createWireSegmentRect = (start, end, width) => ({
|
|
@@ -3596,6 +3669,7 @@ export {
|
|
|
3596
3669
|
convertSchematicLengthUnits,
|
|
3597
3670
|
copperPolygonsTouch,
|
|
3598
3671
|
createBoardOwnerMap,
|
|
3672
|
+
createPcbPhaseSkewIndex,
|
|
3599
3673
|
directionToVec,
|
|
3600
3674
|
distanceBetweenCircleAndCircle,
|
|
3601
3675
|
distanceBetweenCircleAndPolygon,
|
|
@@ -3611,6 +3685,7 @@ export {
|
|
|
3611
3685
|
getMinimumFlexContainer,
|
|
3612
3686
|
getPcbElementBounds,
|
|
3613
3687
|
getPcbElementsWithinBounds,
|
|
3688
|
+
getPcbPhaseSkewAtPoint,
|
|
3614
3689
|
getPlatedHolePolygon,
|
|
3615
3690
|
getPourPolygon,
|
|
3616
3691
|
getPrimaryId,
|