[shapes] move to per-shape purpose-built _from_raw constructors
This commit is contained in:
parent
85aed4388e
commit
e009417eed
11 changed files with 290 additions and 141 deletions
|
|
@ -323,26 +323,40 @@ def _gpath_to_mpath(gpath: klamath.library.Path, raw_mode: bool) -> tuple[layer_
|
|||
else:
|
||||
raise PatternError(f'Unrecognized path type: {gpath.path_type}')
|
||||
|
||||
mpath = Path(
|
||||
vertices=gpath.xy.astype(float),
|
||||
width=gpath.width,
|
||||
cap=cap,
|
||||
offset=numpy.zeros(2),
|
||||
annotations=_properties_to_annotations(gpath.properties),
|
||||
raw=raw_mode,
|
||||
)
|
||||
vertices = gpath.xy.astype(float)
|
||||
annotations = _properties_to_annotations(gpath.properties)
|
||||
cap_extensions = None
|
||||
if cap == Path.Cap.SquareCustom:
|
||||
mpath.cap_extensions = gpath.extension
|
||||
cap_extensions = numpy.asarray(gpath.extension, dtype=float)
|
||||
|
||||
if raw_mode:
|
||||
mpath = Path._from_raw(
|
||||
vertices=vertices,
|
||||
width=gpath.width,
|
||||
cap=cap,
|
||||
cap_extensions=cap_extensions,
|
||||
annotations=annotations,
|
||||
)
|
||||
else:
|
||||
mpath = Path(
|
||||
vertices=vertices,
|
||||
width=gpath.width,
|
||||
cap=cap,
|
||||
cap_extensions=cap_extensions,
|
||||
offset=numpy.zeros(2),
|
||||
annotations=annotations,
|
||||
)
|
||||
return gpath.layer, mpath
|
||||
|
||||
|
||||
def _boundary_to_polygon(boundary: klamath.library.Boundary, raw_mode: bool) -> tuple[layer_t, Polygon]:
|
||||
return boundary.layer, Polygon(
|
||||
vertices=boundary.xy[:-1].astype(float),
|
||||
offset=numpy.zeros(2),
|
||||
annotations=_properties_to_annotations(boundary.properties),
|
||||
raw=raw_mode,
|
||||
)
|
||||
vertices = boundary.xy[:-1].astype(float)
|
||||
annotations = _properties_to_annotations(boundary.properties)
|
||||
if raw_mode:
|
||||
poly = Polygon._from_raw(vertices=vertices, annotations=annotations)
|
||||
else:
|
||||
poly = Polygon(vertices=vertices, offset=numpy.zeros(2), annotations=annotations)
|
||||
return boundary.layer, poly
|
||||
|
||||
|
||||
def _mrefs_to_grefs(refs: dict[str | None, list[Ref]]) -> list[klamath.library.Reference]:
|
||||
|
|
|
|||
|
|
@ -680,8 +680,23 @@ def _gpaths_to_mpaths(
|
|||
cap_extensions = None
|
||||
|
||||
annotations = _read_annotations(prop_offs, prop_key, prop_val, ee)
|
||||
path = Path(vertices=vertices, offset=ZERO_OFFSET, annotations=annotations, raw=raw_mode,
|
||||
width=width, cap=cap,cap_extensions=cap_extensions)
|
||||
if raw_mode:
|
||||
path = Path._from_raw(
|
||||
vertices=vertices,
|
||||
width=width,
|
||||
cap=cap,
|
||||
cap_extensions=cap_extensions,
|
||||
annotations=annotations,
|
||||
)
|
||||
else:
|
||||
path = Path(
|
||||
vertices=vertices,
|
||||
width=width,
|
||||
cap=cap,
|
||||
cap_extensions=cap_extensions,
|
||||
offset=ZERO_OFFSET,
|
||||
annotations=annotations,
|
||||
)
|
||||
pat.shapes[layer].append(path)
|
||||
|
||||
|
||||
|
|
@ -718,13 +733,13 @@ def _boundary_batches_to_polygons(
|
|||
if raw_mode:
|
||||
poly = Polygon._from_raw(vertices=vertices, annotations=None)
|
||||
else:
|
||||
poly = Polygon(vertices=vertices, offset=ZERO_OFFSET, annotations=None, raw=False)
|
||||
poly = Polygon(vertices=vertices, offset=ZERO_OFFSET, annotations=None)
|
||||
pat.shapes[layer].append(poly)
|
||||
else:
|
||||
if raw_mode:
|
||||
polys = PolyCollection._from_raw(vertex_lists=vertices, vertex_offsets=vertex_offsets, annotations=None)
|
||||
else:
|
||||
polys = PolyCollection(vertex_lists=vertices, vertex_offsets=vertex_offsets, offset=ZERO_OFFSET, annotations=None, raw=False)
|
||||
polys = PolyCollection(vertex_lists=vertices, vertex_offsets=vertex_offsets, offset=ZERO_OFFSET, annotations=None)
|
||||
pat.shapes[layer].append(polys)
|
||||
|
||||
|
||||
|
|
@ -755,7 +770,7 @@ def _rect_batches_to_rectcollections(
|
|||
if raw_mode:
|
||||
rect_collection = RectCollection._from_raw(rects=rects, annotations=None)
|
||||
else:
|
||||
rect_collection = RectCollection(rects=rects, offset=ZERO_OFFSET, annotations=None, raw=False)
|
||||
rect_collection = RectCollection(rects=rects, offset=ZERO_OFFSET, annotations=None)
|
||||
pat.shapes[layer].append(rect_collection)
|
||||
|
||||
|
||||
|
|
@ -790,7 +805,7 @@ def _boundary_props_to_polygons(
|
|||
if raw_mode:
|
||||
poly = Polygon._from_raw(vertices=vertices, annotations=annotations)
|
||||
else:
|
||||
poly = Polygon(vertices=vertices, offset=ZERO_OFFSET, annotations=annotations, raw=False)
|
||||
poly = Polygon(vertices=vertices, offset=ZERO_OFFSET, annotations=annotations)
|
||||
pat.shapes[layer].append(poly)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue