[AutoTool] Enable running AutoTool without any bends in the list
This commit is contained in:
parent
66d6fae2bd
commit
72f462d077
1 changed files with 13 additions and 5 deletions
|
|
@ -543,9 +543,10 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||
return self
|
||||
|
||||
@staticmethod
|
||||
def _bend2dxy(bend: Bend, ccw: SupportsBool | None) -> tuple[NDArray[numpy.float64], float]:
|
||||
def _bend2dxy(bend: Bend | None, ccw: SupportsBool | None) -> tuple[NDArray[numpy.float64], float]:
|
||||
if ccw is None:
|
||||
return numpy.zeros(2), pi
|
||||
assert bend is not None
|
||||
bend_dxy, bend_angle = bend.in_port.measure_travel(bend.out_port)
|
||||
assert bend_angle is not None
|
||||
if bool(ccw):
|
||||
|
|
@ -590,6 +591,11 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||
) -> tuple[Port, LData]:
|
||||
|
||||
success = False
|
||||
# If ccw is None, we don't need a bend, but we still loop to reuse the logic.
|
||||
# We'll use a dummy loop if bends is empty and ccw is None.
|
||||
bends = cast(list[AutoTool.Bend | None], self.bends)
|
||||
if ccw is None and not bends:
|
||||
bends += [None]
|
||||
|
||||
# Initialize these to avoid UnboundLocalError in the error message
|
||||
bend_dxy, bend_angle = numpy.zeros(2), pi
|
||||
|
|
@ -598,7 +604,7 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||
btrans_dxy = numpy.zeros(2)
|
||||
|
||||
for straight in self.straights:
|
||||
for bend in self.bends:
|
||||
for bend in bends:
|
||||
bend_dxy, bend_angle = self._bend2dxy(bend, ccw)
|
||||
|
||||
in_ptype_pair = ('unk' if in_ptype is None else in_ptype, straight.ptype)
|
||||
|
|
@ -607,13 +613,15 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||
|
||||
out_ptype_pair = (
|
||||
'unk' if out_ptype is None else out_ptype,
|
||||
straight.ptype if ccw is None else bend.out_port.ptype
|
||||
straight.ptype if ccw is None else cast(AutoTool.Bend, bend).out_port.ptype
|
||||
)
|
||||
out_transition = self.transitions.get(out_ptype_pair, None)
|
||||
otrans_dxy = self._otransition2dxy(out_transition, bend_angle)
|
||||
|
||||
b_transition = None
|
||||
if ccw is not None and bend.in_port.ptype != straight.ptype:
|
||||
if ccw is not None:
|
||||
assert bend is not None
|
||||
if bend.in_port.ptype != straight.ptype:
|
||||
b_transition = self.transitions.get((bend.in_port.ptype, straight.ptype), None)
|
||||
btrans_dxy = self._itransition2dxy(b_transition)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue