From 2b835ec3a49a558c43d1922bde7ec8319626065d Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 20 Nov 2025 12:59:20 -0800 Subject: [PATCH 1/3] [Port] mirror() should not mirror port position, only orientation --- masque/pattern.py | 11 ++++++----- masque/ports.py | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/masque/pattern.py b/masque/pattern.py index 4a401b6..d870a43 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -1169,12 +1169,13 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): ports[new_name] = port for name, port in ports.items(): - p = port.deepcopy() + pp = port.deepcopy() if mirrored: - p.mirror() - p.rotate_around(pivot, rotation) - p.translate(offset) - self.ports[name] = p + pp.mirror() + pp.offset[1] *= -1 + pp.rotate_around(pivot, rotation) + pp.translate(offset) + self.ports[name] = pp if append: if isinstance(other, Abstract): diff --git a/masque/ports.py b/masque/ports.py index b8137c0..0211723 100644 --- a/masque/ports.py +++ b/masque/ports.py @@ -100,7 +100,6 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable): return self def mirror(self, axis: int = 0) -> Self: - self.offset[1 - axis] *= -1 if self.rotation is not None: self.rotation *= -1 self.rotation += axis * pi From 355365c0dc20533a432b518d79b068fddc359281 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 20 Nov 2025 13:00:57 -0800 Subject: [PATCH 2/3] [Pather / RenderPather] Fix handling of jog polarity --- masque/builder/pather.py | 9 +++++---- masque/builder/pather_mixin.py | 2 +- masque/builder/renderpather.py | 11 ++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/masque/builder/pather.py b/masque/builder/pather.py index 3a0dee4..9af473d 100644 --- a/masque/builder/pather.py +++ b/masque/builder/pather.py @@ -352,16 +352,17 @@ class Pather(Builder, PatherMixin): except NotImplementedError: # Fall back to drawing two L-bends ccw0 = jog > 0 - kwargs_no_out = (kwargs | {'out_ptype': None}) + kwargs_no_out = kwargs | {'out_ptype': None} t_tree0 = tool.path( ccw0, length / 2, port_names=tool_port_names, in_ptype=in_ptype, **kwargs_no_out) t_pat0 = t_tree0.top_pattern() (_, jog0), _ = t_pat0[tool_port_names[0]].measure_travel(t_pat0[tool_port_names[1]]) - t_tree1 = tool.path(not ccw0, jog - jog0, port_names=tool_port_names, in_ptype=t_pat0[tool_port_names[1]].ptype, **kwargs) + t_tree1 = tool.path(not ccw0, abs(jog - jog0), port_names=tool_port_names, in_ptype=t_pat0[tool_port_names[1]].ptype, **kwargs) t_pat1 = t_tree1.top_pattern() (_, jog1), _ = t_pat1[tool_port_names[0]].measure_travel(t_pat1[tool_port_names[1]]) - self.path(portspec, ccw0, length - jog1, **kwargs_no_out) - self.path(portspec, not ccw0, jog - jog0, **kwargs) + kwargs_plug = kwargs | {'plug_into': plug_into} + self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out) + self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug) return self tname = self.library << tree diff --git a/masque/builder/pather_mixin.py b/masque/builder/pather_mixin.py index bcf9d5e..6acd7c6 100644 --- a/masque/builder/pather_mixin.py +++ b/masque/builder/pather_mixin.py @@ -321,7 +321,7 @@ class PatherMixin(PortList, metaclass=ABCMeta): else: # S-bend, delegate to implementations (travel, jog), _ = port_src.measure_travel(port_dst) - self.pathS(portspec_src, -travel, jog, **dst_args) + self.pathS(portspec_src, -travel, -jog, **dst_args) elif numpy.isclose(angle, 0): raise BuildError('Don\'t know how to route a U-bend yet (TODO)!') else: diff --git a/masque/builder/renderpather.py b/masque/builder/renderpather.py index 747a098..303a59d 100644 --- a/masque/builder/renderpather.py +++ b/masque/builder/renderpather.py @@ -488,12 +488,13 @@ class RenderPather(PatherMixin): ccw0 = jog > 0 kwargs_no_out = (kwargs | {'out_ptype': None}) t_port0, _ = tool.planL( ccw0, length / 2, in_ptype=in_ptype, **kwargs_no_out) - (_, jog0), _ = Port((0, 0), 0).measure_travel(t_port0) - t_port1, _ = tool.planL(not ccw0, jog - jog0, in_ptype=t_port0.ptype, **kwargs) - (_, jog1), _ = Port((0, 0), 0).measure_travel(t_port1) + jog0 = Port((0, 0), 0).measure_travel(t_port0)[0][1] + t_port1, _ = tool.planL(not ccw0, abs(jog - jog0), in_ptype=t_port0.ptype, **kwargs) + jog1 = Port((0, 0), 0).measure_travel(t_port1)[0][1] - self.path(portspec, ccw0, length - jog1, **kwargs_no_out) - self.path(portspec, not ccw0, jog - jog0, **kwargs) + kwargs_plug = kwargs | {'plug_into': plug_into} + self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out) + self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug) return self out_port.rotate_around((0, 0), pi + port_rot) From 22b53a930ce63efd145b561bb3d781cdd7cd2551 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 20 Nov 2025 13:01:51 -0800 Subject: [PATCH 3/3] [AutoTool] S-bend to L-bend fallback does not work yet, should throw an error --- masque/builder/tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/masque/builder/tools.py b/masque/builder/tools.py index 9c27a41..6bd7547 100644 --- a/masque/builder/tools.py +++ b/masque/builder/tools.py @@ -768,6 +768,7 @@ class AutoTool(Tool, metaclass=ABCMeta): l2_err: BuildError | None = err else: l2_err = None + raise NotImplementedError('TODO need to handle ldata below') if not success: # Failed to break