vecview 0.2.0__py3-none-any.whl
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.
- vecview/__init__.py +85 -0
- vecview/_occlusion.py +532 -0
- vecview/_types.py +31 -0
- vecview/_vec.py +69 -0
- vecview/camera.py +299 -0
- vecview/projections.py +232 -0
- vecview/py.typed +0 -0
- vecview/scene.py +2427 -0
- vecview/shapes.py +571 -0
- vecview-0.2.0.dist-info/METADATA +290 -0
- vecview-0.2.0.dist-info/RECORD +13 -0
- vecview-0.2.0.dist-info/WHEEL +4 -0
- vecview-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vecview
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Layered 3D scenes that render to SVG, for scientific schematics
|
|
5
|
+
Project-URL: Source, https://github.com/maiani/vecview
|
|
6
|
+
Project-URL: Issues, https://github.com/maiani/vecview/issues
|
|
7
|
+
Author-email: Andrea Maiani <dev@andreamaiani.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: 3d,axonometric,figures,svg,vector-graphics
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Requires-Dist: numpy>=1.24
|
|
24
|
+
Requires-Dist: svg-py>=1.4
|
|
25
|
+
Provides-Extra: examples
|
|
26
|
+
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
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# VecView
|
|
33
|
+
|
|
34
|
+
Layered 3D scenes that render to SVG, for scientific schematics: a slab and a
|
|
35
|
+
beam, a lattice, an optical bench. The schematic is generated from code and
|
|
36
|
+
stays editable afterwards: elements keep the ids you give them, the same scene
|
|
37
|
+
renders to byte-identical SVG, and the output opens in Inkscape.
|
|
38
|
+
|
|
39
|
+
<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">
|
|
41
|
+
</p>
|
|
42
|
+
|
|
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>
|
|
44
|
+
|
|
45
|
+
VecView is a small projection layer on top of
|
|
46
|
+
[`svg.py`](https://pypi.org/project/svg.py/). `svg.py` builds the elements;
|
|
47
|
+
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`.
|
|
49
|
+
|
|
50
|
+
VecView is alpha: the API may change before 1.0.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
Install VecView with pip (Python 3.12 or newer; tested on 3.12–3.14):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
python -m pip install vecview
|
|
58
|
+
python -m pip install "vecview[occlusion]" # exact visibility
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick start
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import vecview
|
|
65
|
+
|
|
66
|
+
cam = vecview.OrthographicCamera(azim_deg=35, elev_deg=24, scale=62)
|
|
67
|
+
scene = vecview.Scene(cam, pad=28, background="#ffffff")
|
|
68
|
+
|
|
69
|
+
slab = vecview.box_faces(center=(0, 0, -0.45), size=(11, 9, 0.9))
|
|
70
|
+
scene.faces(10, slab, cull=True, fill="#cfd6e0", stroke="#8b96a6", stroke_width=1.6)
|
|
71
|
+
|
|
72
|
+
for angle in (0.0, 67.5):
|
|
73
|
+
axis = vecview.in_plane_dir(angle)
|
|
74
|
+
scene.polygon(
|
|
75
|
+
20,
|
|
76
|
+
vecview.double_arrow_shape(
|
|
77
|
+
(0, 0, 0.02), axis, 4.0, (0, 0, 1), shaft_w=0.1, head_w=0.36, head_len=0.34
|
|
78
|
+
),
|
|
79
|
+
fill="#d62828",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
scene.save("slab.svg")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
World coordinates are right-handed `(x, y, z)` with `z` up, and angles are in
|
|
86
|
+
degrees. The first argument of every drawing call is its layer. `cull=True`
|
|
87
|
+
keeps only the walls this camera can see, and the viewBox is fitted to the
|
|
88
|
+
content.
|
|
89
|
+
|
|
90
|
+
## Projections
|
|
91
|
+
|
|
92
|
+
Five, all parallel, so parallel edges stay parallel:
|
|
93
|
+
|
|
94
|
+
| Camera | Foreshortening |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| `OrthographicCamera.isometric(scale)` | all three axes equal, `0.8165` |
|
|
97
|
+
| `OrthographicCamera.dimetric(scale, ratio=0.5)` | two equal, third by `ratio` |
|
|
98
|
+
| `OrthographicCamera(azim_deg, elev_deg, scale)` | trimetric, the general case |
|
|
99
|
+
| `ObliqueCamera.cavalier(scale)` | front face true, depth `1.0` |
|
|
100
|
+
| `ObliqueCamera.cabinet(scale)` | front face true, depth `0.5` |
|
|
101
|
+
|
|
102
|
+
`foreshortening()` reports the ratios for any camera, and `axonometry()` names
|
|
103
|
+
the class an orthographic one falls into; both read the projection rather than
|
|
104
|
+
how it was built. A scene records objects and holds named cameras, one active,
|
|
105
|
+
as a 3D application does. It renders under any camera, byte-identical to building
|
|
106
|
+
it from scratch with that camera, and needs none until then:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
scene.cameras["cabinet"] = vecview.ObliqueCamera.cabinet(62)
|
|
110
|
+
scene.save("cabinet.svg", "cabinet")
|
|
111
|
+
scene.camera = "cabinet" # the active camera, which to_svg_document uses
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`Camera` promises only `project`, `at`, `depth`, and `visible`. `direction`,
|
|
115
|
+
`screen_basis`, `foreshortening`, and `plane_matrix` live on `ParallelCamera`,
|
|
116
|
+
because each assumes a screen offset independent of position. A future
|
|
117
|
+
perspective camera would subclass `Camera` directly and inherit none of them.
|
|
118
|
+
|
|
119
|
+
## Layers first, depth sorting by request
|
|
120
|
+
|
|
121
|
+
There is no z-buffer. Draw order is an explicit layer stack: for a beam passing
|
|
122
|
+
through a translucent slab, the beam above the slab, the attenuated segment
|
|
123
|
+
inside it, and the emerging beam below are three draw calls at three layers, and
|
|
124
|
+
no automatic rule orders them correctly against a partially transparent face.
|
|
125
|
+
Deciding occlusion by hand is worth more than getting it automatically and almost
|
|
126
|
+
right.
|
|
127
|
+
|
|
128
|
+
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.
|
|
135
|
+
`Camera.visible()` and `faces(..., cull=True)` cover the one unambiguous case,
|
|
136
|
+
the back faces of a convex solid.
|
|
137
|
+
|
|
138
|
+
## Drawing
|
|
139
|
+
|
|
140
|
+
World-space calls on `Scene`:
|
|
141
|
+
|
|
142
|
+
- `polygon`, `polyline`, `text`, and `faces` draw projected geometry;
|
|
143
|
+
`faces(..., id="slab")` suffixes the id per face (`slab-pz`, `slab-px`, …).
|
|
144
|
+
- `arrow(..., normal="camera")` turns an arrow about its own axis to show its
|
|
145
|
+
widest face, resolved by the camera that renders, so every camera sees it. An explicit
|
|
146
|
+
normal also works.
|
|
147
|
+
- `silhouette(layer, solid)` fills the projected convex hull of a solid as one
|
|
148
|
+
polygon. Drawn in the wall colour under the cap, it removes the hairline seams
|
|
149
|
+
between per-wall polygons.
|
|
150
|
+
- `gaussian(layer, center, u, v, a, b, id=..., color=...)` draws a soft spot
|
|
151
|
+
lying in a world plane: one polygon filled by a radial gradient mapped
|
|
152
|
+
through the plane's affine transform.
|
|
153
|
+
|
|
154
|
+
Curved solids have exact outlines under any parallel projection, and each is one
|
|
155
|
+
native element or group:
|
|
156
|
+
|
|
157
|
+
- `sphere` is a single `<circle>` (an `<ellipse>` under an oblique camera).
|
|
158
|
+
- `cylinder` and `cone` are two straight sides and two elliptical arcs, plus the
|
|
159
|
+
end disk that faces the camera; `slices=n` cuts a long one into separately
|
|
160
|
+
sorted lengths.
|
|
161
|
+
- `arrow3d` is a solid shaft and head; `tube` follows any curve, such as a `helix`.
|
|
162
|
+
- `highlight="#fff"` shades any of them with a gradient: a fill style, fixed on
|
|
163
|
+
screen, not a lighting model.
|
|
164
|
+
|
|
165
|
+
`edges(layer, faces, back={...})` draws a convex solid's edges and dashes the
|
|
166
|
+
hidden ones, and `sphere_curve` splits a curve on a sphere where it passes behind.
|
|
167
|
+
Labels can be `svg.TSpan` runs, for subscripts.
|
|
168
|
+
|
|
169
|
+
Screen-space `rect2d` and `text2d`, `add_def` for `<defs>`, and `add` for raw
|
|
170
|
+
`svg.py` elements complete the set. Style keywords pass straight to `svg.py`
|
|
171
|
+
(`stroke_width` becomes `stroke-width`).
|
|
172
|
+
|
|
173
|
+
Geometry functions return plain world-space arrays and know nothing about
|
|
174
|
+
cameras, styles, or SVG, which keeps them testable as numbers:
|
|
175
|
+
|
|
176
|
+
| Function | Returns |
|
|
177
|
+
| --- | --- |
|
|
178
|
+
| `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 |
|
|
180
|
+
| `rect_shape`, `circle_shape`, `ellipse_shape` | flat outlines in any plane |
|
|
181
|
+
| `arrow_shape`, `double_arrow_shape` | flat arrows with a shaft and head |
|
|
182
|
+
| `sine_ribbon` | a transverse wave along an axis, for `polyline`; the amplitude may be an envelope |
|
|
183
|
+
| `arc_shape`, `helix` | an arc between two directions; a coil or spin spiral |
|
|
184
|
+
| `surface_faces(x, y, z)` | the quads of a sampled surface, such as a band structure |
|
|
185
|
+
| `convex_polyhedron(vertices)` | a Brillouin zone or coordination polyhedron from its corners |
|
|
186
|
+
| `trim_corners(faces, r)` | faces cut back from atoms sitting on their corners |
|
|
187
|
+
| `in_plane_dir(angle_deg, u, v)` | a unit direction at an angle within a plane |
|
|
188
|
+
|
|
189
|
+
At an azimuth of 35°, neither `+x` nor `+y` moves a point horizontally across
|
|
190
|
+
the picture. `screen_basis()` returns the two in-plane world directions that do:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
horizontal, down = cam.screen_basis() # in the z = 0 plane
|
|
194
|
+
spots = [-3.0 * horizontal + 1.7 * down, +3.0 * horizontal + 1.7 * down]
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Reserving room for other content
|
|
198
|
+
|
|
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.
|
|
202
|
+
|
|
203
|
+
`Scene.plane` reserves a rectangle of a world plane, so flat content lies *in*
|
|
204
|
+
the scene, foreshortened and sheared with the geometry:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
scene.plane(15, origin=(-4.2, -2.9, 0.01), u_edge=(0, 8.4, 0), v_edge=(5.8, 0, 0), id="plot-plane")
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The embedding is exact: a parallel projection restricted to a plane is affine,
|
|
211
|
+
which is what an SVG `matrix` expresses. (A perspective camera would give a
|
|
212
|
+
homography, which `matrix` cannot represent.)
|
|
213
|
+
|
|
214
|
+
`Scene.slot` pins an upright, unforeshortened group to a projected world point,
|
|
215
|
+
for content such as a TeX label that should read at the document's font size:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
scene.slot(45, (5.5, 4.5, 0), 20, 10, id="label-x", align="west", dx=1.6)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The group records `align` as `data-align`, the `w` by `h` box grows the fitted
|
|
222
|
+
viewBox, and each camera projects the anchor afresh.
|
|
223
|
+
|
|
224
|
+
## Output
|
|
225
|
+
|
|
226
|
+
`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).
|
|
231
|
+
|
|
232
|
+
Rasterizing and PDF export are out of scope; they belong to whatever assembles
|
|
233
|
+
the final page.
|
|
234
|
+
|
|
235
|
+
## Examples
|
|
236
|
+
|
|
237
|
+
The [gallery](https://github.com/maiani/vecview/blob/v0.2.0/docs/gallery.md) has the figures everyone draws — a perovskite
|
|
238
|
+
cell, the fcc Brillouin zone, C60, the Bloch sphere, a Dirac cone, a skyrmion, a
|
|
239
|
+
solenoid, crossing mirror planes — each from one script:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
uv run python examples/gallery # all of them
|
|
243
|
+
|
|
244
|
+
uv run python examples/slab_polarizer.py # one projection
|
|
245
|
+
uv run python examples/slab_polarizer.py --projection all # all five
|
|
246
|
+
uv run python examples/altermagnetic_dot.py --projection all # a device sketch, under four cameras
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`slab_polarizer` is a picture of a polarizing slab, rebuilt per
|
|
250
|
+
projection because it mixes in screen-space glows. `altermagnetic_dot` is a
|
|
251
|
+
quantum-dot device sketch with arc-shaped gates, Gaussian densities, and a bias
|
|
252
|
+
circuit; being world-space throughout, it is built once, holds its projections
|
|
253
|
+
as named cameras, and renders each by name.
|
|
254
|
+
|
|
255
|
+
## Development
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
uv sync --all-extras
|
|
259
|
+
uv run ruff format --check .
|
|
260
|
+
uv run ruff check .
|
|
261
|
+
uv run ty check
|
|
262
|
+
uv run pytest
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Run both examples with `--projection all` after touching geometry or projection: mirrored content, or a beam that misses the slab, is the
|
|
266
|
+
usual sign of a projection bug.
|
|
267
|
+
|
|
268
|
+
## Related projects
|
|
269
|
+
|
|
270
|
+
VecView is developed alongside [FigWorks](https://github.com/maiani/figworks),
|
|
271
|
+
which composes multi-panel figures, and two other producers of editable SVG:
|
|
272
|
+
[VecTeX](https://github.com/maiani/vectex) (TeX equations) and [VecWire](https://github.com/maiani/vecwire) (circuit
|
|
273
|
+
schematics). All four share one premise: figures generated from code, with
|
|
274
|
+
stable ids and byte-identical output, that stay editable in Inkscape.
|
|
275
|
+
|
|
276
|
+
VecView depends on none of them and contains no code specific to any of them.
|
|
277
|
+
|
|
278
|
+
## Documentation
|
|
279
|
+
|
|
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)
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
vecview/__init__.py,sha256=jr8Td_8F2xrXV2Myavrhg0OPDuNWxGad3AL-e1JI_AI,2191
|
|
2
|
+
vecview/_occlusion.py,sha256=LoH8j0KdXNzZiLCpTSA1VuVZqi2utc3Wa4DV08Nt2vk,21151
|
|
3
|
+
vecview/_types.py,sha256=8gGQrb3UlIwlciXP-Z0s7HTdeVMw99XAbvo_WOSmsto,940
|
|
4
|
+
vecview/_vec.py,sha256=ypXqNmeDCzZdDzHXyOVujHPESabT_0ualLydQnh6t08,2416
|
|
5
|
+
vecview/camera.py,sha256=G_TFdhjSFOdTohmmqodvYRa9uikbhGzADRhVF0yz5LE,13690
|
|
6
|
+
vecview/projections.py,sha256=gY4nNTsNExskrzLiNOiH3gBHHyaHEXlaNoJ1moNZkpE,9688
|
|
7
|
+
vecview/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
vecview/scene.py,sha256=B8LY9a8c4_w47uLa_kPMnHiLeiCR8-9ToHgyL6dJmxo,98724
|
|
9
|
+
vecview/shapes.py,sha256=WgGOEQQKcVTdmy2q4JilPrl11ICvAKp1RTLTmMlcioo,22211
|
|
10
|
+
vecview-0.2.0.dist-info/METADATA,sha256=xDbRmcrqNCNJj1w6MtVbJZRoX5QrcHEkiMIwI3qwSHA,12930
|
|
11
|
+
vecview-0.2.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
12
|
+
vecview-0.2.0.dist-info/licenses/LICENSE,sha256=OOjR7-6Sm14E-UnnnW_l_pL_BJTQzyoYOrglXbUHYhE,1070
|
|
13
|
+
vecview-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrea Maiani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|