Use ArrayLike and NDArray wherever possible. Some type fixes and some related corner cases
This commit is contained in:
parent
89f327ba37
commit
a4fe3d9e2e
20 changed files with 291 additions and 224 deletions
|
|
@ -30,7 +30,8 @@ import logging
|
|||
import pathlib
|
||||
import gzip
|
||||
|
||||
import numpy # type: ignore
|
||||
import numpy
|
||||
from numpy.typing import NDArray
|
||||
import klamath
|
||||
from klamath import records
|
||||
|
||||
|
|
@ -369,10 +370,12 @@ def _subpatterns_to_refs(subpatterns: List[SubPattern]) -> List[klamath.library.
|
|||
properties = _annotations_to_properties(subpat.annotations, 512)
|
||||
|
||||
if isinstance(rep, Grid):
|
||||
xy = numpy.array(subpat.offset) + [
|
||||
b_vector = rep.b_vector if rep.b_vector is not None else numpy.zeros(2)
|
||||
b_count = rep.b_count if rep.b_count is not None else 1
|
||||
xy: NDArray[numpy.float64] = numpy.array(subpat.offset) + [
|
||||
[0, 0],
|
||||
rep.a_vector * rep.a_count,
|
||||
rep.b_vector * rep.b_count,
|
||||
b_vector * b_count,
|
||||
]
|
||||
aref = klamath.library.Reference(struct_name=encoded_name,
|
||||
xy=numpy.round(xy).astype(int),
|
||||
|
|
|
|||
|
|
@ -198,8 +198,7 @@ def writefile(
|
|||
open_func = open
|
||||
|
||||
with io.BufferedWriter(open_func(path, mode='wb')) as stream:
|
||||
results = write(patterns, stream, *args, **kwargs)
|
||||
return results
|
||||
write(patterns, stream, *args, **kwargs)
|
||||
|
||||
|
||||
def readfile(
|
||||
|
|
@ -491,10 +490,14 @@ def _placement_to_subpat(placement: fatrec.Placement, lib: fatamorgana.OasisLayo
|
|||
pname = placement.get_name()
|
||||
name = pname if isinstance(pname, int) else pname.string
|
||||
annotations = properties_to_annotations(placement.properties, lib.propnames, lib.propstrings)
|
||||
if placement.angle is None:
|
||||
rotation = 0
|
||||
else:
|
||||
rotation = numpy.deg2rad(float(placement.angle))
|
||||
subpat = SubPattern(offset=xy,
|
||||
pattern=None,
|
||||
mirrored=(placement.flip, False),
|
||||
rotation=numpy.deg2rad(placement.angle),
|
||||
rotation=rotation,
|
||||
scale=float(mag),
|
||||
identifier=(name,),
|
||||
repetition=repetition_fata2masq(placement.repetition),
|
||||
|
|
|
|||
|
|
@ -28,11 +28,12 @@ import logging
|
|||
import pathlib
|
||||
import gzip
|
||||
|
||||
import numpy # type: ignore
|
||||
import numpy
|
||||
from numpy.typing import ArrayLike, NDArray
|
||||
# python-gdsii
|
||||
import gdsii.library
|
||||
import gdsii.structure
|
||||
import gdsii.elements
|
||||
import gdsii.library #type: ignore
|
||||
import gdsii.structure #type: ignore
|
||||
import gdsii.elements #type: ignore
|
||||
|
||||
from .utils import clean_pattern_vertices, is_gzipped
|
||||
from .. import Pattern, SubPattern, PatternError, Label, Shape
|
||||
|
|
@ -182,8 +183,7 @@ def writefile(
|
|||
open_func = open
|
||||
|
||||
with io.BufferedWriter(open_func(path, mode='wb')) as stream:
|
||||
results = write(patterns, stream, *args, **kwargs)
|
||||
return results
|
||||
write(patterns, stream, *args, **kwargs)
|
||||
|
||||
|
||||
def readfile(
|
||||
|
|
@ -402,10 +402,12 @@ def _subpatterns_to_refs(
|
|||
new_refs: List[Union[gdsii.elements.SRef, gdsii.elements.ARef]]
|
||||
ref: Union[gdsii.elements.SRef, gdsii.elements.ARef]
|
||||
if isinstance(rep, Grid):
|
||||
xy = numpy.array(subpat.offset) + [
|
||||
b_vector = rep.b_vector if rep.b_vector is not None else numpy.zeros(2)
|
||||
b_count = rep.b_count if rep.b_count is not None else 1
|
||||
xy: NDArray[numpy.float64] = numpy.array(subpat.offset) + [
|
||||
[0, 0],
|
||||
rep.a_vector * rep.a_count,
|
||||
rep.b_vector * rep.b_count,
|
||||
b_vector * b_count,
|
||||
]
|
||||
ref = gdsii.elements.ARef(struct_name=encoded_name,
|
||||
xy=numpy.round(xy).astype(int),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ SVG file format readers and writers
|
|||
from typing import Dict, Optional
|
||||
import warnings
|
||||
|
||||
import numpy # type: ignore
|
||||
import numpy
|
||||
from numpy.typing import ArrayLike
|
||||
import svgwrite # type: ignore
|
||||
|
||||
from .utils import mangle_name
|
||||
|
|
@ -141,7 +142,7 @@ def writefile_inverted(pattern: Pattern, filename: str):
|
|||
svg.save()
|
||||
|
||||
|
||||
def poly2path(vertices: numpy.ndarray) -> str:
|
||||
def poly2path(vertices: ArrayLike) -> str:
|
||||
"""
|
||||
Create an SVG path string from an Nx2 list of vertices.
|
||||
|
||||
|
|
@ -151,8 +152,9 @@ def poly2path(vertices: numpy.ndarray) -> str:
|
|||
Returns:
|
||||
SVG path-string.
|
||||
"""
|
||||
commands = 'M{:g},{:g} '.format(vertices[0][0], vertices[0][1])
|
||||
for vertex in vertices[1:]:
|
||||
verts = numpy.array(vertices, copy=False)
|
||||
commands = 'M{:g},{:g} '.format(verts[0][0], verts[0][1])
|
||||
for vertex in verts[1:]:
|
||||
commands += 'L{:g},{:g}'.format(vertex[0], vertex[1])
|
||||
commands += ' Z '
|
||||
return commands
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue