vecview 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. vecview-0.3.0/AGENTS.md +203 -0
  2. {vecview-0.2.0 → vecview-0.3.0}/CHANGELOG.md +136 -0
  3. {vecview-0.2.0 → vecview-0.3.0}/PKG-INFO +93 -37
  4. {vecview-0.2.0 → vecview-0.3.0}/README.md +90 -33
  5. vecview-0.3.0/docs/animation.md +293 -0
  6. {vecview-0.2.0 → vecview-0.3.0}/docs/cameras.md +115 -35
  7. {vecview-0.2.0 → vecview-0.3.0}/docs/development.md +56 -14
  8. {vecview-0.2.0 → vecview-0.3.0}/docs/embedding.md +40 -16
  9. vecview-0.3.0/docs/gallery/altermagnetic_dot.svg +1 -0
  10. vecview-0.3.0/docs/gallery/bloch_sphere.svg +1 -0
  11. vecview-0.3.0/docs/gallery/brillouin_zone.svg +1 -0
  12. vecview-0.3.0/docs/gallery/dirac_cone.svg +1 -0
  13. vecview-0.3.0/docs/gallery/fullerene.svg +1 -0
  14. vecview-0.3.0/docs/gallery/kitaev_chain.svg +1 -0
  15. vecview-0.3.0/docs/gallery/mirror_planes.svg +1 -0
  16. vecview-0.3.0/docs/gallery/perovskite.svg +1 -0
  17. {vecview-0.2.0 → vecview-0.3.0}/docs/gallery/skyrmion.svg +1 -1
  18. vecview-0.3.0/docs/gallery/slab_polarizer.svg +1 -0
  19. vecview-0.3.0/docs/gallery/solenoid.svg +1 -0
  20. {vecview-0.2.0 → vecview-0.3.0}/docs/gallery.md +51 -26
  21. vecview-0.3.0/docs/images/readme.svg +1 -0
  22. {vecview-0.2.0 → vecview-0.3.0}/docs/index.md +27 -20
  23. vecview-0.3.0/docs/outlines.md +99 -0
  24. vecview-0.3.0/docs/scenes.md +714 -0
  25. {vecview-0.2.0 → vecview-0.3.0}/docs/shapes.md +94 -22
  26. vecview-0.3.0/examples/README.md +54 -0
  27. vecview-0.3.0/examples/__main__.py +69 -0
  28. {vecview-0.2.0 → vecview-0.3.0}/examples/altermagnetic_dot.py +157 -127
  29. vecview-0.3.0/examples/bloch_sphere.py +175 -0
  30. {vecview-0.2.0/examples/gallery → vecview-0.3.0/examples}/brillouin_zone.py +65 -26
  31. vecview-0.3.0/examples/dirac_cone.py +150 -0
  32. {vecview-0.2.0/examples/gallery → vecview-0.3.0/examples}/fullerene.py +36 -39
  33. vecview-0.3.0/examples/kitaev_chain.py +370 -0
  34. {vecview-0.2.0/examples/gallery → vecview-0.3.0/examples}/mirror_planes.py +18 -19
  35. vecview-0.3.0/examples/pendulum.py +129 -0
  36. {vecview-0.2.0/examples/gallery → vecview-0.3.0/examples}/perovskite.py +42 -34
  37. vecview-0.3.0/examples/rotating_dipole.py +276 -0
  38. vecview-0.3.0/examples/skyrmion.py +85 -0
  39. {vecview-0.2.0 → vecview-0.3.0}/examples/slab_polarizer.py +153 -163
  40. {vecview-0.2.0/examples/gallery → vecview-0.3.0/examples}/solenoid.py +46 -21
  41. {vecview-0.2.0 → vecview-0.3.0}/pyproject.toml +2 -5
  42. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/__init__.py +13 -3
  43. vecview-0.3.0/src/vecview/_animation_refs.py +119 -0
  44. vecview-0.3.0/src/vecview/_animation_svg.py +469 -0
  45. vecview-0.3.0/src/vecview/_canvas.py +871 -0
  46. vecview-0.3.0/src/vecview/_drawing.py +925 -0
  47. vecview-0.3.0/src/vecview/_elements.py +181 -0
  48. vecview-0.3.0/src/vecview/_numeric.py +30 -0
  49. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/_occlusion.py +124 -48
  50. vecview-0.3.0/src/vecview/_place.py +173 -0
  51. vecview-0.3.0/src/vecview/_solids.py +566 -0
  52. vecview-0.3.0/src/vecview/_tracks.py +113 -0
  53. vecview-0.3.0/src/vecview/_transforms.py +59 -0
  54. vecview-0.3.0/src/vecview/animation.py +159 -0
  55. vecview-0.3.0/src/vecview/outlines.py +231 -0
  56. vecview-0.3.0/src/vecview/scene.py +335 -0
  57. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/shapes.py +176 -23
  58. vecview-0.3.0/tests/test_animation.py +449 -0
  59. {vecview-0.2.0 → vecview-0.3.0}/tests/test_occlusion.py +21 -38
  60. vecview-0.3.0/tests/test_outlines.py +171 -0
  61. {vecview-0.2.0 → vecview-0.3.0}/tests/test_package_metadata.py +27 -3
  62. vecview-0.3.0/tests/test_parts.py +254 -0
  63. {vecview-0.2.0 → vecview-0.3.0}/tests/test_scene.py +158 -4
  64. {vecview-0.2.0 → vecview-0.3.0}/tests/test_shapes.py +152 -0
  65. {vecview-0.2.0 → vecview-0.3.0}/tests/test_solids.py +25 -5
  66. vecview-0.3.0/tests/test_tracked_scenes.py +116 -0
  67. {vecview-0.2.0 → vecview-0.3.0}/zensical.toml +2 -0
  68. vecview-0.2.0/AGENTS.md +0 -116
  69. vecview-0.2.0/docs/gallery/altermagnetic_dot.svg +0 -1
  70. vecview-0.2.0/docs/gallery/bloch_sphere.svg +0 -1
  71. vecview-0.2.0/docs/gallery/brillouin_zone.svg +0 -1
  72. vecview-0.2.0/docs/gallery/dirac_cone.svg +0 -1
  73. vecview-0.2.0/docs/gallery/fullerene.svg +0 -1
  74. vecview-0.2.0/docs/gallery/mirror_planes.svg +0 -1
  75. vecview-0.2.0/docs/gallery/perovskite.svg +0 -1
  76. vecview-0.2.0/docs/gallery/slab_polarizer.svg +0 -1
  77. vecview-0.2.0/docs/gallery/solenoid.svg +0 -1
  78. vecview-0.2.0/docs/images/readme.svg +0 -1
  79. vecview-0.2.0/docs/scenes.md +0 -513
  80. vecview-0.2.0/examples/gallery/__main__.py +0 -78
  81. vecview-0.2.0/examples/gallery/_common.py +0 -39
  82. vecview-0.2.0/examples/gallery/bloch_sphere.py +0 -126
  83. vecview-0.2.0/examples/gallery/dirac_cone.py +0 -93
  84. vecview-0.2.0/examples/gallery/skyrmion.py +0 -71
  85. vecview-0.2.0/src/vecview/scene.py +0 -2427
  86. {vecview-0.2.0 → vecview-0.3.0}/.gitignore +0 -0
  87. {vecview-0.2.0 → vecview-0.3.0}/LICENSE +0 -0
  88. {vecview-0.2.0 → vecview-0.3.0}/docs/readme_figure.py +0 -0
  89. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/_types.py +0 -0
  90. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/_vec.py +0 -0
  91. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/camera.py +0 -0
  92. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/projections.py +0 -0
  93. {vecview-0.2.0 → vecview-0.3.0}/src/vecview/py.typed +0 -0
  94. {vecview-0.2.0 → vecview-0.3.0}/tests/test_camera.py +0 -0
  95. {vecview-0.2.0 → vecview-0.3.0}/tests/test_document.py +0 -0
  96. {vecview-0.2.0 → vecview-0.3.0}/tests/test_planes.py +0 -0
  97. {vecview-0.2.0 → vecview-0.3.0}/tests/test_projections.py +0 -0
@@ -0,0 +1,203 @@
1
+ # VecView contributor guide
2
+
3
+ ## Scope
4
+
5
+ `vecview` projects world-space geometry into one SVG document, with an explicit
6
+ layer stack. It does not plot data, compile TeX, rasterize, export PDF, compose
7
+ multi-panel figures, or edit existing SVG.
8
+
9
+ The package is **independent and has no downstream dependencies**. Consumers
10
+ integrate through `Scene.to_svg_document()` alone; that direction is one-way.
11
+ Do not add a consumer-specific adapter, import, dependency, example, or test.
12
+
13
+ Naming the sibling projects is fine where it is only provenance: `vecview` is
14
+ developed alongside FigWorks and VecTeX as a suite, and a "Related projects"
15
+ link says so. What must stay out is *coupling* -- consumer-specific API
16
+ documentation, worked integration examples, or tests that import a consumer.
17
+ A tool that composes figures from `vecview` output documents that integration
18
+ on its own side.
19
+
20
+ ## Architecture
21
+
22
+ - Keep the three-way split, and do not let it blur:
23
+ - `shapes.py` knows numbers only — world-space arrays and `Face` records. No
24
+ camera, no style, no SVG import.
25
+ - `outlines.py` is the same in 2D: `(n, 2)` footprints and cross-sections,
26
+ combined through `shapely`, which is the only module besides `_occlusion.py`
27
+ that imports it. A result an outline cannot hold -- a hole -- raises
28
+ rather than being dropped.
29
+ - `camera.py` defines what a camera *is*: `Camera` (the abstract contract) and
30
+ `ParallelCamera` (the affine machinery). Back-face culling lives here
31
+ because it is a camera question, not a scene one.
32
+ - `projections.py` holds the concrete projections: `OrthographicCamera` and
33
+ `ObliqueCamera`.
34
+ - Only the rendering modules import `svg`: `scene.py` and the private
35
+ `_elements.py`, `_canvas.py`, and `_solids.py`, and for animation
36
+ `_animation_svg.py` and `_animation_refs.py`. `shapes.py`, `camera.py`,
37
+ `projections.py`, `_occlusion.py`, `_place.py`, `_drawing.py`,
38
+ `_tracks.py`, and `_transforms.py` never do.
39
+ - `animation.py` samples a pure time-to-scene callback through the static
40
+ renderer and writes once what every frame draws alike. A scene holding tracks
41
+ is that callback underneath: a drawing call given a `Track` anywhere in its
42
+ arguments is kept as made (`_Tracked`, via `_trackable` in `_drawing.py`),
43
+ and `at(t)` replays it with the tracks read, sharing the calls without one.
44
+ A frame is drawn exactly as the same scene would be as a still; do not add an
45
+ animation-only rendering path. A new drawing call needs `@_trackable`.
46
+ - `_occlusion.py` is private: exact visibility for `sort_by_depth(layer)`.
47
+ The canvas describes each element of a sorted layer as a `Surface` (outline
48
+ plus a depth that goes on smoothly past its edge) or a `Line`, lazily, and
49
+ `resolve` clips and splits them. Keep closed-form depths closed-form.
50
+ Its shapely work is batched -- one tree query, then one vectorised call per
51
+ stage over every pair -- because per-call overhead, not GEOS, was most of the
52
+ time; keep new stages batched. Pairs keep the order the tree returns them in,
53
+ which fixes the order of everything built from them and so the output bytes.
54
+ - `_vec.py` and `_types.py` are private. Re-export from `__init__.py` what should
55
+ be public; `unit` is the only helper promoted so far.
56
+ - Geometry that needs a camera to be computed does not belong in `shapes.py`.
57
+ - Angles are degrees at every public boundary, radians nowhere.
58
+ - Keep the camera hierarchy honest. `Camera` promises only `project`, `at`,
59
+ `depth`, and `visible`. `direction`, `screen_basis`, `foreshortening`, and
60
+ `plane_matrix` belong on `ParallelCamera` because each assumes a screen offset
61
+ independent of position. Moving any of them up would make them a silent wrong
62
+ answer for a perspective camera, which would subclass `Camera` directly.
63
+ - `Scene.plane` reserves a group and nothing more. This package must not parse,
64
+ normalize, or embed foreign SVG; a consumer fills the group by id.
65
+ - `Scene.slot` may hold an svg.py element passed as `content`, placed as given
66
+ in the aligned box and never parsed, copied, or rewritten. That is the one
67
+ way content from elsewhere -- a VecTeX label -- goes into a scene without a
68
+ consumer; anything that would need VecView to read or change it does not.
69
+ - `Scene` records objects and nothing else; it never projects. Every public
70
+ drawing method validates what it can without a camera and appends one record.
71
+ The canvas holds a camera and implements each method of the same name;
72
+ rendering replays the record onto a fresh canvas. Camera-dependent work and
73
+ errors belong in the canvas, and a canvas never records, so its methods may
74
+ call each other freely. `_Canvas` (`_canvas.py`) has the layer stack, exact
75
+ visibility, and the flat calls; `_SolidCanvas` (`_solids.py`) adds the curved
76
+ solids and is the canvas a render uses. `_elements.py` holds the SVG emission
77
+ helpers both share.
78
+ - The world-space drawing calls live on the private `_Drawing` base
79
+ (`_drawing.py`, with `Part`), shared by
80
+ `Scene` and `Part`. `Scene` adds what only makes sense for a whole document:
81
+ cameras, rendering, `sort_by_depth` (a property of the layer stack), `<defs>`,
82
+ raw elements, and screen-space calls. Keep a call off `_Drawing` unless it has
83
+ a world position, because a part must be able to move everything it holds.
84
+ - `place` copies a part's recorded calls with their geometry moved by a `_Frame`
85
+ (`_place.py`).
86
+ `_MOVES` says, per call, which arguments are points, directions, edges, or
87
+ lengths. A new world-space call needs an entry there, or placing it fails with
88
+ a `KeyError`; `tests/test_parts.py` places one of every call.
89
+
90
+ ## Module size
91
+
92
+ - No Python file in the repository exceeds **1000 lines**, pylint's default
93
+ `max-module-lines` (C0302). `tests/test_package_metadata.py` enforces it.
94
+ - Aim for a few hundred lines. When a module nears the limit, split it before
95
+ adding to it, along a real seam of responsibility -- emission, visibility,
96
+ solids -- not into arbitrary halves, and keep the output byte-identical: a
97
+ split moves code, it does not change it.
98
+
99
+ ## Deliberate non-features
100
+
101
+ Do not add these without the user changing the design first:
102
+
103
+ - **Automatic depth sorting across layers** (a z-buffer, or sorting a layer that
104
+ did not ask). Layers are the model. A beam crossing a translucent slab has
105
+ three parts that no automatic depth rule orders correctly. Depth only ever
106
+ acts inside a layer passed to `Scene.sort_by_depth`, and there it is exact
107
+ visibility by clipping -- there is no painter's-algorithm mode, so do not add
108
+ geometry workarounds for one (cutting solids into pieces so they sort).
109
+ - **Rasterizing or PDF export.** Runtime dependencies stay `numpy`, `svg.py`,
110
+ `shapely`, and `contourpy`; a test in `tests/test_package_metadata.py`
111
+ enforces it. The last two are required because robust polygon clipping and
112
+ sub-pixel contours -- exact visibility, booleans on outlines -- are not worth
113
+ reimplementing. There are no runtime extras.
114
+ - **Shading, materials, or lighting models.** This draws schematics, not renders.
115
+ `highlight=` gradients are a fill style fixed on screen, with no light
116
+ direction; keep them that way.
117
+
118
+ ## Development
119
+
120
+ - Supported Python: 3.12 and newer.
121
+ - `uv sync --all-extras` for a full environment.
122
+ - Run `uv run ruff format --check .`, `uv run ruff check .`, `uv run ty check`,
123
+ and `uv run pytest` before reporting a change complete.
124
+ - Typing serves the code, not the other way round. Type public signatures and
125
+ what types naturally, and keep `ty check` passing; where precise types would
126
+ contort the code -- a decorator that changes what a parameter accepts, say --
127
+ use a looser annotation or a targeted `# ty: ignore[code]`. Do not raise the
128
+ Python floor for typing features.
129
+ - Run `uv run python examples/slab_polarizer.py --projection all`,
130
+ `uv run python examples/altermagnetic_dot.py --projection all`, and
131
+ `uv run python examples` after touching geometry or projection, and
132
+ look at `examples/out/*.png` after touching a solid, an outline, or
133
+ the depth sort. Refresh `docs/gallery/` with `--docs` when a figure changes. It is the realistic end-to-end check, and it renders
134
+ pictures whose correctness is visible. Mirrored or upside-down content, or a
135
+ beam that misses the slab, is the usual symptom of a projection bug.
136
+ - Keep output deterministic: layer ties resolve by insertion order, coordinates
137
+ are rounded on emission. Byte-identical output is what keeps a figure diffable.
138
+
139
+ ## Examples
140
+
141
+ The examples -- `examples/*.py`, `examples/README.md`, and `docs/readme_figure.py`
142
+ -- are the showcase. People read them to learn the library, so they must read as
143
+ the obvious way to draw the figure, not as a record of how it was first got to
144
+ work.
145
+
146
+ - After adding a public function or parameter, go through every example and use
147
+ it wherever it makes the code shorter or clearer, in the same piece of work.
148
+ A helper an example wrote for itself that the library now provides is
149
+ deleted, not kept beside the new call.
150
+ - Prefer the library's vocabulary to hand-rolled geometry: `extrude` over axis
151
+ permutations, `place` over copy-pasted blocks, `cull=True` over
152
+ `cam.visible`, `class_` for kinds of objects.
153
+ - Name things for what they are in the figure (`gate`, `contact`, `beam`), keep
154
+ each function to one part of the picture, and comment the physics or the
155
+ design decision, not the Python.
156
+ - A simplification must not change the picture: check the rendered PNGs, and
157
+ say so if an id or a pixel changed on purpose.
158
+
159
+ ## Testing
160
+
161
+ - Test geometry as numbers, not as rendered strings: winding against declared
162
+ normal, a wave against an exact sine, a circle's radius. Reserve
163
+ rendered-output assertions for document structure.
164
+ - Add a regression test for every projection or winding bug — a wrong normal is
165
+ invisible until it culls the wrong wall.
166
+ - Test a projection through `foreshortening()`, not through its construction
167
+ angles: the ratios are what the axonometric classification is defined by.
168
+ - Rendering under a camera must stay byte-identical to building the scene with
169
+ that camera from the start. The parametrized test in `tests/test_scene.py`
170
+ covers all five projections.
171
+ - `tests/test_document.py` pins what a consumer relies on: a parseable
172
+ standalone document, a viewBox agreeing with `width`/`height`, geometry inside
173
+ it, and deterministic bytes. It must not import a consumer.
174
+
175
+ ## Documentation
176
+
177
+ Documentation is part of every change, not a follow-up. A change is not complete,
178
+ and must not be committed, until the documentation agrees with it.
179
+
180
+ - Every user-visible change -- a new call or parameter, a changed default or
181
+ behaviour, a new error, a renamed id -- updates, in the same commit: the
182
+ docstrings, the relevant page in `docs/`, `README.md` wherever it summarizes
183
+ the feature, and `CHANGELOG.md` (Keep a Changelog 1.1.0).
184
+ - Documentation states what the code does, checked against the code: every
185
+ signature, default, generated id, and error matches the source, and every
186
+ runnable snippet runs. Do not document intentions or planned features.
187
+ - When a change makes a passage elsewhere wrong, fix that passage in the same
188
+ commit, even on a page the change did not otherwise touch.
189
+ - When a figure's output changes, refresh `docs/gallery/` with
190
+ `uv run python examples --docs`, and `docs/images/` with
191
+ `uv run python docs/readme_figure.py`.
192
+ - Run `uv run zensical build` and confirm it reports no issues before reporting
193
+ the change complete.
194
+
195
+ ## Naming and packaging
196
+
197
+ - **`vecview` is the distribution and import name**, published on PyPI since
198
+ 0.2.0. See `docs/development.md` for the rename procedure, should it ever be
199
+ needed.
200
+ - `pyproject.toml` is canonical for Python metadata.
201
+ - Do not commit, tag, upload, or publish unless the user explicitly asks.
202
+ - Before 1.0, make API changes directly: update consumers, tests, and docs in the
203
+ same change. No compatibility aliases or deprecated wrappers.
@@ -5,6 +5,142 @@ All notable changes to this project are documented here, following
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.3.0] - 2026-10-08
9
+
10
+ Animation is new in this release, and its API may still change before 1.0.
11
+
12
+ ### Added
13
+
14
+ - `slot(..., content=element)` -- a slot can hold an svg.py element instead of
15
+ waiting for a consumer to fill it: the element, `w` by `h` in its own
16
+ coordinates from its top-left, is placed with its box aligned on the anchor,
17
+ and follows every camera. VecView places it as given, never parsing, copying,
18
+ or changing it. The examples with mathematical labels now typeset them with
19
+ VecTeX and hold them in slots, in place of `svg.TSpan` subscripts.
20
+ - `Animation(scene, *, duration, view_box, fps=30, repeat=1, background=None)`
21
+ -- a scene that moves, sampled at evenly spaced times, rendered by the
22
+ static renderer, and written as one standalone SVG that plays itself with
23
+ native SVG timing. Any argument of any drawing call may be a `Track`, inside
24
+ lists and style keywords too; `place` takes a track of parts, for what
25
+ changes in number, and the active camera may be a track. A call holding a
26
+ track is checked at `t = 0` and kept as made; `Scene.at(t)` and `Part.at(t)`
27
+ give the drawing as it stands at `t`, and a scene with tracks renders as it
28
+ stands at `t = 0`. `Animation` also takes a pure function from seconds to a
29
+ whole `Scene`. Finite playback holds the exact
30
+ frame at `duration`; `repeat=None` loops. What every frame draws alike --
31
+ identical definitions, and the elements every frame draws in the same paint
32
+ order, wherever they fall -- is written once, in place, with its own ids.
33
+ Each stretch that changes is one `<use>` whose `href` steps through its
34
+ distinct contents with discrete timing, each written once in `<defs>` with
35
+ its ids renamed `frame{i}-{id}` (the original kept as `data-vecview-id`);
36
+ a stretch is cut at layer boundaries and per element wherever that is
37
+ estimated to be smaller, a lone element is its own target, and an animation
38
+ that never changes is a static document. `animation.breakdown()` says where
39
+ the file's bytes go, stretch by stretch.
40
+ - `vecview.animation`: `Track` with `keyframes` and `map`, the interpolators
41
+ `linear` (numbers and 3D points) and `hold`, the easing `smoothstep`, and
42
+ `rotate` and `scale`, which copy a part turned or scaled about a pivot and
43
+ take tracks too.
44
+ - `examples/pendulum.py` -- a pendulum swinging through one seamless period,
45
+ with its equations typeset by VecTeX. See `docs/animation.md`.
46
+ - `examples/rotating_dipole.py` -- a rotating electric dipole and the exact
47
+ retarded field it radiates: `E` as arrows and `B_z` as spiral shading over
48
+ the equatorial plane, through one seamless period.
49
+
50
+ - `class_=` on every drawing call that takes style keywords: one string,
51
+ space-separated, or a sequence of names. An id names one object, a class a
52
+ kind of object -- every gate, every oxygen -- for a stylesheet, a selector in
53
+ the composing tool, or Inkscape to reach together. Each top-level element a
54
+ call emits carries the classes (every face, both strokes of an edge set, every
55
+ slice of a sliced solid, both parts of a line a depth-sorted layer splits) and the
56
+ elements inside a solid's group do not, so a selector matches each object
57
+ once. Names that are not strings raise `TypeError` at the call.
58
+ - `Part` and `place` -- objects drawn once, in their own coordinates, and
59
+ placed any number of times: `place(layer, part, at=, rotate=(axis, deg),
60
+ mirror=, scale=, id=, class_=)`. Only rigid motions and a uniform scale, so
61
+ every solid keeps its exact outline; faces stay wound to their normals under a
62
+ mirror. The placement's layer is added to the part's layers, `id` prefixes
63
+ every id in the part, `class_` is added to its classes, and parts nest. A
64
+ part holds only world-space calls: no camera, `<defs>`, screen-space calls, or
65
+ depth sorting, which stay the scene's.
66
+ - `extrude(section, along)` -- a planar cross-section in any plane swept along
67
+ any vector, as correctly wound `Face`s named `"start"`, `"end"`, and
68
+ `"side-{i}"`. Wall `i` is built on section edge `i` as given, in either
69
+ winding, so walls can be picked out by edge. `prism_faces` is now the
70
+ special case along `z`, with unchanged output.
71
+ - `vecview.outlines` -- footprints and cross-sections built in 2D: `rect`,
72
+ `regular`, `offset`, `film` (a layer of given thickness deposited on a run of
73
+ edges, numbered as `extrude` numbers walls), `union`, `difference`,
74
+ `intersection`, and `to_plane` to lift an outline into 3D. Results are
75
+ counter-clockwise and ordered deterministically; a result with a hole
76
+ raises `ValueError` rather than dropping it.
77
+ - `cut(faces, origin, normal)` -- a closed solid cut open by a plane, for a
78
+ cutaway: faces are clipped and keep their names, and the cut is capped by
79
+ faces named `"cut"` (or `"cut-0"`, ...) lying in the plane, so a section can
80
+ be styled apart. Non-convex solids work; a cap with a hole raises.
81
+ - `examples/kitaev_chain.py` -- a minimal Kitaev chain after Dvir et
82
+ al., Nature 614, 445 (2023): a gated InSb nanowire running past draped Cr/Au
83
+ contacts, a grounded Al shell of finite thickness that continues onto the
84
+ dielectric, and a Majorana mode on each dot.
85
+ - A documentation page for `vecview.outlines`.
86
+
87
+ ### Changed
88
+
89
+ - Depth-sorted layers render faster, with byte-identical output: exact
90
+ visibility makes its shapely calls in batches -- one tree query, and one
91
+ vectorised intersection for every overlapping pair -- and orders the painting
92
+ of clipped surfaces with a heap. The Dirac cone renders in 0.61 of the time,
93
+ the solenoid in 0.79.
94
+ - The examples are self-contained scripts side by side in `examples/`, each
95
+ writing its own SVG to `examples/out`; `examples/gallery/` and the shared
96
+ `_common.py` are gone. `python examples` builds them all, with timings and
97
+ PNG previews, and `--docs` still refreshes `docs/gallery/`.
98
+ - `sort_by_depth(layer)` always decides visibility exactly, point by point:
99
+ surfaces are clipped where an opaque surface hides them, lines are split, and
100
+ a surface hidden entirely is dropped. The painter's algorithm keyed on each
101
+ element's mean depth is gone, and with it the need to cut geometry so it
102
+ sorts: a coil wraps an unsliced core. A sorted layer renders in up to a few
103
+ seconds and can double in size, from its clip paths.
104
+ - `shapely` and `contourpy` are required dependencies, alongside `numpy` and
105
+ `svg.py`, and the `occlusion` extra is gone: exact visibility always works,
106
+ and robust polygon clipping is needed beyond it, for booleans on outlines.
107
+ Both still load only when first needed.
108
+ - An unsliced cylinder or cone names its end disks `{id}-end0` and `{id}-end1`
109
+ and its highlight gradient `{id}-shade`, as a sliced one already did, instead
110
+ of `{id}-body-end0` and `{id}-body-shade`. Slicing no longer renames what a
111
+ consumer selects.
112
+ - Rendering raises `ValueError` when two elements share an id, naming every
113
+ id used more than once. Duplicate ids are invalid SVG, and a consumer
114
+ selecting by id -- or a `url(#...)` fill -- would silently reach the wrong
115
+ element. Ids a call derives (`slab-pz`, `{id}-body`, `{id}-profile`) are
116
+ checked too, so a hand-written id that collides with one is caught.
117
+ - Every example is rewritten with the new API -- `Part` and `place` for
118
+ repeated and mirrored objects, `extrude` and `outlines` for cross-sections,
119
+ `class_` for every kind of object -- and reads as the obvious way to draw its
120
+ figure. The pictures are unchanged apart from the depth-sorted ones.
121
+ - The documentation is checked against the code, page by page: wrong
122
+ signatures, ids, and claims fixed, every runnable snippet run, and the
123
+ missing public API documented.
124
+
125
+ ### Removed
126
+
127
+ - `sort_by_depth(..., exact=True)`: every sorted layer is exact now, so the
128
+ keyword is gone and passing it raises `TypeError`.
129
+
130
+ ### Fixed
131
+
132
+ - Text is escaped: a label holding `<`, `>`, or `&` -- `"B < 0"`, `"Smith &
133
+ Jones"` -- made the document unreadable, because svg.py writes text as it is
134
+ given. `text`, `text2d`, and their `svg.TSpan` runs are escaped now, the
135
+ runs copied rather than changed.
136
+ - `double_arrow_shape` clamps a `head_len` longer than half the arrow, as
137
+ `arrow_shape` already did, instead of returning a self-crossing polygon.
138
+ - `Scene.is_empty` is true exactly when rendering would find nothing to fit a
139
+ viewBox to. A scene holding only `add`, or `rect2d` and `text2d` with
140
+ `grow=False`, was reported non-empty and then failed to render.
141
+ - The background `<rect>` takes the viewBox's rounded numbers, so it covers
142
+ the viewBox exactly and no longer carries full-precision floats.
143
+
8
144
  ## [0.2.0] - 2026-10-06
9
145
 
10
146
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vecview
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Layered 3D scenes that render to SVG, for scientific schematics
5
5
  Project-URL: Source, https://github.com/maiani/vecview
6
6
  Project-URL: Issues, https://github.com/maiani/vecview/issues
@@ -20,13 +20,12 @@ Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
20
20
  Classifier: Topic :: Scientific/Engineering :: Visualization
21
21
  Classifier: Typing :: Typed
22
22
  Requires-Python: >=3.12
23
+ Requires-Dist: contourpy>=1.2
23
24
  Requires-Dist: numpy>=1.24
25
+ Requires-Dist: shapely>=2.0
24
26
  Requires-Dist: svg-py>=1.4
25
27
  Provides-Extra: examples
26
28
  Requires-Dist: cairosvg>=2.7; extra == 'examples'
27
- Provides-Extra: occlusion
28
- Requires-Dist: contourpy>=1.2; extra == 'occlusion'
29
- Requires-Dist: shapely>=2.0; extra == 'occlusion'
30
29
  Description-Content-Type: text/markdown
31
30
 
32
31
  # VecView
@@ -37,15 +36,16 @@ stays editable afterwards: elements keep the ids you give them, the same scene
37
36
  renders to byte-identical SVG, and the output opens in Inkscape.
38
37
 
39
38
  <p align="center">
40
- <img src="https://raw.githubusercontent.com/maiani/vecview/v0.2.0/docs/images/readme.svg" alt="A gate-defined quantum dot on a layered slab, with leads, gates, spin densities and a bias circuit" width="640">
39
+ <img src="https://raw.githubusercontent.com/maiani/vecview/v0.3.0/docs/images/readme.svg" alt="A gate-defined quantum dot on a layered slab, with leads, gates, spin densities and a bias circuit" width="640">
41
40
  </p>
42
41
 
43
- <p align="center"><sub>A device sketch: layered solids, Gaussian densities, solid arrows and a circuit, from <code>examples/altermagnetic_dot.py</code>. More in the <a href="https://github.com/maiani/vecview/blob/v0.2.0/docs/gallery.md">gallery</a>.</sub></p>
42
+ <p align="center"><sub>A device sketch: layered solids, Gaussian densities, camera-facing arrows and a circuit, from <code>examples/altermagnetic_dot.py</code>. More in the <a href="https://github.com/maiani/vecview/blob/v0.3.0/docs/gallery.md">gallery</a>.</sub></p>
44
43
 
45
44
  VecView is a small projection layer on top of
46
45
  [`svg.py`](https://pypi.org/project/svg.py/). `svg.py` builds the elements;
47
46
  VecView supplies what it has no notion of: a camera, world-space glyph geometry,
48
- and an explicit layer stack. Runtime dependencies are `numpy` and `svg.py`.
47
+ and an explicit layer stack. Runtime dependencies are `numpy` and `svg.py`, plus
48
+ `shapely` and `contourpy` for polygon clipping and exact visibility.
49
49
 
50
50
  VecView is alpha: the API may change before 1.0.
51
51
 
@@ -55,7 +55,6 @@ Install VecView with pip (Python 3.12 or newer; tested on 3.12–3.14):
55
55
 
56
56
  ```bash
57
57
  python -m pip install vecview
58
- python -m pip install "vecview[occlusion]" # exact visibility
59
58
  ```
60
59
 
61
60
  ## Quick start
@@ -126,12 +125,10 @@ Deciding occlusion by hand is worth more than getting it automatically and almos
126
125
  right.
127
126
 
128
127
  A lattice of hundreds of atoms is the opposite case. `scene.sort_by_depth(layer)`
129
- opts one layer in to the painter's algorithm: its elements are drawn back to
130
- front, ties keep insertion order, and every other layer is untouched.
131
- `sort_by_depth(layer, exact=True)` goes further and decides visibility point by
132
- point: each element keeps its native shape, clipped to what shows of it, so
133
- planes can cross and a bond can run into an atom, and lines are dashed exactly
134
- where they pass behind something.
128
+ has one layer decide visibility by depth, point by point: each element keeps its
129
+ native shape, clipped to what shows of it, so planes can cross, a coil can wrap
130
+ its core, and a bond can run into an atom, and lines are dropped or dashed
131
+ exactly where they pass behind something. Every other layer is untouched.
135
132
  `Camera.visible()` and `faces(..., cull=True)` cover the one unambiguous case,
136
133
  the back faces of a convex solid.
137
134
 
@@ -168,7 +165,13 @@ Labels can be `svg.TSpan` runs, for subscripts.
168
165
 
169
166
  Screen-space `rect2d` and `text2d`, `add_def` for `<defs>`, and `add` for raw
170
167
  `svg.py` elements complete the set. Style keywords pass straight to `svg.py`
171
- (`stroke_width` becomes `stroke-width`).
168
+ (`stroke_width` becomes `stroke-width`), and `class_="gate"` tags every element
169
+ an object is drawn with, so all the gates can be selected or restyled together.
170
+
171
+ A `Part` records the same world-space calls in its own coordinates, and
172
+ `scene.place(layer, part, at=..., rotate=(axis, deg), mirror=..., scale=..., id=...)`
173
+ draws a moved copy: one unit cell tiled into a lattice, one gate turned into four
174
+ quadrants. Ids are prefixed per placement, and parts nest.
172
175
 
173
176
  Geometry functions return plain world-space arrays and know nothing about
174
177
  cameras, styles, or SVG, which keeps them testable as numbers:
@@ -176,7 +179,9 @@ cameras, styles, or SVG, which keeps them testable as numbers:
176
179
  | Function | Returns |
177
180
  | --- | --- |
178
181
  | `box_faces(center, size)` | an axis-aligned box as six named, correctly wound `Face`s |
179
- | `prism_faces(footprint, z0, z1)` | a convex footprint extruded along `z`, culling like a box |
182
+ | `prism_faces(footprint, z0, z1)` | any simple footprint, convex or not, extruded along `z`, culling like a box |
183
+ | `extrude(section, along)` | a planar section swept along any vector: a nanowire along `x`, a fin |
184
+ | `annulus_sector(center, r_in, r_out, theta0_deg, theta1_deg)` | an arc-shaped footprint, such as a gate |
180
185
  | `rect_shape`, `circle_shape`, `ellipse_shape` | flat outlines in any plane |
181
186
  | `arrow_shape`, `double_arrow_shape` | flat arrows with a shaft and head |
182
187
  | `sine_ribbon` | a transverse wave along an axis, for `polyline`; the amplitude may be an envelope |
@@ -184,8 +189,14 @@ cameras, styles, or SVG, which keeps them testable as numbers:
184
189
  | `surface_faces(x, y, z)` | the quads of a sampled surface, such as a band structure |
185
190
  | `convex_polyhedron(vertices)` | a Brillouin zone or coordination polyhedron from its corners |
186
191
  | `trim_corners(faces, r)` | faces cut back from atoms sitting on their corners |
192
+ | `cut(faces, origin, normal)` | a solid cut open by a plane, the cut capped: a cutaway |
187
193
  | `in_plane_dir(angle_deg, u, v)` | a unit direction at an angle within a plane |
188
194
 
195
+ Cross-sections and footprints are built in 2D by `vecview.outlines`: `regular`
196
+ and `rect` to start, `offset` and `film` to grow them — a film is a deposited
197
+ layer on chosen facets — and `union`, `difference`, and `intersection` to
198
+ combine them; `to_plane` lifts the result into 3D for `extrude`.
199
+
189
200
  At an azimuth of 35°, neither `+x` nor `+y` moves a point horizontally across
190
201
  the picture. `screen_basis()` returns the two in-plane world directions that do:
191
202
 
@@ -196,9 +207,9 @@ spots = [-3.0 * horizontal + 1.7 * down, +3.0 * horizontal + 1.7 * down]
196
207
 
197
208
  ## Reserving room for other content
198
209
 
199
- Two calls reserve an empty group for content VecView does not draw itself, such
200
- as a plot or a TeX label. VecView never parses foreign SVG; a consumer fills the
201
- group by id.
210
+ Two calls reserve a group for content VecView does not draw itself, such as a
211
+ plot or a TeX label. VecView never parses foreign SVG: a consumer fills the
212
+ group by id, or a slot holds an svg.py element it is given.
202
213
 
203
214
  `Scene.plane` reserves a rectangle of a world plane, so flat content lies *in*
204
215
  the scene, foreshortened and sheared with the geometry:
@@ -219,33 +230,75 @@ scene.slot(45, (5.5, 4.5, 0), 20, 10, id="label-x", align="west", dx=1.6)
219
230
  ```
220
231
 
221
232
  The group records `align` as `data-align`, the `w` by `h` box grows the fitted
222
- viewBox, and each camera projects the anchor afresh.
233
+ viewBox, and each camera projects the anchor afresh. Give it `content` and it
234
+ holds that element, aligned the same way — a label typeset by
235
+ [VecTeX](https://github.com/maiani/vectex), say:
236
+
237
+ ```python
238
+ label = vectex.render("$k_x$", size_pt=15, color="#4b5563")
239
+ scene.slot(
240
+ 45,
241
+ (5.5, 4.5, 0),
242
+ label.width_px,
243
+ label.height_px,
244
+ id="label-kx",
245
+ align="west",
246
+ dx=1.6,
247
+ content=label.to_svg_py(),
248
+ )
249
+ ```
223
250
 
224
251
  ## Output
225
252
 
226
253
  `Scene.save(path)` writes the document; `Scene.to_svg_document()` returns it as
227
- a string. In Jupyter a scene displays itself inline. That method is the whole embedding contract: any tool that accepts an
228
- object exposing it can place a scene, without VecView knowing about the tool.
229
- The fitted viewBox usually does *not* start at `0, 0`, so a consumer must honour
230
- its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.2.0/docs/embedding.md).
254
+ a string, rendered by the active camera. That method is the whole embedding
255
+ contract: any tool that accepts an object exposing it can place a scene, without
256
+ VecView knowing about the tool. The fitted viewBox usually does *not* start at
257
+ `0, 0`, so a consumer must honour its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.3.0/docs/embedding.md).
258
+
259
+ In Jupyter a scene displays itself inline. Rasterizing and PDF export are out of
260
+ scope; they belong to whatever assembles the final page.
261
+
262
+ ## Animation
231
263
 
232
- Rasterizing and PDF export are out of scope; they belong to whatever assembles
233
- the final page.
264
+ An `Animation` is a scene that moves: draw it once, and give what moves a
265
+ track — a function of time — wherever a still takes a value. VecView renders a
266
+ sample per frame and writes one SVG that plays itself with native SVG timing —
267
+ every frame still vector, no script — and writes once what does not change:
268
+
269
+ ```python
270
+ orbit = Track(lambda t: (2 * cos(t), 2 * sin(t), 0))
271
+ scene = vecview.Scene(camera)
272
+ scene.sphere(1, orbit, 0.25, id="planet", fill="#3b6fb6")
273
+
274
+ vecview.Animation(scene, duration=6.283, view_box=(-150, -110, 300, 220)).save("orbit.svg")
275
+ ```
276
+
277
+ `Track` with keyframes and easing, turning parts about a pivot, and frame
278
+ callbacks for anything else are in `vecview.animation`; see the [animation
279
+ guide](https://github.com/maiani/vecview/blob/v0.3.0/docs/animation.md).
234
280
 
235
281
  ## Examples
236
282
 
237
- The [gallery](https://github.com/maiani/vecview/blob/v0.2.0/docs/gallery.md) has the figures everyone draws — a perovskite
283
+ The [gallery](https://github.com/maiani/vecview/blob/v0.3.0/docs/gallery.md) has the static figures everyone draws — a perovskite
238
284
  cell, the fcc Brillouin zone, C60, the Bloch sphere, a Dirac cone, a skyrmion, a
239
- solenoid, crossing mirror planes — each from one script:
285
+ solenoid, crossing mirror planes, and two device sketches — and two
286
+ animations, a pendulum and a rotating dipole radiating. Each is one
287
+ self-contained script:
240
288
 
241
289
  ```bash
242
- uv run python examples/gallery # all of them
290
+ uv run python examples # all of them
291
+ uv run python examples/perovskite.py # one of them
243
292
 
244
293
  uv run python examples/slab_polarizer.py # one projection
245
294
  uv run python examples/slab_polarizer.py --projection all # all five
246
295
  uv run python examples/altermagnetic_dot.py --projection all # a device sketch, under four cameras
247
296
  ```
248
297
 
298
+ See [examples/README.md](https://github.com/maiani/vecview/blob/v0.3.0/examples/README.md) for the full list and what each
299
+ needs; several typeset their labels with
300
+ [VecTeX](https://github.com/maiani/vectex), which needs TeX.
301
+
249
302
  `slab_polarizer` is a picture of a polarizing slab, rebuilt per
250
303
  projection because it mixes in screen-space glows. `altermagnetic_dot` is a
251
304
  quantum-dot device sketch with arc-shaped gates, Gaussian densities, and a bias
@@ -262,7 +315,8 @@ uv run ty check
262
315
  uv run pytest
263
316
  ```
264
317
 
265
- Run both examples with `--projection all` after touching geometry or projection: mirrored content, or a beam that misses the slab, is the
318
+ Run both device examples with `--projection all`, and the gallery, after touching
319
+ geometry or projection: mirrored content, or a beam that misses the slab, is the
266
320
  usual sign of a projection bug.
267
321
 
268
322
  ## Related projects
@@ -277,13 +331,15 @@ VecView depends on none of them and contains no code specific to any of them.
277
331
 
278
332
  ## Documentation
279
333
 
280
- - [Overview](https://github.com/maiani/vecview/blob/v0.2.0/docs/index.md)
281
- - [Cameras](https://github.com/maiani/vecview/blob/v0.2.0/docs/cameras.md)
282
- - [Scenes and layers](https://github.com/maiani/vecview/blob/v0.2.0/docs/scenes.md)
283
- - [Shapes](https://github.com/maiani/vecview/blob/v0.2.0/docs/shapes.md)
284
- - [Gallery](https://github.com/maiani/vecview/blob/v0.2.0/docs/gallery.md)
285
- - [Embedding a scene](https://github.com/maiani/vecview/blob/v0.2.0/docs/embedding.md)
286
- - [Development](https://github.com/maiani/vecview/blob/v0.2.0/docs/development.md)
334
+ - [Overview](https://github.com/maiani/vecview/blob/v0.3.0/docs/index.md)
335
+ - [Cameras](https://github.com/maiani/vecview/blob/v0.3.0/docs/cameras.md)
336
+ - [Scenes and layers](https://github.com/maiani/vecview/blob/v0.3.0/docs/scenes.md)
337
+ - [Shapes](https://github.com/maiani/vecview/blob/v0.3.0/docs/shapes.md)
338
+ - [Outlines](https://github.com/maiani/vecview/blob/v0.3.0/docs/outlines.md)
339
+ - [Animation](https://github.com/maiani/vecview/blob/v0.3.0/docs/animation.md)
340
+ - [Gallery](https://github.com/maiani/vecview/blob/v0.3.0/docs/gallery.md)
341
+ - [Embedding a scene](https://github.com/maiani/vecview/blob/v0.3.0/docs/embedding.md)
342
+ - [Development](https://github.com/maiani/vecview/blob/v0.3.0/docs/development.md)
287
343
 
288
344
  ## License
289
345