[OASIS] cleanup

This commit is contained in:
Jan Petykiewicz 2026-02-15 16:43:46 -08:00
commit c18e5b8d3e

View file

@ -120,10 +120,10 @@ def build(
layer, data_type = _mlayer2oas(layer_num) layer, data_type = _mlayer2oas(layer_num)
lib.layers += [ lib.layers += [
fatrec.LayerName( fatrec.LayerName(
nstring=name, nstring = name,
layer_interval=(layer, layer), layer_interval = (layer, layer),
type_interval=(data_type, data_type), type_interval = (data_type, data_type),
is_textlayer=tt, is_textlayer = tt,
) )
for tt in (True, False)] for tt in (True, False)]
@ -286,11 +286,11 @@ def read(
annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings) annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings)
pat.polygon( pat.polygon(
vertices=vertices, vertices = vertices,
layer=element.get_layer_tuple(), layer = element.get_layer_tuple(),
offset=element.get_xy(), offset = element.get_xy(),
annotations=annotations, annotations = annotations,
repetition=repetition, repetition = repetition,
) )
elif isinstance(element, fatrec.Path): elif isinstance(element, fatrec.Path):
vertices = numpy.cumsum(numpy.vstack(((0, 0), element.get_point_list())), axis=0) vertices = numpy.cumsum(numpy.vstack(((0, 0), element.get_point_list())), axis=0)
@ -310,13 +310,13 @@ def read(
annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings) annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings)
pat.path( pat.path(
vertices=vertices, vertices = vertices,
layer=element.get_layer_tuple(), layer = element.get_layer_tuple(),
offset=element.get_xy(), offset = element.get_xy(),
repetition=repetition, repetition = repetition,
annotations=annotations, annotations = annotations,
width=element.get_half_width() * 2, width = element.get_half_width() * 2,
cap=cap, cap = cap,
**path_args, **path_args,
) )
@ -325,11 +325,11 @@ def read(
height = element.get_height() height = element.get_height()
annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings) annotations = properties_to_annotations(element.properties, lib.propnames, lib.propstrings)
pat.polygon( pat.polygon(
layer=element.get_layer_tuple(), layer = element.get_layer_tuple(),
offset=element.get_xy(), offset = element.get_xy(),
repetition=repetition, repetition = repetition,
vertices=numpy.array(((0, 0), (1, 0), (1, 1), (0, 1))) * (width, height), vertices = numpy.array(((0, 0), (1, 0), (1, 1), (0, 1))) * (width, height),
annotations=annotations, annotations = annotations,
) )
elif isinstance(element, fatrec.Trapezoid): elif isinstance(element, fatrec.Trapezoid):
@ -440,11 +440,11 @@ def read(
else: else:
string = str_or_ref.string string = str_or_ref.string
pat.label( pat.label(
layer=element.get_layer_tuple(), layer = element.get_layer_tuple(),
offset=element.get_xy(), offset = element.get_xy(),
repetition=repetition, repetition = repetition,
annotations=annotations, annotations = annotations,
string=string, string = string,
) )
else: else:
@ -549,13 +549,13 @@ def _shapes_to_elements(
offset = rint_cast(shape.offset + rep_offset) offset = rint_cast(shape.offset + rep_offset)
radius = rint_cast(shape.radius) radius = rint_cast(shape.radius)
circle = fatrec.Circle( circle = fatrec.Circle(
layer=layer, layer = layer,
datatype=datatype, datatype = datatype,
radius=cast('int', radius), radius = cast('int', radius),
x=offset[0], x = offset[0],
y=offset[1], y = offset[1],
properties=properties, properties = properties,
repetition=repetition, repetition = repetition,
) )
elements.append(circle) elements.append(circle)
elif isinstance(shape, Path): elif isinstance(shape, Path):
@ -566,16 +566,16 @@ def _shapes_to_elements(
extension_start = (path_type, shape.cap_extensions[0] if shape.cap_extensions is not None else None) extension_start = (path_type, shape.cap_extensions[0] if shape.cap_extensions is not None else None)
extension_end = (path_type, shape.cap_extensions[1] if shape.cap_extensions is not None else None) extension_end = (path_type, shape.cap_extensions[1] if shape.cap_extensions is not None else None)
path = fatrec.Path( path = fatrec.Path(
layer=layer, layer = layer,
datatype=datatype, datatype = datatype,
point_list=cast('Sequence[Sequence[int]]', deltas), point_list = cast('Sequence[Sequence[int]]', deltas),
half_width=cast('int', half_width), half_width = cast('int', half_width),
x=xy[0], x = xy[0],
y=xy[1], y = xy[1],
extension_start=extension_start, # TODO implement multiple cap types? extension_start = extension_start, # TODO implement multiple cap types?
extension_end=extension_end, extension_end = extension_end,
properties=properties, properties = properties,
repetition=repetition, repetition = repetition,
) )
elements.append(path) elements.append(path)
else: else:
@ -583,13 +583,13 @@ def _shapes_to_elements(
xy = rint_cast(polygon.offset + polygon.vertices[0] + rep_offset) xy = rint_cast(polygon.offset + polygon.vertices[0] + rep_offset)
points = rint_cast(numpy.diff(polygon.vertices, axis=0)) points = rint_cast(numpy.diff(polygon.vertices, axis=0))
elements.append(fatrec.Polygon( elements.append(fatrec.Polygon(
layer=layer, layer = layer,
datatype=datatype, datatype = datatype,
x=xy[0], x = xy[0],
y=xy[1], y = xy[1],
point_list=cast('list[list[int]]', points), point_list = cast('list[list[int]]', points),
properties=properties, properties = properties,
repetition=repetition, repetition = repetition,
)) ))
return elements return elements
@ -606,13 +606,13 @@ def _labels_to_texts(
xy = rint_cast(label.offset + rep_offset) xy = rint_cast(label.offset + rep_offset)
properties = annotations_to_properties(label.annotations) properties = annotations_to_properties(label.annotations)
texts.append(fatrec.Text( texts.append(fatrec.Text(
layer=layer, layer = layer,
datatype=datatype, datatype = datatype,
x=xy[0], x = xy[0],
y=xy[1], y = xy[1],
string=label.string, string = label.string,
properties=properties, properties = properties,
repetition=repetition, repetition = repetition,
)) ))
return texts return texts
@ -622,10 +622,12 @@ def repetition_fata2masq(
) -> Repetition | None: ) -> Repetition | None:
mrep: Repetition | None mrep: Repetition | None
if isinstance(rep, fatamorgana.GridRepetition): if isinstance(rep, fatamorgana.GridRepetition):
mrep = Grid(a_vector=rep.a_vector, mrep = Grid(
b_vector=rep.b_vector, a_vector = rep.a_vector,
a_count=rep.a_count, b_vector = rep.b_vector,
b_count=rep.b_count) a_count = rep.a_count,
b_count = rep.b_count,
)
elif isinstance(rep, fatamorgana.ArbitraryRepetition): elif isinstance(rep, fatamorgana.ArbitraryRepetition):
displacements = numpy.cumsum(numpy.column_stack(( displacements = numpy.cumsum(numpy.column_stack((
rep.x_displacements, rep.x_displacements,
@ -647,14 +649,19 @@ def repetition_masq2fata(
frep: fatamorgana.GridRepetition | fatamorgana.ArbitraryRepetition | None frep: fatamorgana.GridRepetition | fatamorgana.ArbitraryRepetition | None
if isinstance(rep, Grid): if isinstance(rep, Grid):
a_vector = rint_cast(rep.a_vector) a_vector = rint_cast(rep.a_vector)
b_vector = rint_cast(rep.b_vector) if rep.b_vector is not None else None a_count = int(rep.a_count)
a_count = rint_cast(rep.a_count) if rep.b_count > 1:
b_count = rint_cast(rep.b_count) if rep.b_count is not None else None b_vector = rint_cast(rep.b_vector)
b_count = int(rep.b_count)
else:
b_vector = None
b_count = None
frep = fatamorgana.GridRepetition( frep = fatamorgana.GridRepetition(
a_vector=cast('list[int]', a_vector), a_vector = a_vector,
b_vector=cast('list[int] | None', b_vector), b_vector = b_vector,
a_count=cast('int', a_count), a_count = a_count,
b_count=cast('int | None', b_count), b_count = b_count,
) )
offset = (0, 0) offset = (0, 0)
elif isinstance(rep, Arbitrary): elif isinstance(rep, Arbitrary):