Index
pleat.io ¶
File I/O for pleat graphs: the .heg half-edge format, the CirclePack
.p format, and the FOLD crease-pattern format.
CirclePackData
dataclass
¶
CirclePackData(
nodecount: int,
geometry: str | None,
alpha: int | None,
beta: int | None,
gamma: int | None,
flowers: dict[int, list[int]],
radii: ndarray | None,
centers: ndarray | None,
)
Structured contents of a CirclePack .p file.
All vertex indices are 0-indexed internally even though the file format
stores them 1-indexed. Use :func:parse_p_file to read and
:func:write_p_file to write this dataclass verbatim.
load_circlepack ¶
Load a CirclePack .p file into an :class:EuclideanPositionHEG.
Populates v['pos'] and v['radius'] on every vertex when the file
provides RADII (and CENTERS, where applicable). For hyperbolic packings
the file's RADII are interpreted as x-radii; the returned graph stores
the corresponding euclidean (Poincaré-disk) center and radius, matching
:func:pleat.circle_packing.pack_hyperbolic's output convention. If a
hyperbolic file omits CENTERS, the layout is computed via
:func:pleat.circle_packing._layout_hyperbolic.
The returned graph's geometry is set to :class:EuclideanGeometry or
:class:PoincareDiskModel based on the file's GEOMETRY line; unknown or
missing values default to :class:EuclideanGeometry.
Source code in pleat/io/circlepack.py
parse_p_file ¶
Parse a CirclePack .p file into a :class:CirclePackData dataclass.
Source code in pleat/io/circlepack.py
save_circlepack ¶
Save an :class:EuclideanPositionHEG to a CirclePack .p file.
Emits FLOWERS for the triangulation, plus RADII / CENTERS if every vertex
has radius / pos attributes, plus GEOMETRY based on G.geometry.
Hyperbolic packings (G.geometry is PoincareDiskModel) are emitted with
x-radii in the RADII section, matching CirclePack's convention.
Source code in pleat/io/circlepack.py
write_p_file ¶
Write a :class:CirclePackData verbatim to a CirclePack .p file.
Vertex labels and the per-vertex neighbor list order in data.flowers
are preserved exactly, so :func:parse_p_file ∘ :func:write_p_file
round-trips losslessly (modulo float precision).
Source code in pleat/io/circlepack.py
fold_to_graph ¶
Reconstruct a Euclidean half-edge graph from a FOLD dict.
Requires faces_vertices (needs oriented faces to rebuild the DCEL).
Interior edges are twinned across their two faces; boundary edges get a
border twin (face=None) linked into the outer cycle. vertices_coords
restores positions and edges_assignment restores M/V creases.
Source code in pleat/io/fold.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
graph_to_fold ¶
Serialise a Euclidean crease-pattern graph to a FOLD v1.2 dict.
Undirected edges are the rev-pairs of G.halfedges. Each edge's
assignment comes from :data:CREASE_ASSIGNMENT (M/V), or "B" when either
side is a border half-edge, or "U" otherwise. Faces are G.faces (the
outer region is not a Face in pleat), each emitted as its CCW vertex loop.
Raises:
| Type | Description |
|---|---|
ValueError
|
if G does not have real 2D vertex positions -- FOLD cannot represent the hyperbolic (complex Poincaré-disk) or spherical (3D) coordinates pleat uses for curved tilings. |
Source code in pleat/io/fold.py
load_fold ¶
save_fold ¶
Write G to a .fold JSON file (appends .fold if missing).
Source code in pleat/io/fold.py
dict_to_graph ¶
Inverse of :func:graph_to_dict: reconstruct a graph from its serialised dict.
The returned graph is always an :class:EuclideanPositionHEG regardless of
the source graph's class (TODO: persist the class).
Source code in pleat/io/heg.py
graph_to_dict ¶
graph_to_dict(
G: HalfEdgeGraph,
attributes_to_save: tuple[str, ...] = (
"pos",
"length",
"in_angle",
"color_key",
),
) -> dict
Serialise a half-edge graph to a JSON/YAML-friendly nested dict.
Vertices, half-edges, and faces are each given an opaque string label
(v0, h0, f0, ...). Cross-references are stored by label.
Numpy arrays in attributes are converted to plain Python lists, and numpy
scalars to float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
HalfEdgeGraph
|
The graph to serialise. |
required |
attributes_to_save
|
tuple[str, ...]
|
Attribute keys to copy onto each element. Other attributes are dropped. |
('pos', 'length', 'in_angle', 'color_key')
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
func: |
Source code in pleat/io/heg.py
load_graph ¶
Load a graph previously saved by :func:save_graph.
Source code in pleat/io/heg.py
save_graph ¶
save_graph(
filename: str,
graph: HalfEdgeGraph,
overwrite: bool = False,
extra_attributes_to_save: (
str | tuple[str, ...] | None
) = None,
attributes_to_save: tuple[str, ...] = (
"pos",
"length",
"in_angle",
"color_key",
),
) -> None
Save graph to a .heg (YAML) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output path; |
required |
graph
|
HalfEdgeGraph
|
The graph to save. |
required |
overwrite
|
bool
|
If False and the file already exists, raise instead of overwriting. |
False
|
extra_attributes_to_save
|
str | tuple[str, ...] | None
|
Convenience: attribute key(s) to save in addition to attributes_to_save. |
None
|
attributes_to_save
|
tuple[str, ...]
|
Attribute keys to persist (see :func: |
('pos', 'length', 'in_angle', 'color_key')
|