From a2f4b21e5556e5ae607e3aa15469b678c41483fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Le=20Garrec?= Date: Fri, 17 Oct 2025 11:08:18 +0200 Subject: [PATCH 1/2] Handle misalignments on thick elements --- xplt/line.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/xplt/line.py b/xplt/line.py index 42f30d9..7b65ffe 100644 --- a/xplt/line.py +++ b/xplt/line.py @@ -269,7 +269,7 @@ def __init__( `{"regex": {...}}`. For each matching element name, the options are used. """ - + kwargs["_properties"] = defaults( kwargs.get("_properties"), X=DataProperty("X", "m"), @@ -428,6 +428,11 @@ def ang(a): continue element = None + rot_s_rad = 0 + rot_x_rad = 0 + rot_y_rad = 0 + shift_y = 0 + shift_x = 0 if line is not None: # Fallback to extract missing properties from line try: @@ -440,7 +445,13 @@ def ang(a): order = effective_order(element) if not length: length = get(element, "length", 0) - except (TypeError, KeyError): + + rot_s_rad = get(element, "rot_s_rad", 0) + rot_x_rad = get(element, "rot_x_rad", 0) + rot_y_rad = get(element, "rot_y_rad", 0) + shift_y = get(element, "shift_y", 0) + shift_x = get(element, "shift_x", 0) + except (TypeError, KeyError) as e: pass if self.ignore is not None: @@ -475,14 +486,18 @@ def ang(a): box_style.pop("label") # prevent duplicate legend entries else: legend_entries.append(box_style.get("label")) + + # get the shift angle of the projection + proj = self.projection[1].lower() + shift_angle = {"x": rot_x_rad, "y": rot_y_rad, "z": rot_s_rad}.get(proj, 0) # Handle thick elements if is_thick: # Find the center of single kick for equivalent thin element d = length * tanc(arc / 2) / 2 - x += d * np.cos(ang(rt)) - y += d * np.sin(ang(rt)) - + x += d * np.cos(ang(rt) + ang(shift_angle)) + shift_x + y += d * np.sin(ang(rt) + ang(shift_angle)) + shift_y + if length > 0 and arc: # bending elements as wedge rho = length / arc @@ -504,6 +519,7 @@ def ang(a): box = mpl.patches.Wedge(**wedge_kwargs) else: # other elements as rect + box = mpl.patches.Rectangle( **defaults_for( mpl.patches.Rectangle, @@ -511,7 +527,7 @@ def ang(a): xy=(x - width / 2, y - length / 2), width=width, height=length, - angle=np.rad2deg(ang(rt - arc / 2)) - 90, + angle=np.rad2deg(ang(rt + shift_angle - arc / 2)) - 90, rotation_point="center", alpha=0.5, zorder=3, From 941b3651262a42718a45d5b0368d7df66776e458 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Oct 2025 09:46:06 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xplt/line.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xplt/line.py b/xplt/line.py index 7b65ffe..de12c62 100644 --- a/xplt/line.py +++ b/xplt/line.py @@ -269,7 +269,7 @@ def __init__( `{"regex": {...}}`. For each matching element name, the options are used. """ - + kwargs["_properties"] = defaults( kwargs.get("_properties"), X=DataProperty("X", "m"), @@ -445,7 +445,7 @@ def ang(a): order = effective_order(element) if not length: length = get(element, "length", 0) - + rot_s_rad = get(element, "rot_s_rad", 0) rot_x_rad = get(element, "rot_x_rad", 0) rot_y_rad = get(element, "rot_y_rad", 0) @@ -486,7 +486,7 @@ def ang(a): box_style.pop("label") # prevent duplicate legend entries else: legend_entries.append(box_style.get("label")) - + # get the shift angle of the projection proj = self.projection[1].lower() shift_angle = {"x": rot_x_rad, "y": rot_y_rad, "z": rot_s_rad}.get(proj, 0) @@ -497,7 +497,7 @@ def ang(a): d = length * tanc(arc / 2) / 2 x += d * np.cos(ang(rt) + ang(shift_angle)) + shift_x y += d * np.sin(ang(rt) + ang(shift_angle)) + shift_y - + if length > 0 and arc: # bending elements as wedge rho = length / arc