diff --git a/masque/builder/renderpather.py b/masque/builder/renderpather.py index c546f8b..ba97fd7 100644 --- a/masque/builder/renderpather.py +++ b/masque/builder/renderpather.py @@ -345,17 +345,6 @@ class RenderPather(PortList, PatherMixin): return self - def plugged( - self, - connections: dict[str, str], - ) -> Self: - for aa, bb in connections.items(): - porta = self.ports[aa] - portb = self.ports[bb] - self.paths[aa].append(RenderStep('P', None, porta.copy(), porta.copy(), None)) - self.paths[bb].append(RenderStep('P', None, portb.copy(), portb.copy(), None)) - PortList.plugged(self, connections) - return self def path( self, diff --git a/masque/builder/tools.py b/masque/builder/tools.py index 2acdffd..1ff6d54 100644 --- a/masque/builder/tools.py +++ b/masque/builder/tools.py @@ -340,7 +340,7 @@ class BasicTool(Tool, metaclass=ABCMeta): bend_angle *= -1 else: bend_dxy = numpy.zeros(2) - bend_angle = pi + bend_angle = 0 in_transition = self.transitions.get('unk' if in_ptype is None else in_ptype, None) if in_transition is not None: @@ -401,15 +401,15 @@ class BasicTool(Tool, metaclass=ABCMeta): gen_straight, sport_in, _sport_out = self.straight for step in batch: - data = step.data + straight_length, ccw, in_transition, out_transition = step.data assert step.tool == self if step.opcode == 'L': - if data.in_transition: - ipat, iport_theirs, _iport_ours = data.in_transition + if in_transition: + ipat, iport_theirs, _iport_ours = in_transition pat.plug(ipat, {port_names[1]: iport_theirs}) - if not numpy.isclose(data.straight_length, 0): - straight_pat_or_tree = gen_straight(data.straight_length, **kwargs) + if not numpy.isclose(straight_length, 0): + straight_pat_or_tree = gen_straight(straight_length, **kwargs) pmap = {port_names[1]: sport_in} if isinstance(straight_pat_or_tree, Pattern): straight_pat = straight_pat_or_tree @@ -427,11 +427,11 @@ class BasicTool(Tool, metaclass=ABCMeta): else: straight = tree <= straight_pat_or_tree pat.plug(straight, pmap) - if data.ccw is not None: + if ccw is not None: bend, bport_in, bport_out = self.bend - pat.plug(bend, {port_names[1]: bport_in}, mirrored=bool(data.ccw)) - if data.out_transition: - opat, oport_theirs, oport_ours = data.out_transition + pat.plug(bend, {port_names[1]: bport_in}, mirrored=bool(ccw)) + if out_transition: + opat, oport_theirs, oport_ours = out_transition pat.plug(opat, {port_names[1]: oport_ours}) return tree @@ -443,8 +443,7 @@ class AutoTool(Tool, metaclass=ABCMeta): for generating straight paths, and a table of pre-rendered `transitions` for converting from non-native ptypes. """ - straights: list[tuple[str, Callable[[float], Pattern] | Callable[[float], Library], str, str, tuple[float, float]]] - # TODO add min length? + straights: list[tuple[str, Callable[[float], Pattern] | Callable[[float], Library], str, str]] bends: list[abstract_tuple_t] # Assumed to be clockwise """ `clockwise_bend_abstract, in_port_name, out_port_name` """ @@ -509,7 +508,7 @@ class AutoTool(Tool, metaclass=ABCMeta): @staticmethod def _bend2dxy(bend_tuple: abstract_tuple_t, ccw: SupportsBool | None) -> tuple[NDArray[numpy.float64], float]: if ccw is None: - return numpy.zeros(2), pi + return numpy.zeros(2), 0.0 bend, bport_in, bport_out = bend_tuple angle_in = bend.ports[bport_in].rotation @@ -567,10 +566,9 @@ class AutoTool(Tool, metaclass=ABCMeta): ) -> tuple[Port, LData]: # TODO check all the math for L-shaped bends - success = False + for straight_tuple in self.straights: stype = straight_tuple[0] - straight_bounds = straight_tuple[-1] for bend_tuple in self.bends: bend_dxy, bend_angle = self._bend2dxy(bend_tuple, ccw) btypei = bend_tuple[0][bend_tuple[1]].ptype @@ -580,7 +578,7 @@ class AutoTool(Tool, metaclass=ABCMeta): itrans_dxy = self._itransition2dxy(in_transition) out_transition = self.transitions.get(('unk' if out_ptype is None else out_ptype, stype if ccw is None else btypeo), None) - otrans_dxy = self._otransition2dxy(out_transition, bend_angle) + otrans_dxy = self._otransition2dxy(in_transition, bend_angle) b_transition = None if ccw is not None and btypei != stype: @@ -589,10 +587,9 @@ class AutoTool(Tool, metaclass=ABCMeta): straight_length = length - bend_dxy[0] - itrans_dxy[0] - btrans_dxy[0] - otrans_dxy[0] bend_run = bend_dxy[1] + itrans_dxy[1] + btrans_dxy[1] + otrans_dxy[1] - success = straight_bounds[0] <= straight_length < straight_bounds[1] - if success: + if straight_length >= 0: break - if success: + if straight_length >= 0: break else: # Failed to break @@ -628,16 +625,15 @@ class AutoTool(Tool, metaclass=ABCMeta): pat.add_port_pair(names=(port_names[0], port_names[1])) for step in batch: - data = step.data - _stype, gen_straight, sport_in, _sport_out, _length_bounds = data.straight_tuple + _stype, gen_straight, sport_in, _sport_out = step.data.straight_tuple assert step.tool == self if step.opcode == 'L': - if data.in_transition: - ipat, iport_theirs, _iport_ours = data.in_transition + if step.data.in_transition: + ipat, iport_theirs, _iport_ours = step.data.in_transition pat.plug(ipat, {port_names[1]: iport_theirs}) - if not numpy.isclose(data.straight_length, 0): - straight_pat_or_tree = gen_straight(data.straight_length, **kwargs) + if not numpy.isclose(step.data.straight_length, 0): + straight_pat_or_tree = gen_straight(step.data.straight_length, **kwargs) pmap = {port_names[1]: sport_in} if isinstance(straight_pat_or_tree, Pattern): straight_pat = straight_pat_or_tree @@ -655,18 +651,19 @@ class AutoTool(Tool, metaclass=ABCMeta): else: straight = tree <= straight_pat_or_tree pat.plug(straight, pmap) - if data.b_transition: - btpat, btport_bend, btport_straight = data.b_transition + if step.data.b_transition: + btpat, btport_bend, btport_straight = step.data.b_transition pat.plug(btpat, {port_names[1]: btport_straight}) - if data.ccw is not None: - bend, bport_in, bport_out = data.bend_tuple - pat.plug(bend, {port_names[1]: bport_in}, mirrored=bool(data.ccw)) - if data.out_transition: - opat, oport_theirs, oport_ours = data.out_transition + if step.data.ccw is not None: + bend, bport_in, bport_out = step.data.bend_tuple + pat.plug(bend, {port_names[1]: bport_in}, mirrored=bool(step.data.ccw)) + if step.data.out_transition: + opat, oport_theirs, oport_ours = step.data.out_transition pat.plug(opat, {port_names[1]: oport_ours}) return tree + @dataclass class PathTool(Tool, metaclass=ABCMeta): """