@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.
Files changed (2) hide show
  1. package/dist/index.js +39 -26
  2. 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 === edge.to.x ? "vertical" : "horizontal";
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 intersection = doesLineIntersectLine2(
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 (intersection) {
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 crossingSegmentLength = 0.1;
3757
- const lastDrawnPoint = edge.from;
3758
- const crossingPoint = { x: intersectX, y: intersectY };
3759
- const crossingUnitVec = getUnitVectorFromPointAToB(
3760
- lastDrawnPoint,
3761
- crossingPoint
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.174",
4
+ "version": "0.0.175",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",