@tscircuit/core 0.0.174 → 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 +39 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3727,7 +3727,7 @@ var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
|
3727
3727
|
};
|
|
3728
3728
|
|
|
3729
3729
|
// lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
|
|
3730
|
-
import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3730
|
+
import { distance as distance2, doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3731
3731
|
import { getUnitVectorFromPointAToB } from "@tscircuit/math-utils";
|
|
3732
3732
|
var createSchematicTraceCrossingSegments = ({
|
|
3733
3733
|
edges,
|
|
@@ -3741,42 +3741,55 @@ var createSchematicTraceCrossingSegments = ({
|
|
|
3741
3741
|
}).flatMap((t) => t.edges);
|
|
3742
3742
|
for (let i = 0; i < edges.length; i++) {
|
|
3743
3743
|
const edge = edges[i];
|
|
3744
|
-
const edgeOrientation = edge.from.x
|
|
3744
|
+
const edgeOrientation = Math.abs(edge.from.x - edge.to.x) < 0.01 ? "vertical" : "horizontal";
|
|
3745
|
+
const otherEdgesIntersections = [];
|
|
3745
3746
|
for (const otherEdge of otherEdges) {
|
|
3746
3747
|
const otherOrientation = otherEdge.from.x === otherEdge.to.x ? "vertical" : "horizontal";
|
|
3747
3748
|
if (edgeOrientation === otherOrientation) continue;
|
|
3748
|
-
const
|
|
3749
|
+
const hasIntersection = doesLineIntersectLine2(
|
|
3749
3750
|
[edge.from, edge.to],
|
|
3750
3751
|
[otherEdge.from, otherEdge.to],
|
|
3751
3752
|
{ lineThickness: 0.01 }
|
|
3752
3753
|
);
|
|
3753
|
-
if (
|
|
3754
|
+
if (hasIntersection) {
|
|
3754
3755
|
const intersectX = edgeOrientation === "vertical" ? edge.from.x : otherEdge.from.x;
|
|
3755
3756
|
const intersectY = edgeOrientation === "vertical" ? otherEdge.from.y : edge.from.y;
|
|
3756
|
-
const
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
);
|
|
3763
|
-
const beforeCrossing = {
|
|
3764
|
-
x: crossingPoint.x - crossingUnitVec.x * crossingSegmentLength / 2,
|
|
3765
|
-
y: crossingPoint.y - crossingUnitVec.y * crossingSegmentLength / 2
|
|
3766
|
-
};
|
|
3767
|
-
const afterCrossing = {
|
|
3768
|
-
x: crossingPoint.x + crossingUnitVec.x * crossingSegmentLength / 2,
|
|
3769
|
-
y: crossingPoint.y + crossingUnitVec.y * crossingSegmentLength / 2
|
|
3770
|
-
};
|
|
3771
|
-
const newEdges = [
|
|
3772
|
-
{ from: edge.from, to: beforeCrossing },
|
|
3773
|
-
{ from: beforeCrossing, to: afterCrossing, is_crossing: true },
|
|
3774
|
-
{ from: afterCrossing, to: edge.to }
|
|
3775
|
-
];
|
|
3776
|
-
edges.splice(i, 1, ...newEdges);
|
|
3777
|
-
i += 2;
|
|
3757
|
+
const crossingPoint2 = { x: intersectX, y: intersectY };
|
|
3758
|
+
otherEdgesIntersections.push({
|
|
3759
|
+
otherEdge,
|
|
3760
|
+
crossingPoint: crossingPoint2,
|
|
3761
|
+
distanceFromEdgeFrom: distance2(edge.from, crossingPoint2)
|
|
3762
|
+
});
|
|
3778
3763
|
}
|
|
3779
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;
|
|
3770
|
+
}
|
|
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
|
+
}
|
|
3780
3793
|
}
|
|
3781
3794
|
};
|
|
3782
3795
|
|