qcc_kplugin.geometry¶
Plain-Python geometry for the GUI tools (points are (x, y) tuples in µm; no pya, so it is unit-tested).
Mirrors what quantcore_circuits.route does when it builds a route, closely enough for a live preview:
port stub → user waypoints → port stub, with Manhattan corners when there are no waypoints (or one oblique straight
between ports that face an angle: oblique_mids()). The real geometry (KQC WaveguideComposite, bends of
radius r, meanders) always comes from the rebuild.
Attributes¶
Functions¶
|
|
|
Ports that can be snapped together: same CPW (a, b) and facing each other. |
|
The point a click / move at |
|
Length of each adjacent straight a bend of radius |
|
|
|
Distance to a polyline and the 1-based index of the closest segment (segment k joins points k-1 and k). |
|
|
|
|
|
The square corner between |
|
|
|
(waypoint handles [(node_index, pos)], insert handles [(segment, midpoint)]) for a sidecar route. |
|
|
|
True for a horizontal / vertical direction (a port that faces along an axis). |
|
|
|
|
|
|
|
Corners of the oblique route the router draws between stub ends |
|
|
|
|
|
A KLayout editor-grid config value ( |
|
The bend radius whose arc middle is at |
|
Curvature handle of the corner at |
|
Sharp polyline → polyline with every interior corner |
|
The sidecar route whose polyline passes within |
|
Sharp polyline of a route from a port ( |
|
Ports of the same CPW cross-section (a, b), whichever way they face. |
|
1-based index of the polyline segment within |
|
|
|
Best (moving_port, target_port, corrected_delta) when |
|
Best |
|
|
|
|
|
|
|
Segments (1-based) too short for the bends at both their ends (the rebuild would fail there). |
|
|
|
|
|
Index in |
Module Contents¶
- qcc_kplugin.geometry.compatible(pa: dict, pb: dict, tol: float = 0.001) bool¶
Ports that can be snapped together: same CPW (a, b) and facing each other.
- qcc_kplugin.geometry.constrain(p: Point, grid: float, neighbours=(), shift: bool = False, rays=(), tol: float = 0.0) Point¶
The point a click / move at
pstands for: on the grid and, with Shift, constrained byneighbours. One neighbour (drawing the next segment, moving an end node): the segment snaps to 0° / 45° / 90° / …; two neighbours (moving a middle node): horizontal / vertical to both. Aligned coordinates take the neighbour’s exact value, which wins over the grid.rays((origin, direction) lines: the axes of angled ports) are offered with Shift too: a ray withintolµm ofpand nearer than the 45° / aligned choice wins. Without Shift the point is only put on the grid: any angle (Ctrl in the tools is the same, spelled out).
- qcc_kplugin.geometry.corner_cut(prev: Point, p: Point, nxt: Point, r: float) float¶
Length of each adjacent straight a bend of radius
ratpuses (KQC corner model).
- qcc_kplugin.geometry.dist_point_polyline(p: Point, pts: list[Point]) tuple[float, int]¶
Distance to a polyline and the 1-based index of the closest segment (segment k joins points k-1 and k).
- qcc_kplugin.geometry.elbow(anchor: Point, anchor_dir: Point | None, p: Point) list[Point]¶
The square corner between
anchorandp([]when they are aligned): the segment leavesanchoralonganchor_dir(the previous segment / the port), or along the longer axis when there is none. This is the corner the Connect preview shows, and a click commits it as a node, so the built route matches the preview.
- qcc_kplugin.geometry.free_end_dir(end: Point, toward: Point) float | None¶
FreeEnd.dir(degrees, pointing from the end into the route) of a free end atendwhose route comes fromtoward.
- qcc_kplugin.geometry.handle_points(route: dict) tuple[list[tuple[int, Point]], list[tuple[int, Point]]]¶
(waypoint handles [(node_index, pos)], insert handles [(segment, midpoint)]) for a sidecar route.
- qcc_kplugin.geometry.hanger_side(polyline: list[Point], segment: int, toward: Point) str¶
"left"/"right"of the route’s travel direction onsegment(1-based), the sidetowardis on (a hanger coupler sits on the side its resonator comes from).
- qcc_kplugin.geometry.is_axis(d: Point | None) bool¶
True for a horizontal / vertical direction (a port that faces along an axis).
- qcc_kplugin.geometry.oblique_mids(p0: Point, d0: Point | None, p1: Point, d1: Point | None, r: float = 0.0) list[Point] | None¶
Corners of the oblique route the router draws between stub ends
p0(arriving alongd0) andp1(leaving alongd1) when a port faces an angle, else None (Manhattan, as the router).[]= one straight (the ports face each other along a line, within 5°);[X]= one corner where the two ports’ axes meet. Candidates whose bends do not fit the radiusrare left out, as in the router.
- qcc_kplugin.geometry.ortho(anchor: Point, p: Point) Point¶
pmoved so the segment fromanchoris horizontal or vertical, whichever is nearer (Shift).
- qcc_kplugin.geometry.ortho_between(p: Point, neighbours) Point¶
p(a node being moved or inserted) aligned with its neighbours (Shift): each neighbour segment is made horizontal or vertical, the nearer choice first; a second neighbour can only fix the other coordinate, so two generic neighbours give the square corner nearestpand two neighbours on one line keeppon it.
- qcc_kplugin.geometry.parse_grid(text) float | None¶
A KLayout editor-grid config value (
"0.5","1,1","") → grid step in µm, or None.
- qcc_kplugin.geometry.radius_from_handle(prev: Point, p: Point, nxt: Point, q: Point) float | None¶
The bend radius whose arc middle is at
qprojected on the corner’s bisector (inverse ofradius_handle()); None on a straight node.
- qcc_kplugin.geometry.radius_handle(prev: Point, p: Point, nxt: Point, r: float) Point | None¶
Curvature handle of the corner at
pbent to radiusr: the middle of the arc, on the bisector.
- qcc_kplugin.geometry.rounded_points(points: list[Point], radii: list[float], segments_per_90: int = 12) list[Point]¶
Sharp polyline → polyline with every interior corner
ireplaced by an arc of radiusradii[i](index by point; the ends are ignored). Radii too big for the legs are clipped so the preview stays drawable.
- qcc_kplugin.geometry.route_near(routes: dict, p: Point, radius: float, exclude=()) tuple[str, int] | None¶
The sidecar route whose polyline passes within
radiusµm ofp:(name, segment)or None.
- qcc_kplugin.geometry.route_preview(start: Point, start_dir: Point | None, waypoints: list[Point], end: Point, end_dir: Point | None, stub: float) list[Point]¶
Sharp polyline of a route from a port (
start, outwardstart_dir) throughwaypointstoend.end_diris the outward direction of the end port (Nonewhile the end is still the mouse position or a free end);start_diris None for a route starting at a free end (no stub).
- qcc_kplugin.geometry.same_line(pa: dict, pb: dict, tol: float = 0.001) bool¶
Ports of the same CPW cross-section (a, b), whichever way they face.
- qcc_kplugin.geometry.segment_near(polyline: list[Point], p: Point, radius: float) int | None¶
1-based index of the polyline segment within
radiusofp, or None.
- qcc_kplugin.geometry.snap45(anchor: Point, p: Point, grid: float = 0.0) Point¶
pmoved onto the nearest of the 8 directions fromanchor(0°, 45°, 90°, …; Shift while drawing). Horizontal / vertical keep the anchor’s exact coordinate; a diagonal keeps |dx| = |dy| on the grid.
- qcc_kplugin.geometry.snap_candidate(moving: dict[str, dict], others: dict[str, dict], delta: Point, radius: float) tuple[str, str, Point] | None¶
Best (moving_port, target_port, corrected_delta) when
movingports are translated bydelta.moving/othersmap port names to sidecar ports{"pos", "dir", "a", "b"}. Only translation is considered while dragging; the rebuild solves the rotation forplace.snapexactly.
- qcc_kplugin.geometry.snap_candidate_rot(moving: dict[str, dict], others: dict[str, dict], delta: Point, radius: float, origin: Point = (0.0, 0.0), turn: float = 0.0, rotate: bool = True) tuple[str, str, Point, float] | None¶
Best
(moving_port, target_port, corrected_delta, extra_turn)while dragging, rotation included.moving/othersare sidecar ports{"pos", "dir", "a", "b"}. The held instance is turned byturndegrees aboutorigin(the 90° steps of [ and ]) and translated bydelta. Withrotatea port snaps to any target port of the same CPW, however it faces: the instance is turned byextra_turn(degrees, -180..180) more, so the port faces the target exactly (StarQubit pins 72° apart, ConcentricTransmon couplers at 60°), and the port then has to be withinradiusof the target after that turn. The smallest turn wins ties (a symmetric qubit has four ports that all land on the same spot). Withoutrotateonly ports that already face the target (within 2.5°) snap, withextra_turn0: translation only.corrected_deltais the translation that puts the port on the target.
- qcc_kplugin.geometry.snap_rays(p: Point, q: Point, rays, tol: float, grid: float = 0.0) Point¶
q(the point an axis / 45° snap chose forp), orpput on the nearest ofrays((origin, direction) lines, e.g. an angled port’s own axis) when that ray passes withintolofpand nearer thanq. The distance along the ray is rounded to the grid.
- qcc_kplugin.geometry.tight_segments(points: list[Point], radii: list[float]) list[int]¶
Segments (1-based) too short for the bends at both their ends (the rebuild would fail there).
- qcc_kplugin.geometry.waypoint_insert_index(waypoint_pidx: list[int], segment: int) int¶
Index in
route.nodesfor a new waypoint on polylinesegment(1-based).
- qcc_kplugin.geometry.ALIGN_TOL¶
- qcc_kplugin.geometry.EPS = 1e-06¶
- qcc_kplugin.geometry.FACE_TOL_DEG = 2.5¶
- qcc_kplugin.geometry.Point¶