[AutoTool] enable custom sbend endpoint_at
This commit is contained in:
parent
7083edc7ca
commit
0230fb49a6
3 changed files with 101 additions and 13 deletions
|
|
@ -5,7 +5,7 @@ import pytest
|
|||
from numpy import pi
|
||||
from numpy.testing import assert_allclose
|
||||
|
||||
from masque.builder.tools import AutoTool, PrimitiveOffer, RenderStep, UOffer
|
||||
from masque.builder.tools import AutoTool, PrimitiveOffer, RenderStep, UOffer, circular_arc_sbend_endpoint
|
||||
from masque.builder.pather import Pather
|
||||
from masque.library import Library
|
||||
from masque.pattern import Pattern
|
||||
|
|
@ -368,6 +368,60 @@ def make_sbend_tool(jog_range: tuple[float, float]) -> AutoTool:
|
|||
)
|
||||
|
||||
|
||||
def test_autotool_sbend_custom_endpoint_avoids_generator_during_planning() -> None:
|
||||
calls = 0
|
||||
|
||||
def make_counted_sbend(jog: float) -> Pattern:
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
return make_sbend(jog, ptype="core")
|
||||
|
||||
def endpoint(jog: float) -> Port:
|
||||
return Port((20, jog), rotation=pi, ptype="core")
|
||||
|
||||
tool = AutoTool().add_sbend(
|
||||
"core",
|
||||
make_counted_sbend,
|
||||
"A",
|
||||
"B",
|
||||
jog_range=(0, 1e8),
|
||||
endpoint=endpoint,
|
||||
)
|
||||
|
||||
offer = tool.primitive_offers("s", in_ptype="core")[0]
|
||||
out_port = offer.endpoint_at(4)
|
||||
|
||||
assert calls == 0
|
||||
assert_allclose(out_port.offset, [20, 4])
|
||||
assert out_port.rotation == pi
|
||||
assert out_port.ptype == "core"
|
||||
|
||||
data = offer.commit(4)
|
||||
assert data.parameter == 4
|
||||
assert data.mirrored is False
|
||||
|
||||
|
||||
def test_circular_arc_sbend_endpoint() -> None:
|
||||
endpoint = circular_arc_sbend_endpoint(radius=5, ptype="core")
|
||||
|
||||
out_port = endpoint(4)
|
||||
assert_allclose(out_port.offset, [8, 4])
|
||||
assert out_port.rotation == pi
|
||||
assert out_port.ptype == "core"
|
||||
|
||||
mirrored_port = endpoint(-4)
|
||||
assert_allclose(mirrored_port.offset, [8, -4])
|
||||
assert mirrored_port.rotation == pi
|
||||
assert mirrored_port.ptype == "core"
|
||||
|
||||
zero_port = endpoint(0)
|
||||
assert_allclose(zero_port.offset, [0, 0])
|
||||
assert zero_port.rotation == pi
|
||||
|
||||
with pytest.raises(BuildError, match="exceeds diameter"):
|
||||
endpoint(11)
|
||||
|
||||
|
||||
def make_uturn_pattern(length: float = 10, jog: float = 4, ptype: str = "core") -> Pattern:
|
||||
pat = Pattern()
|
||||
y0, y1 = sorted((0, jog))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue