|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**naive-svg** is a C++/Python hybrid library for SVG generation with GeoJSON-to-SVG conversion. C++ core (`src/naive_svg.hpp`) provides SVG primitives via a fluent API, exposed to Python through pybind11 bindings (`src/pybind11_naive_svg.cpp`). A pure-Python module (`src/naive_svg/geojson2svg.py`) handles GeoJSON conversion with WGS84/ENU coordinate transforms. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build (editable install with C++ compilation) |
| 13 | +make build |
| 14 | + |
| 15 | +# Run tests |
| 16 | +make pytest # runs pytest tests/test_basic.py |
| 17 | +pytest tests/test_basic.py # core tests |
| 18 | +pytest tests/test_geojson_showcase.py -v -s # showcase with SVG output |
| 19 | + |
| 20 | +# Lint (runs pre-commit hooks: ruff, clang-format, cmake-format, mypy) |
| 21 | +make lint |
| 22 | + |
| 23 | +# Regenerate type stubs after changing C++ bindings |
| 24 | +make restub # runs pybind11-stubgen, copies to src/naive_svg/_core.pyi |
| 25 | +``` |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +### Two-layer design |
| 30 | + |
| 31 | +1. **C++ layer** (`src/naive_svg.hpp`): All SVG types live in `namespace cubao` under `struct SVG`. Element types: `Color`, `Polyline`, `Polygon`, `Circle`, `Text`, `Path`, `Rect`. The `SVG` class is the container that holds elements and produces SVG XML via `write()`/`to_string()`/`dump()`. |
| 32 | + |
| 33 | +2. **Python layer** (`src/naive_svg/`): `_core` is the compiled pybind11 module. `geojson2svg.py` adds GeoJSON parsing, coordinate conversion (via `pybind11_geobuf`), and layered styling. |
| 34 | + |
| 35 | +### Fluent API pattern |
| 36 | + |
| 37 | +The C++ macro `SETUP_FLUENT_API(Klass, VarType, VarName)` generates getter/setter pairs where setters return `Klass&` for chaining. A corresponding pybind11 macro `SETUP_FLUENT_API_PYBIND` mirrors this in Python bindings. When adding new element properties, update both macros. |
| 38 | + |
| 39 | +### Key conventions |
| 40 | + |
| 41 | +- All Python files require `from __future__ import annotations` (enforced by ruff isort). |
| 42 | +- C++ formatted with `.clang-format`; Python with `ruff format`. |
| 43 | +- Type stubs in `stubs/naive_svg/_core.pyi` are auto-generated — edit the C++ bindings, then `make restub`. |
| 44 | +- The C++ header is canonical and synced upstream to `cubao-headers` via `make sync_headers`. |
| 45 | + |
| 46 | +## Source Layout |
| 47 | + |
| 48 | +- `src/naive_svg.hpp` — C++ SVG library (single header) |
| 49 | +- `src/pybind11_naive_svg.cpp` — pybind11 bindings |
| 50 | +- `src/main.cpp` — PYBIND11_MODULE entry point |
| 51 | +- `src/naive_svg/geojson2svg.py` — GeoJSON-to-SVG converter (pure Python) |
| 52 | +- `src/naive_svg/_core.pyi` — auto-generated type stubs |
| 53 | +- `tests/test_basic.py` — unit tests for C++ bindings and geojson2svg |
| 54 | +- `tests/test_geojson_showcase.py` — integration test generating showcase SVG |
0 commit comments