From 899d05217e2468115e5608038dcc8bd167cac4b3 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 12 Nov 2025 17:42:52 -0800 Subject: [PATCH] [AutoTool] support min/max length for straight segments --- masque/builder/tools.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/masque/builder/tools.py b/masque/builder/tools.py index ac505ff..2acdffd 100644 --- a/masque/builder/tools.py +++ b/masque/builder/tools.py @@ -443,7 +443,8 @@ 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]] + straights: list[tuple[str, Callable[[float], Pattern] | Callable[[float], Library], str, str, tuple[float, float]]] + # TODO add min length? bends: list[abstract_tuple_t] # Assumed to be clockwise """ `clockwise_bend_abstract, in_port_name, out_port_name` """ @@ -566,9 +567,10 @@ 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 @@ -587,9 +589,10 @@ 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] - if straight_length >= 0: + success = straight_bounds[0] <= straight_length < straight_bounds[1] + if success: break - if straight_length >= 0: + if success: break else: # Failed to break