layouttk 0.5.0

GDSII and OASIS layout toolkit for layer extraction, verification, and window clipping
Documentation
# Migrating a gdspy workflow

Start with one representative cell. Record its library unit and precision, the selected layer/datatype pairs, its references, and one physical dimension you can measure. Export the same cell from both scripts and compare it in KLayout. Instance transforms, text orientation and properties need separate checks even when the filled regions match.

## Coordinates and ownership

gdspy drawing coordinates are in the library's user unit. layouttk stores integer database units (DBU) in a cell. For `unit=1e-6` and `precision=1e-9`, 2.5 gdspy user units corresponds to 2,500 DBU. Specify the source unit before converting. Lengths in layouttk files and cells are DBU and areas are square DBU. Placement and polygon parameters named `angle_deg` take degrees. Path arcs and turns take radians. `Layout` owns definitions explicitly and a `Cell` is a live handle. `Cell.elements()` returns snapshots.

## Drawing, paths and geometry

| gdspy entry points | layouttk entry points | Migration detail |
| --- | --- | --- |
| `Polygon`, `PolygonSet` | `Polygon`, `PolygonSet`, `Cell.add_polygon` | Use drafts for a sequence of fractional transforms. Direct insertion takes integer coordinates. Each draft member can retain its own layer and properties. |
| `Rectangle`, `Round` | `rectangle`, `ellipse`, `elliptic_sector`, `fracture` | Set tolerance or an explicit sector vertex count. Fracture to a maximum output vertex count after sampling. `Layout.add_circle` preserves an OASIS circle. |
| `Text`, `Label` | `polygon_text`, `add_polygon_text`, `Layout.add_text` | Mask lettering is geometry. A text label stores content, anchor and presentation. Check label orientation after a reflected placement. |
| `rotate`, `scale`, `translate`, `mirror`, `copy` | Draft transforms, `transform_points`, `scale_points`, `mirror_points`, `hierarchy.transform_elements` | Drafts postpone quantization. Copy before mutating a draft when the original is needed. |
| `area`, `get_bounding_box` | Draft `area`, `bounds`, `area_by_layer()`, or functions in `hierarchy` | Individual overlapping shapes can be counted twice. Use `Region.area` for the area of filled material. |
| `boolean`, `fast_boolean`, `offset`, `slice`, `inside`, `fillet`, `fracture` | Functions of the same operation name, Boolean operators on `Region` | Winding identifies holes. Use `fracture` for independent filled pieces. For a group of points, apply `any` or `all` to the containment results. |
| `Curve` line, SVG-like and Bézier commands, arcs, interpolation | `Curve.segment`, `horizontal`, `vertical`, `quadratic`, `cubic`, smooth variants, `bezier`, `interpolation`, `arc` | `points()` gives sampled coordinates and `grid_points()` quantizes them. Choose a tolerance suitable for the grid. |
| `Path`, `PolyPath`, `L1Path` | `Path`, `PolyPath`, `L1Path` | Construct segments, arcs, turns and parametric sections. Use `length` for centreline length. Curved sections with no analytic length use sampled segments. |
| `FlexPath`, `RobustPath` | `FlexPath`, `RobustPath`, `PathBuilder` | Set widths, offsets, joins and ends per track. `to_polygons` gives outlines. Store an outline when a native PATH cannot represent its shape. |
| `RobustPath.__call__`, `grad`, `width` | `track_positions`, `track_gradients`, `widths_at`, `offsets_at` | Specify the arm and choose the side of a segment junction for a one-sided query. Positive offset is left of the direction of travel. |

An independently offset set of polygons can differ from a union offset as a group. `PolygonSet.offset(..., join_first=False)` keeps the inputs separate, `join_first=True` merges within each layer, and `Region.sized` operates on filled material. Check the XOR, area and vertex budget when migrating. Ring seams, emitted polygon order and tessellation can differ. [Polygon drafting guide](https://docs.rs/layouttk/0.5.0/layouttk/guides/polygon_drafts/)

## Cells, arrays, files and inspection

| gdspy entry points | layouttk entry points | Migration detail |
| --- | --- | --- |
| `GdsLibrary`, `current_library`, `new_cell`, `top_level` | `Layout`, `add_cell`, `top_cells` | Pass a layout to cell factories. Iterating it yields cell handles. Iterating a cell yields direct element snapshots. |
| `Cell.add`, `copy`, `remove_polygons`, `remove_paths`, `remove_labels` | `Cell.add_*`, `Layout.add_*`, `hierarchy.copy_cell`, `remove_elements` | A copied definition has independent elements. Its nested references still point to their targets. |
| `CellReference`, `CellArray` | `Cell.add_reference`, `Layout.set_repetition` | Regular step vectors for references are in the parent frame. For explicit OASIS offsets, include additional placements only. The origin is implicit. |
| `get_layers`, `get_datatypes`, `get_texttypes`, `get_svg_classes` | `Cell.layers`, `hierarchy.tags` | Keep layer/type pairs together. `tags` accepts separate text and shape selection and a traversal depth. |
| `get_polygons`, `get_polygonsets`, `get_paths`, `get_labels` | `hierarchy.polygons`, `placed_elements`, `paths`, `labels` | Select a layer, depth and expansion limit. A label query composes parent transforms by default. |
| `get_dependencies`, `flatten`, reference-level queries | `hierarchy.dependencies`, `flatten`, `reference_layout`, `reference_boxes` | Flattening can remove the owner of instance properties. Review the diagnostics before choosing a discard policy. |
| `add`, `remove`, `extract`, `rename_cell`, `replace_references` on libraries | `hierarchy.import_cells`, `remove_cell`, `extract_cells`, `rename_cell`, `replace_references` | Inspect conflict mappings on import. Use an explicit grid policy when combining libraries. |
| `read_gds`, `write_gds`, top-level `write_gds` | `Layout.read`, `from_bytes`, `write`, `to_bytes` | Reads retain source DBU. Use `resample` for a physical conversion. To reproduce gdspy's `units="skip"`, reinterpret the DBU as `src_precision * (dst_unit / src_unit)`, then resample to the destination precision. |
| `GdsWriter`, `get_binary_cells`, `get_gds_units`, `gdsii_hash`, `set_gdsii_timestamp` | `layouttk.gds_tools` | Stream complete definitions or reassemble raw GDS structures. Resolve external targets when assembling a final library. |
| `to_gds`, `to_svg`, `write_svg`, `LayoutViewer` | `element_bytes`, `cell_bytes`, `svg_fragment`, `write_svg`, `write_viewer` | Export an element with its dependencies or generate an offline HTML viewer with a ruler, layer controls and hierarchy depth. |

## Coverage of the inventory

The inventory uses gdspy 1.6.13 at commit `5234778068e8d85dde955056517dd5f95379b6d4`. It counts **18 exported classes, 11 top-level functions and 126 directly declared public class methods** (66 distinct method names). It includes deprecated entry points and the optional viewer. Constructors, inherited methods, global library state and the four domain-specific special methods are considered by behavior. Coverage refers to these workflow families. Existing scripts need adaptation and parameter combinations can have different numerical behavior. [gdspy exports at the audited revision](https://github.com/heitzmann/gdspy/blob/5234778068e8d85dde955056517dd5f95379b6d4/gdspy/__init__.py) · [gdspy reference](https://gdspy.readthedocs.io/en/stable/reference.html)

For a migration test, compare per-layer XOR and bounding boxes, then compare the reference graph, labels, repetition offsets and typed properties. Use byte comparisons for raw records and fixed timestamps when testing hashes. Preserve a regression fixture for half-grid inputs, odd-width paths, label transforms, absolute widths and high coordinates. Non-orthogonal transforms reaching 2⁵² DBU can require more floating-point precision than the operation supports. [Worked cross-reader example](https://docs.rs/layouttk/0.5.0/layouttk/guides/python_workflows/) · [Upstream evidence](https://docs.rs/layouttk/0.5.0/layouttk/guides/upstream_research_and_roadmap/)