@tscircuit/core 0.0.883 → 0.0.885
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.js +161 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6756,6 +6756,149 @@ function Trace_doInitialPcbTraceRender(trace) {
|
|
|
6756
6756
|
|
|
6757
6757
|
// lib/components/primitive-components/Trace/Trace_doInitialPcbManualTraceRender.ts
|
|
6758
6758
|
import { applyToPoint as applyToPoint7, identity as identity3 } from "transformation-matrix";
|
|
6759
|
+
|
|
6760
|
+
// lib/utils/trace-clipping/computeLineRectIntersection.ts
|
|
6761
|
+
function computeLineRectIntersection(params) {
|
|
6762
|
+
const { lineStart, lineEnd, rectCenter, rectWidth, rectHeight } = params;
|
|
6763
|
+
const left = rectCenter.x - rectWidth / 2;
|
|
6764
|
+
const right = rectCenter.x + rectWidth / 2;
|
|
6765
|
+
const top = rectCenter.y + rectHeight / 2;
|
|
6766
|
+
const bottom = rectCenter.y - rectHeight / 2;
|
|
6767
|
+
const dx = lineEnd.x - lineStart.x;
|
|
6768
|
+
const dy = lineEnd.y - lineStart.y;
|
|
6769
|
+
const intersections = [];
|
|
6770
|
+
if (dx !== 0) {
|
|
6771
|
+
const t = (left - lineStart.x) / dx;
|
|
6772
|
+
if (t >= 0 && t <= 1) {
|
|
6773
|
+
const y = lineStart.y + t * dy;
|
|
6774
|
+
if (y >= bottom && y <= top) {
|
|
6775
|
+
intersections.push({ x: left, y, t });
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
if (dx !== 0) {
|
|
6780
|
+
const t = (right - lineStart.x) / dx;
|
|
6781
|
+
if (t >= 0 && t <= 1) {
|
|
6782
|
+
const y = lineStart.y + t * dy;
|
|
6783
|
+
if (y >= bottom && y <= top) {
|
|
6784
|
+
intersections.push({ x: right, y, t });
|
|
6785
|
+
}
|
|
6786
|
+
}
|
|
6787
|
+
}
|
|
6788
|
+
if (dy !== 0) {
|
|
6789
|
+
const t = (bottom - lineStart.y) / dy;
|
|
6790
|
+
if (t >= 0 && t <= 1) {
|
|
6791
|
+
const x = lineStart.x + t * dx;
|
|
6792
|
+
if (x >= left && x <= right) {
|
|
6793
|
+
intersections.push({ x, y: bottom, t });
|
|
6794
|
+
}
|
|
6795
|
+
}
|
|
6796
|
+
}
|
|
6797
|
+
if (dy !== 0) {
|
|
6798
|
+
const t = (top - lineStart.y) / dy;
|
|
6799
|
+
if (t >= 0 && t <= 1) {
|
|
6800
|
+
const x = lineStart.x + t * dx;
|
|
6801
|
+
if (x >= left && x <= right) {
|
|
6802
|
+
intersections.push({ x, y: top, t });
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
}
|
|
6806
|
+
if (intersections.length === 0) return null;
|
|
6807
|
+
intersections.sort((a, b) => a.t - b.t);
|
|
6808
|
+
return { x: intersections[0].x, y: intersections[0].y };
|
|
6809
|
+
}
|
|
6810
|
+
|
|
6811
|
+
// lib/utils/trace-clipping/computeLineCircleIntersection.ts
|
|
6812
|
+
function computeLineCircleIntersection(params) {
|
|
6813
|
+
const { lineStart, lineEnd, circleCenter, circleRadius } = params;
|
|
6814
|
+
const x1 = lineStart.x - circleCenter.x;
|
|
6815
|
+
const y1 = lineStart.y - circleCenter.y;
|
|
6816
|
+
const x2 = lineEnd.x - circleCenter.x;
|
|
6817
|
+
const y2 = lineEnd.y - circleCenter.y;
|
|
6818
|
+
const dx = x2 - x1;
|
|
6819
|
+
const dy = y2 - y1;
|
|
6820
|
+
const a = dx * dx + dy * dy;
|
|
6821
|
+
const b = 2 * (x1 * dx + y1 * dy);
|
|
6822
|
+
const c = x1 * x1 + y1 * y1 - circleRadius * circleRadius;
|
|
6823
|
+
const discriminant = b * b - 4 * a * c;
|
|
6824
|
+
if (discriminant < 0) return null;
|
|
6825
|
+
const sqrtDisc = Math.sqrt(discriminant);
|
|
6826
|
+
const t1 = (-b - sqrtDisc) / (2 * a);
|
|
6827
|
+
const t2 = (-b + sqrtDisc) / (2 * a);
|
|
6828
|
+
let t = null;
|
|
6829
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
6830
|
+
t = t1;
|
|
6831
|
+
} else if (t2 >= 0 && t2 <= 1) {
|
|
6832
|
+
t = t2;
|
|
6833
|
+
}
|
|
6834
|
+
if (t === null) return null;
|
|
6835
|
+
return {
|
|
6836
|
+
x: lineStart.x + t * dx,
|
|
6837
|
+
y: lineStart.y + t * dy
|
|
6838
|
+
};
|
|
6839
|
+
}
|
|
6840
|
+
|
|
6841
|
+
// lib/utils/trace-clipping/clipTraceEndAtPad.ts
|
|
6842
|
+
function clipTraceEndAtPad(params) {
|
|
6843
|
+
const { traceStart, traceEnd, traceWidth, port } = params;
|
|
6844
|
+
const pcbPrimitive = port.matchedComponents.find((c) => c.isPcbPrimitive);
|
|
6845
|
+
if (!pcbPrimitive) {
|
|
6846
|
+
return traceEnd;
|
|
6847
|
+
}
|
|
6848
|
+
const padBounds = pcbPrimitive._getPcbCircuitJsonBounds();
|
|
6849
|
+
const padWidth = padBounds.width;
|
|
6850
|
+
const padHeight = padBounds.height;
|
|
6851
|
+
const padCenter = padBounds.center;
|
|
6852
|
+
const smallestPadDimension = Math.min(padWidth, padHeight);
|
|
6853
|
+
if (traceWidth <= smallestPadDimension / 2) {
|
|
6854
|
+
return traceEnd;
|
|
6855
|
+
}
|
|
6856
|
+
let clippedPoint = null;
|
|
6857
|
+
if (pcbPrimitive.componentName === "SmtPad") {
|
|
6858
|
+
const smtPad = pcbPrimitive;
|
|
6859
|
+
const padShape = smtPad._parsedProps.shape;
|
|
6860
|
+
if (padShape === "circle") {
|
|
6861
|
+
const radius = smtPad._parsedProps.radius;
|
|
6862
|
+
clippedPoint = computeLineCircleIntersection({
|
|
6863
|
+
lineStart: traceStart,
|
|
6864
|
+
lineEnd: traceEnd,
|
|
6865
|
+
circleCenter: padCenter,
|
|
6866
|
+
circleRadius: radius
|
|
6867
|
+
});
|
|
6868
|
+
} else if (padShape === "rect" || padShape === "rotated_rect" || padShape === "pill" || padShape === "polygon") {
|
|
6869
|
+
clippedPoint = computeLineRectIntersection({
|
|
6870
|
+
lineStart: traceStart,
|
|
6871
|
+
lineEnd: traceEnd,
|
|
6872
|
+
rectCenter: padCenter,
|
|
6873
|
+
rectWidth: padWidth,
|
|
6874
|
+
rectHeight: padHeight
|
|
6875
|
+
});
|
|
6876
|
+
}
|
|
6877
|
+
} else if (pcbPrimitive.componentName === "PlatedHole") {
|
|
6878
|
+
const platedHole = pcbPrimitive;
|
|
6879
|
+
const holeShape = platedHole._parsedProps.shape;
|
|
6880
|
+
if (holeShape === "circle") {
|
|
6881
|
+
const outerDiameter = platedHole._parsedProps.outerDiameter;
|
|
6882
|
+
clippedPoint = computeLineCircleIntersection({
|
|
6883
|
+
lineStart: traceStart,
|
|
6884
|
+
lineEnd: traceEnd,
|
|
6885
|
+
circleCenter: padCenter,
|
|
6886
|
+
circleRadius: outerDiameter / 2
|
|
6887
|
+
});
|
|
6888
|
+
} else {
|
|
6889
|
+
clippedPoint = computeLineRectIntersection({
|
|
6890
|
+
lineStart: traceStart,
|
|
6891
|
+
lineEnd: traceEnd,
|
|
6892
|
+
rectCenter: padCenter,
|
|
6893
|
+
rectWidth: padWidth,
|
|
6894
|
+
rectHeight: padHeight
|
|
6895
|
+
});
|
|
6896
|
+
}
|
|
6897
|
+
}
|
|
6898
|
+
return clippedPoint ?? traceEnd;
|
|
6899
|
+
}
|
|
6900
|
+
|
|
6901
|
+
// lib/components/primitive-components/Trace/Trace_doInitialPcbManualTraceRender.ts
|
|
6759
6902
|
function Trace_doInitialPcbManualTraceRender(trace) {
|
|
6760
6903
|
if (trace.root?.pcbDisabled) return;
|
|
6761
6904
|
const { db } = trace.root;
|
|
@@ -6796,19 +6939,31 @@ function Trace_doInitialPcbManualTraceRender(trace) {
|
|
|
6796
6939
|
const layer2 = sharedLayer ?? startLayers[0] ?? endLayers[0] ?? "top";
|
|
6797
6940
|
const startPos = startPort._getGlobalPcbPositionAfterLayout();
|
|
6798
6941
|
const endPos = endPort._getGlobalPcbPositionAfterLayout();
|
|
6942
|
+
const clippedStartPos = clipTraceEndAtPad({
|
|
6943
|
+
traceStart: endPos,
|
|
6944
|
+
traceEnd: startPos,
|
|
6945
|
+
traceWidth: width,
|
|
6946
|
+
port: startPort
|
|
6947
|
+
});
|
|
6948
|
+
const clippedEndPos = clipTraceEndAtPad({
|
|
6949
|
+
traceStart: startPos,
|
|
6950
|
+
traceEnd: endPos,
|
|
6951
|
+
traceWidth: width,
|
|
6952
|
+
port: endPort
|
|
6953
|
+
});
|
|
6799
6954
|
const route2 = [
|
|
6800
6955
|
{
|
|
6801
6956
|
route_type: "wire",
|
|
6802
|
-
x:
|
|
6803
|
-
y:
|
|
6957
|
+
x: clippedStartPos.x,
|
|
6958
|
+
y: clippedStartPos.y,
|
|
6804
6959
|
width,
|
|
6805
6960
|
layer: layer2,
|
|
6806
6961
|
start_pcb_port_id: startPort.pcb_port_id
|
|
6807
6962
|
},
|
|
6808
6963
|
{
|
|
6809
6964
|
route_type: "wire",
|
|
6810
|
-
x:
|
|
6811
|
-
y:
|
|
6965
|
+
x: clippedEndPos.x,
|
|
6966
|
+
y: clippedEndPos.y,
|
|
6812
6967
|
width,
|
|
6813
6968
|
layer: layer2,
|
|
6814
6969
|
end_pcb_port_id: endPort.pcb_port_id
|
|
@@ -18635,7 +18790,7 @@ import { identity as identity6 } from "transformation-matrix";
|
|
|
18635
18790
|
var package_default = {
|
|
18636
18791
|
name: "@tscircuit/core",
|
|
18637
18792
|
type: "module",
|
|
18638
|
-
version: "0.0.
|
|
18793
|
+
version: "0.0.884",
|
|
18639
18794
|
types: "dist/index.d.ts",
|
|
18640
18795
|
main: "dist/index.js",
|
|
18641
18796
|
module: "dist/index.js",
|
|
@@ -18740,7 +18895,7 @@ var package_default = {
|
|
|
18740
18895
|
dependencies: {
|
|
18741
18896
|
"@flatten-js/core": "^1.6.2",
|
|
18742
18897
|
"@lume/kiwi": "^0.4.3",
|
|
18743
|
-
"calculate-packing": "0.0.
|
|
18898
|
+
"calculate-packing": "0.0.62",
|
|
18744
18899
|
"css-select": "5.1.0",
|
|
18745
18900
|
"format-si-unit": "^0.0.3",
|
|
18746
18901
|
nanoid: "^5.0.7",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.885",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"dependencies": {
|
|
107
107
|
"@flatten-js/core": "^1.6.2",
|
|
108
108
|
"@lume/kiwi": "^0.4.3",
|
|
109
|
-
"calculate-packing": "0.0.
|
|
109
|
+
"calculate-packing": "0.0.62",
|
|
110
110
|
"css-select": "5.1.0",
|
|
111
111
|
"format-si-unit": "^0.0.3",
|
|
112
112
|
"nanoid": "^5.0.7",
|