@tscircuit/core 0.0.173 → 0.0.175
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 +44 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1638,9 +1638,9 @@ function getRelativeDirection(pointA, pointB) {
|
|
|
1638
1638
|
const dx = pointB.x - pointA.x;
|
|
1639
1639
|
const dy = pointB.y - pointA.y;
|
|
1640
1640
|
if (Math.abs(dx) > Math.abs(dy)) {
|
|
1641
|
-
return dx
|
|
1641
|
+
return dx >= 0 ? "right" : "left";
|
|
1642
1642
|
}
|
|
1643
|
-
return dy
|
|
1643
|
+
return dy >= 0 ? "up" : "down";
|
|
1644
1644
|
}
|
|
1645
1645
|
|
|
1646
1646
|
// lib/components/primitive-components/Port.ts
|
|
@@ -1860,15 +1860,16 @@ var Port = class extends PrimitiveComponent {
|
|
|
1860
1860
|
label: "obstacle"
|
|
1861
1861
|
});
|
|
1862
1862
|
}
|
|
1863
|
-
if (!localPortInfo?.side)
|
|
1863
|
+
if (!localPortInfo?.side) {
|
|
1864
1864
|
this.facingDirection = getRelativeDirection(containerCenter, portCenter);
|
|
1865
|
-
else
|
|
1865
|
+
} else {
|
|
1866
1866
|
this.facingDirection = {
|
|
1867
1867
|
left: "left",
|
|
1868
1868
|
right: "right",
|
|
1869
1869
|
top: "up",
|
|
1870
1870
|
bottom: "down"
|
|
1871
1871
|
}[localPortInfo.side];
|
|
1872
|
+
}
|
|
1872
1873
|
const sourcePort = db.source_port.get(this.source_port_id);
|
|
1873
1874
|
let bestDisplayPinLabel = void 0;
|
|
1874
1875
|
for (const portHint of sourcePort?.port_hints ?? []) {
|
|
@@ -3726,7 +3727,7 @@ var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
|
3726
3727
|
};
|
|
3727
3728
|
|
|
3728
3729
|
// lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
|
|
3729
|
-
import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3730
|
+
import { distance as distance2, doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3730
3731
|
import { getUnitVectorFromPointAToB } from "@tscircuit/math-utils";
|
|
3731
3732
|
var createSchematicTraceCrossingSegments = ({
|
|
3732
3733
|
edges,
|
|
@@ -3740,42 +3741,55 @@ var createSchematicTraceCrossingSegments = ({
|
|
|
3740
3741
|
}).flatMap((t) => t.edges);
|
|
3741
3742
|
for (let i = 0; i < edges.length; i++) {
|
|
3742
3743
|
const edge = edges[i];
|
|
3743
|
-
const edgeOrientation = edge.from.x
|
|
3744
|
+
const edgeOrientation = Math.abs(edge.from.x - edge.to.x) < 0.01 ? "vertical" : "horizontal";
|
|
3745
|
+
const otherEdgesIntersections = [];
|
|
3744
3746
|
for (const otherEdge of otherEdges) {
|
|
3745
3747
|
const otherOrientation = otherEdge.from.x === otherEdge.to.x ? "vertical" : "horizontal";
|
|
3746
3748
|
if (edgeOrientation === otherOrientation) continue;
|
|
3747
|
-
const
|
|
3749
|
+
const hasIntersection = doesLineIntersectLine2(
|
|
3748
3750
|
[edge.from, edge.to],
|
|
3749
3751
|
[otherEdge.from, otherEdge.to],
|
|
3750
3752
|
{ lineThickness: 0.01 }
|
|
3751
3753
|
);
|
|
3752
|
-
if (
|
|
3754
|
+
if (hasIntersection) {
|
|
3753
3755
|
const intersectX = edgeOrientation === "vertical" ? edge.from.x : otherEdge.from.x;
|
|
3754
3756
|
const intersectY = edgeOrientation === "vertical" ? otherEdge.from.y : edge.from.y;
|
|
3755
|
-
const
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
y: crossingPoint.y + crossingUnitVec.y * crossingSegmentLength / 2
|
|
3769
|
-
};
|
|
3770
|
-
const newEdges = [
|
|
3771
|
-
{ from: edge.from, to: beforeCrossing },
|
|
3772
|
-
{ from: beforeCrossing, to: afterCrossing, is_crossing: true },
|
|
3773
|
-
{ from: afterCrossing, to: edge.to }
|
|
3774
|
-
];
|
|
3775
|
-
edges.splice(i, 1, ...newEdges);
|
|
3776
|
-
i += 2;
|
|
3757
|
+
const crossingPoint2 = { x: intersectX, y: intersectY };
|
|
3758
|
+
otherEdgesIntersections.push({
|
|
3759
|
+
otherEdge,
|
|
3760
|
+
crossingPoint: crossingPoint2,
|
|
3761
|
+
distanceFromEdgeFrom: distance2(edge.from, crossingPoint2)
|
|
3762
|
+
});
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
if (otherEdgesIntersections.length === 0) continue;
|
|
3766
|
+
let closestIntersection = otherEdgesIntersections[0];
|
|
3767
|
+
for (const intersection of otherEdgesIntersections) {
|
|
3768
|
+
if (intersection.distanceFromEdgeFrom < closestIntersection.distanceFromEdgeFrom) {
|
|
3769
|
+
closestIntersection = intersection;
|
|
3777
3770
|
}
|
|
3778
3771
|
}
|
|
3772
|
+
const crossingPoint = closestIntersection.crossingPoint;
|
|
3773
|
+
const crossingSegmentLength = 0.075;
|
|
3774
|
+
const crossingUnitVec = getUnitVectorFromPointAToB(edge.from, crossingPoint);
|
|
3775
|
+
const beforeCrossing = {
|
|
3776
|
+
x: crossingPoint.x - crossingUnitVec.x * crossingSegmentLength / 2,
|
|
3777
|
+
y: crossingPoint.y - crossingUnitVec.y * crossingSegmentLength / 2
|
|
3778
|
+
};
|
|
3779
|
+
const afterCrossing = {
|
|
3780
|
+
x: crossingPoint.x + crossingUnitVec.x * crossingSegmentLength / 2,
|
|
3781
|
+
y: crossingPoint.y + crossingUnitVec.y * crossingSegmentLength / 2
|
|
3782
|
+
};
|
|
3783
|
+
const newEdges = [
|
|
3784
|
+
{ from: edge.from, to: beforeCrossing },
|
|
3785
|
+
{ from: beforeCrossing, to: afterCrossing, is_crossing: true },
|
|
3786
|
+
{ from: afterCrossing, to: edge.to }
|
|
3787
|
+
];
|
|
3788
|
+
edges.splice(i, 1, ...newEdges);
|
|
3789
|
+
i += newEdges.length - 2;
|
|
3790
|
+
if (distance2(afterCrossing, edge.to) <= 1) {
|
|
3791
|
+
i++;
|
|
3792
|
+
}
|
|
3779
3793
|
}
|
|
3780
3794
|
};
|
|
3781
3795
|
|