geomotif.io.points
¶
Write coordinates out, and read a structured design back in.
Two writers, and the difference between them is strokes:
- :func:
save_pointsflattens everything to one list ofx, ypairs. It is what you want for a spreadsheet, a game map, or anything that just needs the coordinates. - :func:
save_designkeeps the paths apart, so a plotter knows where to lift the pen and a reader knows which points belong to the same stroke.
Only the JSON form of :func:save_design reads back, via :func:load_design.
CSV and TXT are export formats: they are shaped for whatever tool is going to
consume them, and both flatten metadata away. If you want the design back, use
JSON -- and if you want the recipe back rather than the points, that is
:mod:geomotif.io.spec, which writes a file a hundred times smaller.
Functions:
| Name | Description |
|---|---|
save_points |
Write points to a file and return the path written. |
save_design |
Write a design, strokes kept apart, and return the path written. |
load_design |
Read a design back from a JSON file written by :func: |
save_points
¶
save_points(points: Iterable[Point], path: str | PathLike[str], *, fmt: PointFormat | None = None, precision: int | None = None) -> Path
Write points to a file and return the path written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
iterable of (float, float)
|
The points to export. A :class: |
required |
path
|
str or path - like
|
Destination file. |
required |
fmt
|
('csv', 'txt', 'json')
|
Output format. Inferred from the file suffix when omitted
(
|
"csv"
|
precision
|
int
|
Round coordinates to this many decimal places. This rounds the file rather than the design, so it says nothing about
what the other writers do with the same points.
:meth: |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The file that was written. |
Source code in src/geomotif/io/points.py
save_design
¶
save_design(design: Design, path: str | PathLike[str], *, fmt: PointFormat | None = None, precision: int | None = None, meta: bool = True) -> Path
Write a design, strokes kept apart, and return the path written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
design
|
Design
|
What to write. |
required |
path
|
str or path - like
|
Destination file. |
required |
fmt
|
('csv', 'txt', 'json')
|
Output format, inferred from the suffix when omitted.
|
"csv"
|
precision
|
int
|
Round coordinates to this many decimal places, as for
:func: |
None
|
meta
|
bool
|
Record the design's recipe alongside its points, for the JSON format only. Turn it off for a design whose motif takes a parameter that cannot be written as data. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The file that was written. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/geomotif/io/points.py
102 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 185 186 187 188 | |
load_design
¶
load_design(path: str | PathLike[str]) -> Design
Read a design back from a JSON file written by :func:save_design.
A plain JSON array of pairs -- what :func:save_points writes -- also
loads, as a design of loose points with no strokes. The two shapes are an
array and an object, so there is nothing to guess at.
Returns:
| Type | Description |
|---|---|
Design
|
With |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is not one of the two shapes above. |