layouttk 0.1.2

Integer-grid GDSII and OASIS layout processing with hierarchy-aware extraction
Documentation
# Command-line guide

Install the CLI with `cargo install layouttk --locked`. Run `layouttk --help` for the commands and `layouttk create --help` for command-specific options. Use the [Python API](https://docs.rs/layouttk/0.1.2/layouttk/guides/python_api/) for scripted geometry, analysis, and array exchange.

## Create a hierarchical layout

Save the following as `mask.json`. The parent places `PAD` on a one-nanometre grid. Coordinates are integer DBU and layers are `[layer, datatype]`.

```json
{
  "version": 1,
  "name": "MASK",
  "dbu_meters": 1e-9,
  "cells": [
    {"name": "TOP", "elements": [
      {"kind": "reference", "target": "PAD", "origin": [300, -100]}
    ]},
    {"name": "PAD", "elements": [
      {"kind": "rectangle", "layer": [67, 20], "corner1": [0, 0], "corner2": [100, 40]}
    ]}
  ]
}
```

```sh
layouttk create mask.json mask.oas
layouttk create - mask.gds < mask.json
layouttk inspect mask.oas
```

`create` accepts a JSON file or standard input (`-`). The output extension selects GDSII or OASIS. A cell may refer to another definition later in the same request. Omitting the cell's `elements` creates an empty definition. GDSII stores `name` as the library name. OASIS reads back with the name `LIBRARY`.

| `kind` | Required fields | Optional fields |
| --- | --- | --- |
| `rectangle` | `layer`, `corner1`, `corner2` | |
| `polygon` | `layer`, `points` with an implicit closing edge | |
| `path` | `layer`, `points`, nonnegative `width` in DBU | |
| `circle` | `layer`, `center`, `radius` in DBU, for OASIS output | |
| `text` | `layer` with texttype as its second item, `origin`, `text` | |
| `reference` | `target`, `origin` | `angle_deg` (default `0`), `reflect_x` (default `false`), `magnification` (default `1`), `array` |

An `array` contains `columns`, `rows`, `column_step`, and `row_step`. Steps are vectors in the containing cell's coordinates. A path has flush ends. Use Python for custom caps, text styles, typed properties, and other repetition types.

## Inspect, extract, and convert

```sh
layouttk inspect mask.oas
layouttk extract mask.oas metal.gds --top TOP --layer 67/20
layouttk check metal.gds --to oas --json
layouttk convert metal.gds metal.oas
```

- `inspect` prints JSON with `dbu_meters`, `top_cells`, `layers`, and stored counts. A compact array counts as one stored record.
- `extract` applies layer selection while decoding, then keeps the selected root and its dependencies. Repeat `--layer` to retain several layer/type pairs.
- `check --json` reports `can_write` and field-level diagnostics. A failed check exits nonzero. Parse JSON from stdout and read stderr for the process error.
- `create`, `extract`, and `convert` use the target encoder before replacing the destination. To encode a flush path with an odd total width in OASIS, use `--regrid-factor 2` to keep the physical size while doubling integer coordinates.

Use `--oas-budget-bytes` to set the OASIS retained-data budget for input. Query windows, compare geometry by XOR, and make pixel masks with the [Python workflows](https://docs.rs/layouttk/0.1.2/layouttk/guides/python_workflows/) and [binary image tutorial](https://docs.rs/layouttk/0.1.2/layouttk/guides/raster_images/).