vecview 0.4.0__tar.gz → 0.5.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.
- {vecview-0.4.0 → vecview-0.5.0}/AGENTS.md +6 -2
- {vecview-0.4.0 → vecview-0.5.0}/CHANGELOG.md +21 -0
- {vecview-0.4.0 → vecview-0.5.0}/PKG-INFO +19 -16
- {vecview-0.4.0 → vecview-0.5.0}/README.md +18 -15
- {vecview-0.4.0 → vecview-0.5.0}/docs/development.md +4 -2
- {vecview-0.4.0 → vecview-0.5.0}/docs/scenes.md +26 -2
- {vecview-0.4.0 → vecview-0.5.0}/docs/shapes.md +37 -1
- {vecview-0.4.0 → vecview-0.5.0}/pyproject.toml +1 -1
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/__init__.py +3 -1
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_canvas.py +30 -0
- vecview-0.5.0/src/vecview/_cut.py +121 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_drawing.py +66 -0
- vecview-0.5.0/src/vecview/_face.py +34 -0
- vecview-0.5.0/src/vecview/_line_art.py +120 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_place.py +1 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/shapes.py +145 -131
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_parts.py +2 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_shapes.py +102 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_solids.py +71 -0
- {vecview-0.4.0 → vecview-0.5.0}/.gitignore +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/LICENSE +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/animation.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/cameras.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/embedding.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/aharonov_bohm_ring.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/altermagnetic_dot.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/bloch_sphere.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/brillouin_zone.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/dirac_cone.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/fullerene.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/kitaev_chain.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/mirror_planes.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/perovskite.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/skyrmion.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/slab_polarizer.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery/solenoid.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/gallery.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/images/readme.svg +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/index.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/outlines.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/docs/readme_figure.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/README.md +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/__main__.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/aharonov_bohm_ring.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/altermagnetic_dot.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/bloch_sphere.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/brillouin_zone.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/dirac_cone.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/fullerene.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/kitaev_chain.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/mirror_planes.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/pendulum.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/perovskite.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/rotating_dipole.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/skyrmion.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/slab_polarizer.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/examples/solenoid.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_animation_refs.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_animation_svg.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_elements.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_numeric.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_occlusion.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_planar.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_solid_drawing.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_solids.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_tracks.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_transforms.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_types.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/_vec.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/animation.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/camera.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/outlines.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/projections.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/py.typed +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/src/vecview/scene.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_animation.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_arrows.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_camera.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_document.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_occlusion.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_outlines.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_package_metadata.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_planes.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_projections.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_regions.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_scene.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/tests/test_tracked_scenes.py +0 -0
- {vecview-0.4.0 → vecview-0.5.0}/zensical.toml +0 -0
|
@@ -38,8 +38,12 @@ on its own side.
|
|
|
38
38
|
`_animation_svg.py` and `_animation_refs.py`. `_drawing.py` imports it only
|
|
39
39
|
to check what `slot` is given, and `_occlusion.py` only for a type.
|
|
40
40
|
`shapes.py`, `camera.py`, `projections.py`, `_place.py`,
|
|
41
|
-
`_solid_drawing.py`, `_planar.py`, `_tracks.py`,
|
|
42
|
-
do.
|
|
41
|
+
`_solid_drawing.py`, `_planar.py`, `_tracks.py`, `_transforms.py`, `_face.py`,
|
|
42
|
+
`_cut.py`, and `_line_art.py` never do.
|
|
43
|
+
- `shapes.py` re-exports `Face` from `_face.py`, which `_cut.py` (cutting a
|
|
44
|
+
solid open) shares, and `cut` from `_cut.py`. `_line_art.py` decides which
|
|
45
|
+
edges of a faceted solid to ink from which faces face the camera, which the
|
|
46
|
+
canvas passes in: numbers only, tested without a camera.
|
|
43
47
|
- `animation.py` samples a pure time-to-scene callback through the static
|
|
44
48
|
renderer and writes once what every frame draws alike. A scene holding tracks
|
|
45
49
|
is that callback underneath: a drawing call given a `Track` anywhere in its
|
|
@@ -5,6 +5,27 @@ All notable changes to this project are documented here, following
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.5.0] - 2026-11-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `revolve(profile, *, sweep_deg=(0, 360), axis=(0, 0, 1), origin=(0, 0, 0), n=96)`:
|
|
13
|
+
an `(r, z)` profile, with holes if it has them, turned about an axis into a
|
|
14
|
+
closed solid of faceted walls. A partial turn is capped by the profile as
|
|
15
|
+
faces `"start"` and `"end"`, the section of a cutaway. Facets are named
|
|
16
|
+
`"side-{i}-{j}"` by profile edge and step; facets beside the axis are
|
|
17
|
+
triangles.
|
|
18
|
+
- `Scene.line_art(layer, faces, *, crease_deg=30.0, back=None, **style)`: a
|
|
19
|
+
solid's silhouette, creases, and open rims as continuous lines, without the
|
|
20
|
+
seams between facets, so a faceted solid reads as curved and any solid can
|
|
21
|
+
be drawn as a technical drawing. On a closed solid the far side takes the
|
|
22
|
+
`back` style; in a sorted layer, anything in front hides lines exactly.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- `vecview.shapes.__all__` lists `extrude`, which `from vecview.shapes import *`
|
|
27
|
+
missed.
|
|
28
|
+
|
|
8
29
|
## [0.4.0] - 2026-10-16
|
|
9
30
|
|
|
10
31
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vecview
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.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
|
|
@@ -36,10 +36,10 @@ stays editable afterwards: elements keep the ids you give them, the same scene
|
|
|
36
36
|
renders to byte-identical SVG, and the output opens in Inkscape.
|
|
37
37
|
|
|
38
38
|
<p align="center">
|
|
39
|
-
<img src="https://raw.githubusercontent.com/maiani/vecview/v0.
|
|
39
|
+
<img src="https://raw.githubusercontent.com/maiani/vecview/v0.5.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">
|
|
40
40
|
</p>
|
|
41
41
|
|
|
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.
|
|
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.5.0/docs/gallery.md">gallery</a>.</sub></p>
|
|
43
43
|
|
|
44
44
|
VecView is a small projection layer on top of
|
|
45
45
|
[`svg.py`](https://pypi.org/project/svg.py/). `svg.py` builds the elements;
|
|
@@ -160,6 +160,8 @@ native element or group:
|
|
|
160
160
|
- `highlight="#fff"` shades any of them with a gradient: a fill style, fixed on
|
|
161
161
|
screen, not a lighting model.
|
|
162
162
|
|
|
163
|
+
`line_art(layer, faces)` inks any faceted solid as a technical drawing --
|
|
164
|
+
silhouette, creases, and rims, without the seams between facets -- and
|
|
163
165
|
`edges(layer, faces, back={...})` draws a convex solid's edges and dashes the
|
|
164
166
|
hidden ones, and `sphere_curve` splits a curve on a sphere where it passes behind.
|
|
165
167
|
Labels can be `svg.TSpan` runs, for subscripts.
|
|
@@ -192,6 +194,7 @@ cameras, styles, or SVG, which keeps them testable as numbers:
|
|
|
192
194
|
| `surface_faces(x, y, z)` | the quads of a sampled surface, such as a band structure |
|
|
193
195
|
| `convex_polyhedron(vertices)` | a Brillouin zone or coordination polyhedron from its corners |
|
|
194
196
|
| `trim_corners(faces, r)` | faces cut back from atoms sitting on their corners |
|
|
197
|
+
| `revolve(profile, sweep_deg=...)` | an `(r, z)` profile turned about an axis, whole or part-way with its section capped: a lathe |
|
|
195
198
|
| `cut(faces, origin, normal)` | a solid cut open by a plane, the cut capped: a cutaway |
|
|
196
199
|
| `in_plane_dir(angle_deg, u, v)` | a unit direction at an angle within a plane |
|
|
197
200
|
|
|
@@ -263,7 +266,7 @@ scene.slot(
|
|
|
263
266
|
a string, rendered by the active camera. That method is the whole embedding
|
|
264
267
|
contract: any tool that accepts an object exposing it can place a scene, without
|
|
265
268
|
VecView knowing about the tool. The fitted viewBox usually does *not* start at
|
|
266
|
-
`0, 0`, so a consumer must honour its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.
|
|
269
|
+
`0, 0`, so a consumer must honour its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.5.0/docs/embedding.md).
|
|
267
270
|
|
|
268
271
|
In Jupyter a scene displays itself inline. Rasterizing and PDF export are out of
|
|
269
272
|
scope; they belong to whatever assembles the final page.
|
|
@@ -285,11 +288,11 @@ vecview.Animation(scene, duration=6.283, view_box=(-150, -110, 300, 220)).save("
|
|
|
285
288
|
|
|
286
289
|
`Track` with keyframes and easing, turning parts about a pivot, and frame
|
|
287
290
|
callbacks for anything else are in `vecview.animation`; see the [animation
|
|
288
|
-
guide](https://github.com/maiani/vecview/blob/v0.
|
|
291
|
+
guide](https://github.com/maiani/vecview/blob/v0.5.0/docs/animation.md).
|
|
289
292
|
|
|
290
293
|
## Examples
|
|
291
294
|
|
|
292
|
-
The [gallery](https://github.com/maiani/vecview/blob/v0.
|
|
295
|
+
The [gallery](https://github.com/maiani/vecview/blob/v0.5.0/docs/gallery.md) has the static figures everyone draws — a perovskite
|
|
293
296
|
cell, the fcc Brillouin zone, C60, the Bloch sphere, a Dirac cone, a skyrmion, a
|
|
294
297
|
solenoid, crossing mirror planes, an Aharonov–Bohm ring, and two device sketches — and two
|
|
295
298
|
animations, a pendulum and a rotating dipole radiating. Each is one
|
|
@@ -304,7 +307,7 @@ uv run python examples/slab_polarizer.py --projection all # all five
|
|
|
304
307
|
uv run python examples/altermagnetic_dot.py --projection all # a device sketch, under four cameras
|
|
305
308
|
```
|
|
306
309
|
|
|
307
|
-
See [examples/README.md](https://github.com/maiani/vecview/blob/v0.
|
|
310
|
+
See [examples/README.md](https://github.com/maiani/vecview/blob/v0.5.0/examples/README.md) for the full list and what each
|
|
308
311
|
needs; several typeset their labels with
|
|
309
312
|
[VecTeX](https://github.com/maiani/vectex), which needs TeX.
|
|
310
313
|
|
|
@@ -340,15 +343,15 @@ VecView depends on none of them and contains no code specific to any of them.
|
|
|
340
343
|
|
|
341
344
|
## Documentation
|
|
342
345
|
|
|
343
|
-
- [Overview](https://github.com/maiani/vecview/blob/v0.
|
|
344
|
-
- [Cameras](https://github.com/maiani/vecview/blob/v0.
|
|
345
|
-
- [Scenes and layers](https://github.com/maiani/vecview/blob/v0.
|
|
346
|
-
- [Shapes](https://github.com/maiani/vecview/blob/v0.
|
|
347
|
-
- [Outlines](https://github.com/maiani/vecview/blob/v0.
|
|
348
|
-
- [Animation](https://github.com/maiani/vecview/blob/v0.
|
|
349
|
-
- [Gallery](https://github.com/maiani/vecview/blob/v0.
|
|
350
|
-
- [Embedding a scene](https://github.com/maiani/vecview/blob/v0.
|
|
351
|
-
- [Development](https://github.com/maiani/vecview/blob/v0.
|
|
346
|
+
- [Overview](https://github.com/maiani/vecview/blob/v0.5.0/docs/index.md)
|
|
347
|
+
- [Cameras](https://github.com/maiani/vecview/blob/v0.5.0/docs/cameras.md)
|
|
348
|
+
- [Scenes and layers](https://github.com/maiani/vecview/blob/v0.5.0/docs/scenes.md)
|
|
349
|
+
- [Shapes](https://github.com/maiani/vecview/blob/v0.5.0/docs/shapes.md)
|
|
350
|
+
- [Outlines](https://github.com/maiani/vecview/blob/v0.5.0/docs/outlines.md)
|
|
351
|
+
- [Animation](https://github.com/maiani/vecview/blob/v0.5.0/docs/animation.md)
|
|
352
|
+
- [Gallery](https://github.com/maiani/vecview/blob/v0.5.0/docs/gallery.md)
|
|
353
|
+
- [Embedding a scene](https://github.com/maiani/vecview/blob/v0.5.0/docs/embedding.md)
|
|
354
|
+
- [Development](https://github.com/maiani/vecview/blob/v0.5.0/docs/development.md)
|
|
352
355
|
|
|
353
356
|
## License
|
|
354
357
|
|
|
@@ -6,10 +6,10 @@ stays editable afterwards: elements keep the ids you give them, the same scene
|
|
|
6
6
|
renders to byte-identical SVG, and the output opens in Inkscape.
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<img src="https://raw.githubusercontent.com/maiani/vecview/v0.
|
|
9
|
+
<img src="https://raw.githubusercontent.com/maiani/vecview/v0.5.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">
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
|
-
<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.
|
|
12
|
+
<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.5.0/docs/gallery.md">gallery</a>.</sub></p>
|
|
13
13
|
|
|
14
14
|
VecView is a small projection layer on top of
|
|
15
15
|
[`svg.py`](https://pypi.org/project/svg.py/). `svg.py` builds the elements;
|
|
@@ -130,6 +130,8 @@ native element or group:
|
|
|
130
130
|
- `highlight="#fff"` shades any of them with a gradient: a fill style, fixed on
|
|
131
131
|
screen, not a lighting model.
|
|
132
132
|
|
|
133
|
+
`line_art(layer, faces)` inks any faceted solid as a technical drawing --
|
|
134
|
+
silhouette, creases, and rims, without the seams between facets -- and
|
|
133
135
|
`edges(layer, faces, back={...})` draws a convex solid's edges and dashes the
|
|
134
136
|
hidden ones, and `sphere_curve` splits a curve on a sphere where it passes behind.
|
|
135
137
|
Labels can be `svg.TSpan` runs, for subscripts.
|
|
@@ -162,6 +164,7 @@ cameras, styles, or SVG, which keeps them testable as numbers:
|
|
|
162
164
|
| `surface_faces(x, y, z)` | the quads of a sampled surface, such as a band structure |
|
|
163
165
|
| `convex_polyhedron(vertices)` | a Brillouin zone or coordination polyhedron from its corners |
|
|
164
166
|
| `trim_corners(faces, r)` | faces cut back from atoms sitting on their corners |
|
|
167
|
+
| `revolve(profile, sweep_deg=...)` | an `(r, z)` profile turned about an axis, whole or part-way with its section capped: a lathe |
|
|
165
168
|
| `cut(faces, origin, normal)` | a solid cut open by a plane, the cut capped: a cutaway |
|
|
166
169
|
| `in_plane_dir(angle_deg, u, v)` | a unit direction at an angle within a plane |
|
|
167
170
|
|
|
@@ -233,7 +236,7 @@ scene.slot(
|
|
|
233
236
|
a string, rendered by the active camera. That method is the whole embedding
|
|
234
237
|
contract: any tool that accepts an object exposing it can place a scene, without
|
|
235
238
|
VecView knowing about the tool. The fitted viewBox usually does *not* start at
|
|
236
|
-
`0, 0`, so a consumer must honour its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.
|
|
239
|
+
`0, 0`, so a consumer must honour its origin. See [Embedding a scene](https://github.com/maiani/vecview/blob/v0.5.0/docs/embedding.md).
|
|
237
240
|
|
|
238
241
|
In Jupyter a scene displays itself inline. Rasterizing and PDF export are out of
|
|
239
242
|
scope; they belong to whatever assembles the final page.
|
|
@@ -255,11 +258,11 @@ vecview.Animation(scene, duration=6.283, view_box=(-150, -110, 300, 220)).save("
|
|
|
255
258
|
|
|
256
259
|
`Track` with keyframes and easing, turning parts about a pivot, and frame
|
|
257
260
|
callbacks for anything else are in `vecview.animation`; see the [animation
|
|
258
|
-
guide](https://github.com/maiani/vecview/blob/v0.
|
|
261
|
+
guide](https://github.com/maiani/vecview/blob/v0.5.0/docs/animation.md).
|
|
259
262
|
|
|
260
263
|
## Examples
|
|
261
264
|
|
|
262
|
-
The [gallery](https://github.com/maiani/vecview/blob/v0.
|
|
265
|
+
The [gallery](https://github.com/maiani/vecview/blob/v0.5.0/docs/gallery.md) has the static figures everyone draws — a perovskite
|
|
263
266
|
cell, the fcc Brillouin zone, C60, the Bloch sphere, a Dirac cone, a skyrmion, a
|
|
264
267
|
solenoid, crossing mirror planes, an Aharonov–Bohm ring, and two device sketches — and two
|
|
265
268
|
animations, a pendulum and a rotating dipole radiating. Each is one
|
|
@@ -274,7 +277,7 @@ uv run python examples/slab_polarizer.py --projection all # all five
|
|
|
274
277
|
uv run python examples/altermagnetic_dot.py --projection all # a device sketch, under four cameras
|
|
275
278
|
```
|
|
276
279
|
|
|
277
|
-
See [examples/README.md](https://github.com/maiani/vecview/blob/v0.
|
|
280
|
+
See [examples/README.md](https://github.com/maiani/vecview/blob/v0.5.0/examples/README.md) for the full list and what each
|
|
278
281
|
needs; several typeset their labels with
|
|
279
282
|
[VecTeX](https://github.com/maiani/vectex), which needs TeX.
|
|
280
283
|
|
|
@@ -310,15 +313,15 @@ VecView depends on none of them and contains no code specific to any of them.
|
|
|
310
313
|
|
|
311
314
|
## Documentation
|
|
312
315
|
|
|
313
|
-
- [Overview](https://github.com/maiani/vecview/blob/v0.
|
|
314
|
-
- [Cameras](https://github.com/maiani/vecview/blob/v0.
|
|
315
|
-
- [Scenes and layers](https://github.com/maiani/vecview/blob/v0.
|
|
316
|
-
- [Shapes](https://github.com/maiani/vecview/blob/v0.
|
|
317
|
-
- [Outlines](https://github.com/maiani/vecview/blob/v0.
|
|
318
|
-
- [Animation](https://github.com/maiani/vecview/blob/v0.
|
|
319
|
-
- [Gallery](https://github.com/maiani/vecview/blob/v0.
|
|
320
|
-
- [Embedding a scene](https://github.com/maiani/vecview/blob/v0.
|
|
321
|
-
- [Development](https://github.com/maiani/vecview/blob/v0.
|
|
316
|
+
- [Overview](https://github.com/maiani/vecview/blob/v0.5.0/docs/index.md)
|
|
317
|
+
- [Cameras](https://github.com/maiani/vecview/blob/v0.5.0/docs/cameras.md)
|
|
318
|
+
- [Scenes and layers](https://github.com/maiani/vecview/blob/v0.5.0/docs/scenes.md)
|
|
319
|
+
- [Shapes](https://github.com/maiani/vecview/blob/v0.5.0/docs/shapes.md)
|
|
320
|
+
- [Outlines](https://github.com/maiani/vecview/blob/v0.5.0/docs/outlines.md)
|
|
321
|
+
- [Animation](https://github.com/maiani/vecview/blob/v0.5.0/docs/animation.md)
|
|
322
|
+
- [Gallery](https://github.com/maiani/vecview/blob/v0.5.0/docs/gallery.md)
|
|
323
|
+
- [Embedding a scene](https://github.com/maiani/vecview/blob/v0.5.0/docs/embedding.md)
|
|
324
|
+
- [Development](https://github.com/maiani/vecview/blob/v0.5.0/docs/development.md)
|
|
322
325
|
|
|
323
326
|
## License
|
|
324
327
|
|
|
@@ -54,8 +54,10 @@ dimetric, and trimetric cases.
|
|
|
54
54
|
Rasterizing, PDF, and TeX belong to a consumer, not here. A test enforces
|
|
55
55
|
this. `shapely` clips polygons and `contourpy` traces depth contours; both
|
|
56
56
|
load only when they are first needed.
|
|
57
|
-
- **Keep the three-way split**: `shapes` knows only numbers,
|
|
58
|
-
`
|
|
57
|
+
- **Keep the three-way split**: `shapes` knows only numbers, and so do its
|
|
58
|
+
private helpers `_face` (the `Face` record), `_cut`, and `_line_art` (which
|
|
59
|
+
edges of a faceted solid to ink, given which faces face the camera); `camera`
|
|
60
|
+
and `projections` know projection; and `scene` and `animation`, with their
|
|
59
61
|
private rendering modules (`_elements`, `_canvas`, `_solids`,
|
|
60
62
|
`_animation_svg`, `_animation_refs`), are the only code that touches
|
|
61
63
|
`svg.py`. Geometry that needs a camera to be computed does not belong in
|
|
@@ -343,11 +343,35 @@ consumer selects.
|
|
|
343
343
|
## Hidden lines
|
|
344
344
|
|
|
345
345
|
```python
|
|
346
|
+
scene.line_art(layer, faces, *, crease_deg=30.0, back=None, **style)
|
|
346
347
|
scene.edges(layer, faces, back=None, back_layer=None, separate=False, trim=0.0, **style)
|
|
347
348
|
scene.sphere_curve(layer, center, points3, closed=False, back=None, back_layer=None, **style)
|
|
348
349
|
```
|
|
349
350
|
|
|
350
|
-
`
|
|
351
|
+
`line_art` inks any solid given as faces the way a technical drawing would:
|
|
352
|
+
its silhouette, where a face toward the camera meets one away from it; its
|
|
353
|
+
creases, where faces meet at more than `crease_deg`; and the rim of an open
|
|
354
|
+
surface. The seams between facets of one smooth surface are left out, so a
|
|
355
|
+
solid from [`revolve`](shapes.md#turned-solids) or `surface_faces` reads as
|
|
356
|
+
curved, and the drawn edges are joined into continuous lines. On a closed
|
|
357
|
+
solid, lines whose faces all face away are on the far side: dropped, or drawn
|
|
358
|
+
with `{**style, **back}`. What else hides a line — another solid, or a fold of
|
|
359
|
+
this one — is found exactly in a [sorted layer](#sorting-by-depth), where the
|
|
360
|
+
solid's own faces, drawn unstroked in the same layer, hide what is behind them;
|
|
361
|
+
there a near-side line takes the `back` style where a surface hides it:
|
|
362
|
+
|
|
363
|
+
```python
|
|
364
|
+
body = vecview.revolve(profile, sweep_deg=(45, 315))
|
|
365
|
+
scene.faces(20, body, fill="white")
|
|
366
|
+
scene.line_art(20, body, stroke="#222", back={"stroke_dasharray": "3 2"}, id="body")
|
|
367
|
+
scene.sort_by_depth(20)
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
The silhouette changes with the view, so each camera recomputes it. Raise
|
|
371
|
+
`crease_deg` for a coarsely faceted surface whose seams would otherwise count as
|
|
372
|
+
creases.
|
|
373
|
+
|
|
374
|
+
`edges` draws every edge of a convex solid, visible ones with `style`. An edge is
|
|
351
375
|
visible when either face it bounds faces the camera, which is exact for a convex
|
|
352
376
|
solid. Hidden edges are dropped unless `back` is given, in which case they get
|
|
353
377
|
`{**style, **back}` — the crystallographer's dashed back edges — on `back_layer`,
|
|
@@ -380,7 +404,7 @@ dashed = {"stroke_dasharray": "3 3"}
|
|
|
380
404
|
scene.sphere_curve(20, (0, 0, 0), equator, closed=True, back=dashed, back_layer=5, stroke="#333")
|
|
381
405
|
```
|
|
382
406
|
|
|
383
|
-
An `id` becomes `{id}-front` and `{id}-back` for
|
|
407
|
+
An `id` becomes `{id}-front` and `{id}-back` for all three calls, suffixed `-0`, `-1`,
|
|
384
408
|
… per edge when `separate`. Both re-split for
|
|
385
409
|
[each camera](#rendering-one-scene-several-ways).
|
|
386
410
|
|
|
@@ -347,6 +347,42 @@ scene.faces(10, vecview.trim_corners(octahedron, r_o), fill="#6f9fd8", fill_opac
|
|
|
347
347
|
scene.edges(10, octahedron, trim=r_o, stroke="#2d5c94")
|
|
348
348
|
```
|
|
349
349
|
|
|
350
|
+
## Turned solids
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
vecview.revolve(profile, *, sweep_deg=(0, 360), axis=(0, 0, 1), origin=(0, 0, 0), n=96) -> list[Face]
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
The solid a lathe makes: a profile turned about an axis. The profile is drawn
|
|
357
|
+
in a half-plane through the axis as `(r, z)` pairs — `r >= 0` the distance from
|
|
358
|
+
the axis, `z` the height along it from `origin` — so a rectangle away from the
|
|
359
|
+
axis turns into a thick tube, one against it into a cylinder, and a stepped or
|
|
360
|
+
curved outline into a bobbin, a flask, or the electrodes of a vacuum tube. A
|
|
361
|
+
`Region` with holes leaves hollow rings inside.
|
|
362
|
+
|
|
363
|
+
The turn runs over `sweep_deg`, counter-clockwise about `axis` from `+x` (from
|
|
364
|
+
`+y` for an axis along `x`), as `annulus_sector` measures. Anything short of a
|
|
365
|
+
full turn leaves the solid open, capped by the profile itself as faces
|
|
366
|
+
`"start"` and `"end"`: the section of a cutaway, in a style of its own.
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
shell = vecview.revolve(vecview.outlines.rect((2.6, 0), (3.0, 5)), sweep_deg=(30, 300))
|
|
370
|
+
walls = [f for f in shell if f.name not in ("start", "end")]
|
|
371
|
+
section = [f for f in shell if f.name in ("start", "end")]
|
|
372
|
+
scene.faces(20, walls, fill="white", id="shell")
|
|
373
|
+
scene.faces(20, section, fill="url(#hatch)", id="shell-section")
|
|
374
|
+
scene.line_art(20, shell, stroke="#222", id="shell-lines")
|
|
375
|
+
scene.sort_by_depth(20)
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The walls are flat facets, `n` per full turn; facet `j` of the profile edge from
|
|
379
|
+
vertex `i` to `i + 1`, as given, is `"side-{i}-{j}"`, and of hole `k`,
|
|
380
|
+
`"hole{k}_side-{i}-{j}"`. Facets beside the axis are triangles, and an edge
|
|
381
|
+
along it has none. Drawn with `faces`, the facets fill the solid without
|
|
382
|
+
seams in one colour; [`line_art`](scenes.md#hidden-lines) draws its outline
|
|
383
|
+
— silhouette, rims, and cut — and leaves the seams out, so the solid reads as
|
|
384
|
+
curved. The faces close a solid, so `cut` opens it further.
|
|
385
|
+
|
|
350
386
|
## Cutaways
|
|
351
387
|
|
|
352
388
|
```python
|
|
@@ -373,7 +409,7 @@ scene.faces(10, section, cull=True, fill="#cfe6d5", id="wire-section")
|
|
|
373
409
|
The faces must close a solid, each wound counter-clockwise about its outward
|
|
374
410
|
normal — as `box_faces`, `prism_faces`, `extrude`, and `convex_polyhedron` return
|
|
375
411
|
them — and the solid may be non-convex. Curved solids drawn by the scene (spheres,
|
|
376
|
-
cylinders) are not faces and cannot be cut. A plane across a hollow solid — a
|
|
412
|
+
cylinders) are not faces and cannot be cut; a turned one from `revolve` is. A plane across a hollow solid — a
|
|
377
413
|
tube cut square — leaves a cap with a hole in it. Every face is clipped as a planar region, including concave faces without holes; where the plane runs through a hole,
|
|
378
414
|
or along one of its sides, the hole opens into a notch in the outline. Should
|
|
379
415
|
clipping split such a face, its pieces are named `"{name}-0"`, `"{name}-1"`, ….
|
|
@@ -57,12 +57,13 @@ from vecview.shapes import (
|
|
|
57
57
|
path_arrow_shape,
|
|
58
58
|
prism_faces,
|
|
59
59
|
rect_shape,
|
|
60
|
+
revolve,
|
|
60
61
|
sine_ribbon,
|
|
61
62
|
surface_faces,
|
|
62
63
|
trim_corners,
|
|
63
64
|
)
|
|
64
65
|
|
|
65
|
-
__version__ = "0.
|
|
66
|
+
__version__ = "0.5.0"
|
|
66
67
|
|
|
67
68
|
__all__ = [
|
|
68
69
|
"ISOMETRIC_ELEV_DEG",
|
|
@@ -94,6 +95,7 @@ __all__ = [
|
|
|
94
95
|
"path_arrow_shape",
|
|
95
96
|
"prism_faces",
|
|
96
97
|
"rect_shape",
|
|
98
|
+
"revolve",
|
|
97
99
|
"sine_ribbon",
|
|
98
100
|
"surface_faces",
|
|
99
101
|
"trim_corners",
|
|
@@ -29,6 +29,7 @@ from vecview._elements import (
|
|
|
29
29
|
_text_content,
|
|
30
30
|
_text_length,
|
|
31
31
|
)
|
|
32
|
+
from vecview._line_art import feature_lines
|
|
32
33
|
from vecview._occlusion import (
|
|
33
34
|
Line,
|
|
34
35
|
Piece,
|
|
@@ -686,6 +687,35 @@ class _Canvas:
|
|
|
686
687
|
hide = back if visible else None
|
|
687
688
|
self._shape(functools.partial(self._line, group, attrs, hide))
|
|
688
689
|
|
|
690
|
+
def line_art(
|
|
691
|
+
self,
|
|
692
|
+
layer: int,
|
|
693
|
+
faces: Iterable[Face],
|
|
694
|
+
*,
|
|
695
|
+
crease_deg: float = 30.0,
|
|
696
|
+
back: Mapping[str, Style] | None = None,
|
|
697
|
+
**style: Style,
|
|
698
|
+
) -> None:
|
|
699
|
+
"""A faceted solid's silhouette, creases, and boundaries, as one path."""
|
|
700
|
+
given = list(faces)
|
|
701
|
+
base = style.pop("id", None)
|
|
702
|
+
style.setdefault("fill", "none")
|
|
703
|
+
facing = {id(face) for face in self.cam.visible(given)}
|
|
704
|
+
near, far = feature_lines(given, [id(face) in facing for face in given], crease_deg)
|
|
705
|
+
for runs, extra, suffix, hide in ((near, {}, "front", back), (far, back, "back", None)):
|
|
706
|
+
if extra is None or not runs:
|
|
707
|
+
continue
|
|
708
|
+
projected = [self.cam.project(run) for run in runs]
|
|
709
|
+
for run in projected:
|
|
710
|
+
self._grow(run)
|
|
711
|
+
attrs: dict[str, Style] = {**style, **extra}
|
|
712
|
+
if base is not None:
|
|
713
|
+
attrs["id"] = f"{base}-{suffix}"
|
|
714
|
+
self._emit(layer, svg.Path(d=_path(projected), **attrs), self._depth(np.vstack(runs)))
|
|
715
|
+
# Behind another surface, a near-side line takes the back style and
|
|
716
|
+
# a far-side one disappears, as for edges.
|
|
717
|
+
self._shape(functools.partial(self._line, runs, attrs, hide))
|
|
718
|
+
|
|
689
719
|
def text(
|
|
690
720
|
self,
|
|
691
721
|
layer: int,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Cutting a closed solid open by a plane, and capping the cut.
|
|
2
|
+
|
|
3
|
+
Numbers only, as :mod:`vecview.shapes`, which re-exports :func:`cut`.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Iterable
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from vecview._face import Face
|
|
13
|
+
from vecview._planar import _clip_region, _regions
|
|
14
|
+
from vecview._types import Array, Point3
|
|
15
|
+
from vecview._vec import unit
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def cut(faces: Iterable[Face], origin: Point3, normal: Point3) -> list[Face]:
|
|
19
|
+
"""A closed solid cut open by a plane: the part behind it, with the cut capped.
|
|
20
|
+
|
|
21
|
+
The plane passes through ``origin``, and everything on the side ``normal``
|
|
22
|
+
points to is cut away -- the cutaway that shows a wire's core inside its
|
|
23
|
+
shell, or a layer stack from within. Every face is clipped to the half
|
|
24
|
+
that stays and keeps its name, so ids stay stable; faces wholly cut away
|
|
25
|
+
are dropped. The cut itself is capped by new faces lying in the plane and
|
|
26
|
+
facing along ``normal``, named ``"cut"`` -- or ``"cut-0"``, ``"cut-1"``, ...
|
|
27
|
+
when the plane meets the solid in several places -- so a cap can be drawn
|
|
28
|
+
in a style of its own. A face lying in the plane is dropped, the cap
|
|
29
|
+
taking its place. A plane across a hollow solid -- a tube cut square --
|
|
30
|
+
leaves a cap with a hole in it. Every face is clipped as a planar
|
|
31
|
+
region; a hole whose side lies along the plane opens into a notch.
|
|
32
|
+
Should clipping split a face, the pieces are
|
|
33
|
+
named ``"{name}-0"``, ``"{name}-1"``, ...
|
|
34
|
+
|
|
35
|
+
The faces must close a solid, each wound counter-clockwise about its
|
|
36
|
+
outward normal, as every function here returns them; non-convex solids
|
|
37
|
+
are fine. A plane that misses the solid returns it unchanged, or nothing.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
ValueError: If the faces do not close up along the cut.
|
|
41
|
+
"""
|
|
42
|
+
given = list(faces)
|
|
43
|
+
n, o = unit(normal), np.asarray(origin, dtype=np.float64)
|
|
44
|
+
if not n.any():
|
|
45
|
+
raise ValueError("a cut needs a non-zero plane normal")
|
|
46
|
+
if not given:
|
|
47
|
+
return []
|
|
48
|
+
everything = np.vstack([face.points for face in given])
|
|
49
|
+
eps = 1e-9 * max(float(np.ptp(everything, axis=0).max()), 1.0)
|
|
50
|
+
kept: list[Face] = []
|
|
51
|
+
rims: list[tuple[Array, Array]] = []
|
|
52
|
+
for face in given:
|
|
53
|
+
pts = np.asarray(face.points, dtype=np.float64)
|
|
54
|
+
d = (pts - o) @ n
|
|
55
|
+
d[np.abs(d) <= eps] = 0.0
|
|
56
|
+
if np.all(d > 0):
|
|
57
|
+
continue
|
|
58
|
+
if np.all(d == 0):
|
|
59
|
+
continue # lying in the plane: the cap, built from its neighbours, replaces it
|
|
60
|
+
if np.all(d < 0):
|
|
61
|
+
kept.append(face)
|
|
62
|
+
continue
|
|
63
|
+
pieces, edges = _clip_rings(face, o, n, eps)
|
|
64
|
+
kept += pieces
|
|
65
|
+
rims += edges
|
|
66
|
+
return kept + _caps(rims, n, eps)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _clip_rings(
|
|
70
|
+
face: Face, o: Array, n: Array, eps: float
|
|
71
|
+
) -> tuple[list[Face], list[tuple[Array, Array]]]:
|
|
72
|
+
"""Clip every face through the same planar-region operation, including splits."""
|
|
73
|
+
regions = _clip_region(face.region, np.asarray(face.normal), o, n, eps)
|
|
74
|
+
pieces = [
|
|
75
|
+
Face(
|
|
76
|
+
face.name if len(regions) == 1 else f"{face.name}-{k}",
|
|
77
|
+
region.exterior,
|
|
78
|
+
face.normal,
|
|
79
|
+
region.holes,
|
|
80
|
+
)
|
|
81
|
+
for k, region in enumerate(regions)
|
|
82
|
+
]
|
|
83
|
+
rims: list[tuple[Array, Array]] = []
|
|
84
|
+
for region in regions:
|
|
85
|
+
for loop in region.rings:
|
|
86
|
+
on = np.abs((loop - o) @ n) <= eps
|
|
87
|
+
for i in range(len(loop)):
|
|
88
|
+
j = (i + 1) % len(loop)
|
|
89
|
+
if on[i] and on[j]:
|
|
90
|
+
rims.append((loop[j], loop[i]))
|
|
91
|
+
return pieces, rims
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _caps(rims: list[tuple[Array, Array]], normal: Array, eps: float) -> list[Face]:
|
|
95
|
+
"""Chain the directed edges a cut leaves in its plane into cap faces."""
|
|
96
|
+
|
|
97
|
+
def key(p: Array) -> tuple[float, ...]:
|
|
98
|
+
return tuple(np.round(p / (100 * eps)).astype(int).tolist())
|
|
99
|
+
|
|
100
|
+
# Two faces running along the same stretch of the plane both ways cancel.
|
|
101
|
+
edges = {(key(a), key(b)): (a, b) for a, b in rims}
|
|
102
|
+
edges = {k: e for k, e in edges.items() if (k[1], k[0]) not in edges}
|
|
103
|
+
following = {k[0]: k for k in edges}
|
|
104
|
+
if len(following) != len(edges):
|
|
105
|
+
raise ValueError("the faces do not close up along the cut")
|
|
106
|
+
loops: list[Array] = []
|
|
107
|
+
while following:
|
|
108
|
+
start = next(iter(following))
|
|
109
|
+
loop, at = [], start
|
|
110
|
+
while at in following:
|
|
111
|
+
edge = following.pop(at)
|
|
112
|
+
loop.append(edges[edge][0])
|
|
113
|
+
at = edge[1]
|
|
114
|
+
if at != start:
|
|
115
|
+
raise ValueError("the faces do not close up along the cut")
|
|
116
|
+
loops.append(np.array(loop))
|
|
117
|
+
regions = _regions(loops, normal)
|
|
118
|
+
return [
|
|
119
|
+
Face("cut" if len(regions) == 1 else f"cut-{k}", loop, normal.copy(), tuple(holes))
|
|
120
|
+
for k, (loop, holes) in enumerate(regions)
|
|
121
|
+
]
|
|
@@ -476,6 +476,72 @@ class _Drawing:
|
|
|
476
476
|
**style,
|
|
477
477
|
)
|
|
478
478
|
|
|
479
|
+
@_trackable
|
|
480
|
+
def line_art(
|
|
481
|
+
self,
|
|
482
|
+
layer: int,
|
|
483
|
+
faces: Iterable[Face],
|
|
484
|
+
*,
|
|
485
|
+
crease_deg: float = 30.0,
|
|
486
|
+
back: Mapping[str, Style] | None = None,
|
|
487
|
+
**style: Style,
|
|
488
|
+
) -> None:
|
|
489
|
+
"""Ink a solid as a technical drawing: its silhouette, creases, and boundaries.
|
|
490
|
+
|
|
491
|
+
For any solid given as faces -- curved ones built of facets, such as
|
|
492
|
+
:func:`~vecview.shapes.revolve` returns, and non-convex ones -- this
|
|
493
|
+
draws the lines a draughtsman would and leaves out the seams between
|
|
494
|
+
facets of one smooth surface. An edge is drawn where one face at it
|
|
495
|
+
faces the camera and another does not (the silhouette, which each
|
|
496
|
+
camera recomputes), where its faces meet at more than ``crease_deg``
|
|
497
|
+
(a rim, a corner, the edge of a cut), and where it bounds one face only
|
|
498
|
+
(the rim of an open surface). Runs of drawn edges are joined into
|
|
499
|
+
continuous lines, so a rim is one stroke, not a row of segments.
|
|
500
|
+
|
|
501
|
+
On a closed solid, a line whose faces all face away lies on the far
|
|
502
|
+
side. It is dropped, or drawn in the ``back`` style -- the dashed
|
|
503
|
+
hidden lines of a technical drawing. What else hides a line, another
|
|
504
|
+
solid or a fold of this one, is found in a layer passed to
|
|
505
|
+
:meth:`~vecview.scene.Scene.sort_by_depth`, where the solid's own faces,
|
|
506
|
+
drawn unstroked with :meth:`faces` in the same layer, hide what is
|
|
507
|
+
behind them::
|
|
508
|
+
|
|
509
|
+
body = vecview.revolve(profile, sweep_deg=(45, 315))
|
|
510
|
+
scene.faces(20, body, fill="white")
|
|
511
|
+
scene.line_art(20, body, stroke="black", back={"stroke_dasharray": "3 2"})
|
|
512
|
+
scene.sort_by_depth(20)
|
|
513
|
+
|
|
514
|
+
There a near-side line hidden by a surface takes the ``back`` style,
|
|
515
|
+
and a far-side one disappears.
|
|
516
|
+
|
|
517
|
+
Args:
|
|
518
|
+
layer: Draw order.
|
|
519
|
+
faces: Faces of the solid, sharing vertices exactly where they meet.
|
|
520
|
+
crease_deg: The angle between the normals of two faces beyond which
|
|
521
|
+
the edge between them is a crease, in degrees. Raise it for a
|
|
522
|
+
coarsely faceted surface whose seams would otherwise show.
|
|
523
|
+
back: Style overrides for lines on the far side, or ``None`` to
|
|
524
|
+
omit them.
|
|
525
|
+
**style: SVG presentation attributes; ``fill`` defaults to none. An
|
|
526
|
+
``id`` becomes ``{id}-front`` and ``{id}-back``.
|
|
527
|
+
|
|
528
|
+
Raises:
|
|
529
|
+
ValueError: Unless ``crease_deg`` lies in ``[0, 180]``.
|
|
530
|
+
"""
|
|
531
|
+
if not 0.0 <= crease_deg <= 180.0:
|
|
532
|
+
raise ValueError(f"crease_deg must lie in [0, 180], got {crease_deg}")
|
|
533
|
+
given = list(faces)
|
|
534
|
+
base = style.pop("id", None)
|
|
535
|
+
self._add(
|
|
536
|
+
"line_art",
|
|
537
|
+
layer,
|
|
538
|
+
given,
|
|
539
|
+
crease_deg=crease_deg,
|
|
540
|
+
back=back,
|
|
541
|
+
**({} if base is None else {"id": base}),
|
|
542
|
+
**style,
|
|
543
|
+
)
|
|
544
|
+
|
|
479
545
|
@_trackable
|
|
480
546
|
def edges(
|
|
481
547
|
self,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""The planar face record every solid in :mod:`vecview.shapes` is built from.
|
|
2
|
+
|
|
3
|
+
Kept apart so that the modules building solids and the one cutting them can
|
|
4
|
+
share it; :mod:`vecview.shapes` re-exports it.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import NamedTuple
|
|
10
|
+
|
|
11
|
+
from vecview._types import Array, Region
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Face(NamedTuple):
|
|
15
|
+
"""One planar polygon of a solid, with the outward normal it was built from.
|
|
16
|
+
|
|
17
|
+
Carrying the normal alongside the points is what lets
|
|
18
|
+
:meth:`~vecview.camera.Camera.visible` decide which walls of a box to draw
|
|
19
|
+
without the caller reasoning about which octant the camera sits in.
|
|
20
|
+
|
|
21
|
+
``points`` winds counter-clockwise about ``normal``. ``holes`` are rings
|
|
22
|
+
cut out of it, each wound the other way -- the cap of a ring or a plate
|
|
23
|
+
with vias; a face with holes is drawn as one even-odd ``<path>``.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
name: str
|
|
27
|
+
points: Array
|
|
28
|
+
normal: Array
|
|
29
|
+
holes: tuple[Array, ...] = ()
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def region(self) -> Region:
|
|
33
|
+
"""The face's planar region, usable by polygon and geometry operations."""
|
|
34
|
+
return Region(self.points, self.holes)
|