@tscircuit/core 0.0.579 → 0.0.580

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 +45 -32
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4683,45 +4683,56 @@ var createSchematicTraceCrossingSegments = ({
4683
4683
  };
4684
4684
 
4685
4685
  // lib/components/primitive-components/Trace/trace-utils/create-schematic-trace-junctions.ts
4686
+ var TOLERANCE = 1e-3;
4687
+ var isPointWithinEdge = (point, edge) => {
4688
+ const minX = Math.min(edge.from.x, edge.to.x);
4689
+ const maxX = Math.max(edge.from.x, edge.to.x);
4690
+ const minY = Math.min(edge.from.y, edge.to.y);
4691
+ const maxY = Math.max(edge.from.y, edge.to.y);
4692
+ return point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY;
4693
+ };
4694
+ var getEdgeOrientation = (edge) => {
4695
+ const isVertical = Math.abs(edge.from.x - edge.to.x) < TOLERANCE;
4696
+ const isHorizontal = Math.abs(edge.from.y - edge.to.y) < TOLERANCE;
4697
+ if (isVertical) return "vertical";
4698
+ if (isHorizontal) return "horizontal";
4699
+ return "diagonal";
4700
+ };
4686
4701
  var getIntersectionPoint = (edge1, edge2) => {
4687
- if (edge1.from.x === edge1.to.x && edge2.from.x === edge2.to.x) {
4702
+ const orientation1 = getEdgeOrientation(edge1);
4703
+ const orientation2 = getEdgeOrientation(edge2);
4704
+ if (orientation1 === orientation2) {
4688
4705
  return null;
4689
4706
  }
4690
- if (edge1.from.x === edge1.to.x) {
4691
- const x2 = edge1.from.x;
4692
- const m22 = (edge2.to.y - edge2.from.y) / (edge2.to.x - edge2.from.x);
4693
- const b22 = edge2.from.y - m22 * edge2.from.x;
4694
- const y2 = m22 * x2 + b22;
4695
- if (x2 >= Math.min(edge2.from.x, edge2.to.x) && x2 <= Math.max(edge2.from.x, edge2.to.x) && y2 >= Math.min(edge2.from.y, edge2.to.y) && y2 <= Math.max(edge2.from.y, edge2.to.y)) {
4696
- return { x: x2, y: y2 };
4697
- }
4698
- return null;
4699
- }
4700
- if (edge2.from.x === edge2.to.x) {
4701
- const x2 = edge2.from.x;
4702
- const m12 = (edge1.to.y - edge1.from.y) / (edge1.to.x - edge1.from.x);
4703
- const b12 = edge1.from.y - m12 * edge1.from.x;
4704
- const y2 = m12 * x2 + b12;
4705
- if (x2 >= Math.min(edge1.from.x, edge1.to.x) && x2 <= Math.max(edge1.from.x, edge1.to.x) && y2 >= Math.min(edge1.from.y, edge1.to.y) && y2 <= Math.max(edge1.from.y, edge1.to.y)) {
4706
- return { x: x2, y: y2 };
4707
- }
4708
- return null;
4707
+ if (orientation1 === "vertical" && orientation2 === "horizontal" || orientation1 === "horizontal" && orientation2 === "vertical") {
4708
+ const verticalEdge = orientation1 === "vertical" ? edge1 : edge2;
4709
+ const horizontalEdge = orientation1 === "horizontal" ? edge1 : edge2;
4710
+ const x2 = verticalEdge.from.x;
4711
+ const y2 = horizontalEdge.from.y;
4712
+ const intersection2 = { x: x2, y: y2 };
4713
+ return isPointWithinEdge(intersection2, edge1) && isPointWithinEdge(intersection2, edge2) ? intersection2 : null;
4714
+ }
4715
+ if (orientation1 === "vertical" || orientation2 === "vertical") {
4716
+ const verticalEdge = orientation1 === "vertical" ? edge1 : edge2;
4717
+ const diagonalEdge = orientation1 === "vertical" ? edge2 : edge1;
4718
+ const x2 = verticalEdge.from.x;
4719
+ const m = (diagonalEdge.to.y - diagonalEdge.from.y) / (diagonalEdge.to.x - diagonalEdge.from.x);
4720
+ const b = diagonalEdge.from.y - m * diagonalEdge.from.x;
4721
+ const y2 = m * x2 + b;
4722
+ const intersection2 = { x: x2, y: y2 };
4723
+ return isPointWithinEdge(intersection2, edge1) && isPointWithinEdge(intersection2, edge2) ? intersection2 : null;
4709
4724
  }
4710
4725
  const m1 = (edge1.to.y - edge1.from.y) / (edge1.to.x - edge1.from.x);
4711
4726
  const b1 = edge1.from.y - m1 * edge1.from.x;
4712
4727
  const m2 = (edge2.to.y - edge2.from.y) / (edge2.to.x - edge2.from.x);
4713
4728
  const b2 = edge2.from.y - m2 * edge2.from.x;
4714
- if (m1 === m2) {
4729
+ if (Math.abs(m1 - m2) < TOLERANCE) {
4715
4730
  return null;
4716
4731
  }
4717
4732
  const x = (b2 - b1) / (m1 - m2);
4718
4733
  const y = m1 * x + b1;
4719
- const isWithinEdge1 = x >= Math.min(edge1.from.x, edge1.to.x) && x <= Math.max(edge1.from.x, edge1.to.x) && y >= Math.min(edge1.from.y, edge1.to.y) && y <= Math.max(edge1.from.y, edge1.to.y);
4720
- const isWithinEdge2 = x >= Math.min(edge2.from.x, edge2.to.x) && x <= Math.max(edge2.from.x, edge2.to.x) && y >= Math.min(edge2.from.y, edge2.to.y) && y <= Math.max(edge2.from.y, edge2.to.y);
4721
- if (isWithinEdge1 && isWithinEdge2) {
4722
- return { x, y };
4723
- }
4724
- return null;
4734
+ const intersection = { x, y };
4735
+ return isPointWithinEdge(intersection, edge1) && isPointWithinEdge(intersection, edge2) ? intersection : null;
4725
4736
  };
4726
4737
  var createSchematicTraceJunctions = ({
4727
4738
  edges: myEdges,
@@ -4733,17 +4744,19 @@ var createSchematicTraceJunctions = ({
4733
4744
  source_trace_id,
4734
4745
  sameNetOnly: true
4735
4746
  }).flatMap((t) => t.edges);
4736
- const junctions = /* @__PURE__ */ new Set();
4747
+ const junctions = /* @__PURE__ */ new Map();
4737
4748
  for (const myEdge of myEdges) {
4738
4749
  for (const otherEdge of otherEdges) {
4739
4750
  const intersection = getIntersectionPoint(myEdge, otherEdge);
4740
4751
  if (intersection) {
4741
- const pointKey = `${intersection.x},${intersection.y}`;
4742
- return [{ x: intersection.x, y: intersection.y }];
4752
+ const key = `${intersection.x.toFixed(6)},${intersection.y.toFixed(6)}`;
4753
+ if (!junctions.has(key)) {
4754
+ junctions.set(key, intersection);
4755
+ }
4743
4756
  }
4744
4757
  }
4745
4758
  }
4746
- return [];
4759
+ return Array.from(junctions.values());
4747
4760
  };
4748
4761
 
4749
4762
  // lib/components/primitive-components/Trace/trace-utils/get-obstacles-for-trace.ts
@@ -11103,7 +11116,7 @@ import { identity as identity5 } from "transformation-matrix";
11103
11116
  var package_default = {
11104
11117
  name: "@tscircuit/core",
11105
11118
  type: "module",
11106
- version: "0.0.578",
11119
+ version: "0.0.579",
11107
11120
  types: "dist/index.d.ts",
11108
11121
  main: "dist/index.js",
11109
11122
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.579",
4
+ "version": "0.0.580",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",