Routing with Fractional Paths

Prev: Part 8: Reusable Components

This step introduces routing. We’ll focus on fractional routing (manual control) and build a serpentine channel as a reusable custom component.


What is routing?

Routing connects ports with channels. Instead of manually placing a long chain of shapes, you define the start port, end port, and a path, and the router builds the channel geometry for you.

In this step we use fractional routing, which means you define the path as a set of relative steps that add up to the end point.


Router class (high‑level idea)

The Router:

  • Knows your component and its ports
  • Builds channels with a fixed cross‑section (channel_size)
  • Keeps a safety margin (channel_margin) to prevent collisions
  • Collects route requests and then finalizes them into geometry

Fractional routing (how it works)

You pass a list of steps. Each step is a fractional movement along the vector from start to end. For example:

fractional_path = [
    (0.0, 0.3, 1.0),
    (0.4, 0.0, 0.0),
    (0.0, 0.3, 0.0),
    (0.6, 0.0, 0.0),
    (0.0, 0.4, 0.0),
]

The total of each axis should sum to 1.0 (so you end exactly at the target port). Negative values are allowed if you need to double back.


Example — Serpentine component (fractional routing)

We’ll build a serpentine channel as a reusable component. This version is parameterized (e.g., width, loops, levels) and generates the fractional path dynamically, so you can scale the channel without rewriting the route list.

1) Imports + class skeleton

2) Initialize, labels, bulk, and ports

3) Simple routing first (one easy path)

Start with a very simple route so you can see how fractional steps work.

Preview this simple route before moving on.

Simple Fractional Routing

4) Replace with a 2D serpentine (one level)

Now remove the simple routing block above and use a single‑layer serpentine (no Z moves). This helps you learn the pattern before stacking levels.

Preview the 2D serpentine.

Single Level Serpentine

5) Replace with the full 3D serpentine (stacked levels)

Now remove the 2D serpentine above and add Z steps to stack multiple levels.

Preview the full 3D serpentine.

Multi Level Serpentine


Full example

The full script below combines the component setup, ports, and routing into one file so you can run it directly and preview the channel.


Notes

  • Fractional steps should sum to 1.0 on each axis.
  • Negative steps are fine for back‑and‑forth paths like serpentines.
  • Routing builds channels as voids; bulk is still added separately.

Next

Next: Part 10: Using Components in a Device