diff --git a/README.md b/README.md index 68c0686..6448b26 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ to output to multiple formats. - [Source repository](https://mpxd.net/code/jan/masque) - [PyPI](https://pypi.org/project/masque) -- [Github mirror](https://github.com/anewusername/masque) ## Installation diff --git a/masque/__init__.py b/masque/__init__.py index 76ad2b9..15210ba 100644 --- a/masque/__init__.py +++ b/masque/__init__.py @@ -48,5 +48,5 @@ from .utils import ports2data, oneshot __author__ = 'Jan Petykiewicz' -__version__ = '3.1' +__version__ = '3.0' version = __version__ # legacy diff --git a/masque/builder/pather.py b/masque/builder/pather.py index 11e4d80..4f03a0c 100644 --- a/masque/builder/pather.py +++ b/masque/builder/pather.py @@ -15,7 +15,7 @@ from ..library import ILibrary, SINGLE_USE_PREFIX from ..error import PortError, BuildError from ..ports import PortList, Port from ..abstract import Abstract -from ..utils import SupportsBool, rotation_matrix_2d +from ..utils import SupportsBool from .tools import Tool from .utils import ell from .builder import Builder @@ -431,92 +431,6 @@ class Pather(Builder): ) - def path_into( - self, - portspec_src: str, - portspec_dst: str, - *, - tool_port_names: tuple[str, str] = ('A', 'B'), - out_ptype: str = 'unk', - plug_destination: bool = True, - **kwargs, - ) -> Self: - if self._dead: - logger.error('Skipping path_into() since device is dead') - return self - - port_src = self.pattern[portspec_src] - port_dst = self.pattern[portspec_dst] - - if port_src.rotation is None: - raise PortError(f'Port {portspec_src} has no rotation and cannot be used for path_into()') - if port_dst.rotation is None: - raise PortError(f'Port {portspec_dst} has no rotation and cannot be used for path_into()') - - if not numpy.isclose(port_src.rotation % (pi / 2), 0): - raise BuildError('path_to was asked to route from non-manhattan port') - if not numpy.isclose(port_dst.rotation % (pi / 2), 0): - raise BuildError('path_to was asked to route to non-manhattan port') - - src_is_horizontal = numpy.isclose(port_src.rotation % pi, 0) - dst_is_horizontal = numpy.isclose(port_dst.rotation % pi, 0) - xs, ys = port_src.offset - xd, yd = port_dst.offset - - angle = (port_dst.rotation - port_src.rotation) % (2 * pi) - - src_ne = port_src.rotation % (2 * pi) > (3 * pi /4) # path from src will go north or east - - def get_jog(ccw: SupportsBool, length: float) -> float: - tool = self.tools.get(portspec_src, self.tools[None]) - in_ptype = 'unk' # Could use port_src.ptype, but we're assuming this is after one bend already... - tree2 = tool.path(ccw, length, in_ptype=in_ptype, port_names=('A', 'B'), out_ptype=out_ptype, **kwargs) - top2 = tree2.top_pattern() - jog = rotation_matrix_2d(top2['A'].rotation) @ (top2['B'].offset - top2['A'].offset) - return jog[1] - - dst_extra_args = {'out_ptype': out_ptype} - if plug_destination: - dst_extra_args['plug_into'] = portspec_dst - - src_args = {**kwargs, 'tool_port_names': tool_port_names} - dst_args = {**src_args, **dst_extra_args} - if src_is_horizontal and not dst_is_horizontal: - # single bend should suffice - self.path_to(portspec_src, angle > pi, x=xd, **src_args) - self.path_to(portspec_src, None, y=yd, **dst_args) - elif dst_is_horizontal and not src_is_horizontal: - # single bend should suffice - self.path_to(portspec_src, angle > pi, y=yd, **src_args) - self.path_to(portspec_src, None, x=xd, **dst_args) - elif numpy.isclose(angle, pi): - if src_is_horizontal and ys == yd: - # straight connector - self.path_to(portspec_src, None, x=xd, **dst_args) - elif not src_is_horizontal and xs == xd: - # straight connector - self.path_to(portspec_src, None, y=yd, **dst_args) - elif src_is_horizontal: - # figure out how much x our y-segment (2nd) takes up, then path based on that - y_len = numpy.abs(yd - ys) - ccw2 = src_ne != (yd > ys) - jog = get_jog(ccw2, y_len) * numpy.sign(xd - xs) - self.path_to(portspec_src, not ccw2, x=xd - jog, **src_args) - self.path_to(portspec_src, ccw2, y=yd, **dst_args) - else: - # figure out how much y our x-segment (2nd) takes up, then path based on that - x_len = numpy.abs(xd - xs) - ccw2 = src_ne != (xd < xs) - jog = get_jog(ccw2, x_len) * numpy.sign(yd - ys) - self.path_to(portspec_src, not ccw2, y=yd - jog, **src_args) - self.path_to(portspec_src, ccw2, x=xd, **dst_args) - elif numpy.isclose(angle, 0): - raise BuildError(f'Don\'t know how to route a U-bend at this time!') - else: - raise BuildError(f'Don\'t know how to route ports with relative angle {angle}') - - return self - def mpath( self, portspec: str | Sequence[str], diff --git a/masque/utils/pack2d.py b/masque/utils/pack2d.py index ed6c4b5..d298404 100644 --- a/masque/utils/pack2d.py +++ b/masque/utils/pack2d.py @@ -62,8 +62,7 @@ def maxrects_bssf( ''' Place the rect ''' # Best short-side fit (bssf) to pick a region - region_sizes = regions[:, 2:] - regions[:, :2] - bssf_scores = (region_sizes - rect_size).min(axis=1).astype(float) + bssf_scores = ((regions[:, 2:] - regions[:, :2]) - rect_size).min(axis=1).astype(float) bssf_scores[bssf_scores < 0] = numpy.inf # doesn't fit! rr = bssf_scores.argmin() if numpy.isinf(bssf_scores[rr]): @@ -153,8 +152,7 @@ def guillotine_bssf_sas( for rect_ind, rect_size in enumerate(rect_sizes): ''' Place the rect ''' # Best short-side fit (bssf) to pick a region - region_sizes = regions[:, 2:] - regions[:, :2] - bssf_scores = (region_sizes - rect_size).min(axis=1).astype(float) + bssf_scores = ((regions[:, 2:] - regions[:, :2]) - rect_size).min(axis=1).astype(float) bssf_scores[bssf_scores < 0] = numpy.inf # doesn't fit! rr = bssf_scores.argmin() if numpy.isinf(bssf_scores[rr]): @@ -168,7 +166,7 @@ def guillotine_bssf_sas( loc = regions[rr, :2] rect_locs[rect_ind] = loc - region_size = region_sizes[rr] + region_size = regions[rr, 2:] - loc split_horiz = region_size[0] < region_size[1] new_region0 = regions[rr].copy()