From cb88ae4fa704fcfe8a7e8c179bd2db55fe4670cc Mon Sep 17 00:00:00 2001 From: Manish chaudhary <125847751+techmannih@users.noreply.github.com> Date: Thu, 4 Sep 2025 17:00:20 +0530 Subject: [PATCH] test: add repro for junction hopover overlap --- .../Trace_doInitialSchematicTraceRender.ts | 20 +++-- ...reate-schematic-trace-crossing-segments.ts | 10 ++- ...unction-hopover-overlap-schematic.snap.svg | 41 +++++++++++ .../repro51-junction-hopover-overlap.test.tsx | 73 +++++++++++++++++++ 4 files changed, 134 insertions(+), 10 deletions(-) create mode 100644 tests/repros/__snapshots__/repro51-junction-hopover-overlap-schematic.snap.svg create mode 100644 tests/repros/repro51-junction-hopover-overlap.test.tsx diff --git a/lib/components/primitive-components/Trace/Trace_doInitialSchematicTraceRender.ts b/lib/components/primitive-components/Trace/Trace_doInitialSchematicTraceRender.ts index be0ceb709..73b33ba20 100644 --- a/lib/components/primitive-components/Trace/Trace_doInitialSchematicTraceRender.ts +++ b/lib/components/primitive-components/Trace/Trace_doInitialSchematicTraceRender.ts @@ -372,6 +372,15 @@ export const Trace_doInitialSchematicTraceRender = (trace: Trace) => { // push them out of the way pushEdgesOfSchematicTraceToPreventOverlap({ edges, db, source_trace_id }) + // Find all the intersections between myEdges and edges connected to the + // same net and create junction points + // Calculate junctions where traces of the same net intersect + junctions = createSchematicTraceJunctions({ + edges, + db, + source_trace_id: trace.source_trace_id!, + }) + // Find all intersections between myEdges and all otherEdges and create a // segment representing the crossing. Wherever there's a crossing, we create // 3 new edges. The middle edge has `is_crossing: true` and is 0.01mm wide @@ -380,15 +389,10 @@ export const Trace_doInitialSchematicTraceRender = (trace: Trace) => { source_trace_id, differentNetOnly: true, }).flatMap((t: SchematicTrace) => t.edges) - edges = createSchematicTraceCrossingSegments({ edges, otherEdges }) - - // Find all the intersections between myEdges and edges connected to the - // same net and create junction points - // Calculate junctions where traces of the same net intersect - junctions = createSchematicTraceJunctions({ + edges = createSchematicTraceCrossingSegments({ edges, - db, - source_trace_id: trace.source_trace_id!, + otherEdges, + junctions, }) } diff --git a/lib/components/primitive-components/Trace/trace-utils/create-schematic-trace-crossing-segments.ts b/lib/components/primitive-components/Trace/trace-utils/create-schematic-trace-crossing-segments.ts index 096b9d619..e57bf92d0 100644 --- a/lib/components/primitive-components/Trace/trace-utils/create-schematic-trace-crossing-segments.ts +++ b/lib/components/primitive-components/Trace/trace-utils/create-schematic-trace-crossing-segments.ts @@ -1,7 +1,5 @@ import { distance, doesLineIntersectLine } from "@tscircuit/math-utils" -import type { CircuitJsonUtilObjects } from "@tscircuit/circuit-json-util" import type { SchematicTrace } from "circuit-json" -import { getOtherSchematicTraces } from "./get-other-schematic-traces" import { getUnitVectorFromPointAToB } from "@tscircuit/math-utils" /** @@ -12,9 +10,11 @@ import { getUnitVectorFromPointAToB } from "@tscircuit/math-utils" export const createSchematicTraceCrossingSegments = ({ edges: inputEdges, otherEdges, + junctions, }: { edges: SchematicTrace["edges"] otherEdges: SchematicTrace["edges"] + junctions?: Array<{ x: number; y: number }> }) => { const edges = [...inputEdges] // For each edge in our trace @@ -72,6 +72,12 @@ export const createSchematicTraceCrossingSegments = ({ const crossingPoint = { x: intersectX, y: intersectY } + // Skip creating a crossing segment if there's a junction at this point + const isJunction = junctions?.some( + (j) => distance(j, crossingPoint) < 0.01, + ) + if (isJunction) continue + otherEdgesIntersections.push({ otherEdge, crossingPoint: crossingPoint, diff --git a/tests/repros/__snapshots__/repro51-junction-hopover-overlap-schematic.snap.svg b/tests/repros/__snapshots__/repro51-junction-hopover-overlap-schematic.snap.svg new file mode 100644 index 000000000..5111719e3 --- /dev/null +++ b/tests/repros/__snapshots__/repro51-junction-hopover-overlap-schematic.snap.svg @@ -0,0 +1,41 @@ +-4,-2-4,-1-4,0-4,1-4,2-4,3-4,4-3,-2-3,-1-3,0-3,1-3,2-3,3-3,4-2,-2-2,-1-2,0-2,1-2,2-2,3-2,4-1,-2-1,-1-1,0-1,1-1,2-1,3-1,40,-20,-10,00,10,20,30,41,-21,-11,01,11,21,31,42,-22,-12,02,12,22,32,43,-23,-13,03,13,23,33,44,-24,-14,04,14,24,34,4U11GND2TRIG3OUT4RESET5CTRL6THRES7DISCH8VCCR11kΩR210kΩC110uFC210nFJ11VCC2OUT3GNDGNDNODENODEOUTVCC \ No newline at end of file diff --git a/tests/repros/repro51-junction-hopover-overlap.test.tsx b/tests/repros/repro51-junction-hopover-overlap.test.tsx new file mode 100644 index 000000000..08b457748 --- /dev/null +++ b/tests/repros/repro51-junction-hopover-overlap.test.tsx @@ -0,0 +1,73 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "../fixtures/get-test-fixture" + +test("repro51: junction and hop over traces should not overlap", () => { + const { circuit } = getTestFixture() + + circuit.add( + + {/* --- 555 timer as a generic 8‑pin chip --- */} + + {/* VCC -> DISCH */} + {" "} + {/* DISCH -> node */} + {" "} + {/* node -> GND */} + {" "} + {/* CTRL -> GND (stability) */} + {/* 3-pin header for power + output */} + + {/* Power & housekeeping */} + + + + + + {/* Astable wiring: tie THRES & TRIG; R1, R2, C1 form RC network */} + + + + + + {/* R1 from VCC to DISCH; R2 from DISCH to node */} + + {/* Output to header */} + + , + ) + + circuit.render() + + expect(circuit).toMatchSchematicSnapshot(import.meta.path) +})