[AutoTool] fix output transition offset

This commit is contained in:
jan 2026-05-28 21:45:06 -07:00
commit e4a52b2c90
2 changed files with 44 additions and 1 deletions

View file

@ -1014,7 +1014,7 @@ class AutoTool(Tool, metaclass=ABCMeta):
return numpy.zeros(2)
orot = out_transition.our_port.rotation
assert orot is not None
otrans_dxy = rotation_matrix_2d(pi - orot - bend_angle) @ (out_transition.their_port.offset - out_transition.our_port.offset)
otrans_dxy = rotation_matrix_2d(bend_angle - orot - pi) @ (out_transition.their_port.offset - out_transition.our_port.offset)
return otrans_dxy
def planL(

View file

@ -132,6 +132,49 @@ def test_autotool_planL_selection(multi_bend_tool) -> None:
assert data.straight_length == 13
assert_allclose(p.offset, [15, 2])
@pytest.mark.parametrize("ccw", [False, True])
def test_autotool_traceL_matches_plan_with_post_bend_transition(ccw: bool) -> None:
lib = Library()
bend_pat = Pattern()
bend_pat.ports["A"] = Port((0, 0), 0, ptype="core")
bend_pat.ports["B"] = Port((2, -2), pi / 2, ptype="core")
lib["core_bend"] = bend_pat
trans_pat = Pattern()
trans_pat.ports["CORE"] = Port((0, 0), 0, ptype="core")
trans_pat.ports["EXT"] = Port((3, 1), pi, ptype="ext")
lib["out_trans"] = trans_pat
tool = AutoTool(
straights=[
AutoTool.Straight(
ptype="core",
fn=lambda length: make_straight(length, ptype="core"),
in_port_name="A",
out_port_name="B",
length_range=(0, 1e8),
),
],
bends=[
AutoTool.Bend(lib.abstract("core_bend"), "A", "B", clockwise=True, mirror=True),
],
sbends=[],
transitions={
("ext", "core"): AutoTool.Transition(lib.abstract("out_trans"), "EXT", "CORE"),
},
default_out_ptype="core",
)
plan_port, data = tool.planL(ccw, 10, out_ptype="ext")
assert data.out_transition is not None
tree = tool.traceL(ccw, 10, out_ptype="ext")
assert_trace_matches_plan(plan_port, tree)
def test_autotool_planU_consistency(multi_bend_tool) -> None:
tool, lib = multi_bend_tool