From de0eca2ed7139cb830fa38849508d5d3fe2eacf0 Mon Sep 17 00:00:00 2001 From: Eugene Mikhantyev Date: Sat, 14 Mar 2026 16:20:11 +0000 Subject: [PATCH] refactor: remove redundant junction processing from wire connectivity Shared-endpoint adjacency already connects all wires meeting at the same point, making explicit junction handling a no-op duplicate. Co-Authored-By: Claude Opus 4.6 --- python/commands/wire_connectivity.py | 34 ++++------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/python/commands/wire_connectivity.py b/python/commands/wire_connectivity.py index 42519eb..5942c6a 100644 --- a/python/commands/wire_connectivity.py +++ b/python/commands/wire_connectivity.py @@ -36,30 +36,14 @@ def _parse_wires(schematic) -> List[List[Tuple[int, int]]]: return all_wires -def _parse_junctions(schematic) -> List[Tuple[int, int]]: - """Extract junction points from a schematic object as IU tuples. - - Junctions may be exposed via schematic.junction (kicad-skip attribute) or - might not exist. Handle both cases gracefully. - """ - junctions = [] - if not hasattr(schematic, 'junction'): - return junctions - for junc in schematic.junction: - try: - if hasattr(junc, 'at') and hasattr(junc.at, 'value'): - junctions.append(_to_iu(float(junc.at.value[0]), float(junc.at.value[1]))) - except (IndexError, TypeError, ValueError): - continue - return junctions - - def _build_adjacency( all_wires: List[List[Tuple[int, int]]], - junctions: List[Tuple[int, int]], ) -> Tuple[List[Set[int]], Dict[Tuple[int, int], Set[int]]]: """Build wire adjacency using exact IU coordinate matching. + Wires that share an endpoint are adjacent — this naturally handles + junctions since all wires meeting at the same point get connected. + Returns a tuple of: - adjacency: list of sets, one per wire, containing adjacent wire indices - iu_to_wires: dict mapping each IU endpoint to the set of wire indices @@ -80,15 +64,6 @@ def _build_adjacency( if a != b: adjacency[a].add(b) - # Junctions: connect all wires that have an endpoint at the junction IU point - for junc_iu in junctions: - wire_set = iu_to_wires.get(junc_iu, set()) - wire_list = list(wire_set) - for a in wire_list: - for b in wire_list: - if a != b: - adjacency[a].add(b) - return adjacency, iu_to_wires @@ -194,8 +169,7 @@ def get_wire_connections(schematic, schematic_path: str, x_mm: float, y_mm: floa if not all_wires: return {"pins": [], "wires": []} - junctions = _parse_junctions(schematic) - adjacency, iu_to_wires = _build_adjacency(all_wires, junctions) + adjacency, iu_to_wires = _build_adjacency(all_wires) visited, net_points = _find_connected_wires(x_mm, y_mm, all_wires, iu_to_wires, adjacency) if visited is None: