Skip to content

Commit a2f4b21

Browse files
Handle misalignments on thick elements
1 parent 7d0cca5 commit a2f4b21

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

xplt/line.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def __init__(
269269
`{"regex": {...}}`. For each matching element name, the options are used.
270270
271271
"""
272-
272+
273273
kwargs["_properties"] = defaults(
274274
kwargs.get("_properties"),
275275
X=DataProperty("X", "m"),
@@ -428,6 +428,11 @@ def ang(a):
428428
continue
429429

430430
element = None
431+
rot_s_rad = 0
432+
rot_x_rad = 0
433+
rot_y_rad = 0
434+
shift_y = 0
435+
shift_x = 0
431436
if line is not None:
432437
# Fallback to extract missing properties from line
433438
try:
@@ -440,7 +445,13 @@ def ang(a):
440445
order = effective_order(element)
441446
if not length:
442447
length = get(element, "length", 0)
443-
except (TypeError, KeyError):
448+
449+
rot_s_rad = get(element, "rot_s_rad", 0)
450+
rot_x_rad = get(element, "rot_x_rad", 0)
451+
rot_y_rad = get(element, "rot_y_rad", 0)
452+
shift_y = get(element, "shift_y", 0)
453+
shift_x = get(element, "shift_x", 0)
454+
except (TypeError, KeyError) as e:
444455
pass
445456

446457
if self.ignore is not None:
@@ -475,14 +486,18 @@ def ang(a):
475486
box_style.pop("label") # prevent duplicate legend entries
476487
else:
477488
legend_entries.append(box_style.get("label"))
489+
490+
# get the shift angle of the projection
491+
proj = self.projection[1].lower()
492+
shift_angle = {"x": rot_x_rad, "y": rot_y_rad, "z": rot_s_rad}.get(proj, 0)
478493

479494
# Handle thick elements
480495
if is_thick:
481496
# Find the center of single kick for equivalent thin element
482497
d = length * tanc(arc / 2) / 2
483-
x += d * np.cos(ang(rt))
484-
y += d * np.sin(ang(rt))
485-
498+
x += d * np.cos(ang(rt) + ang(shift_angle)) + shift_x
499+
y += d * np.sin(ang(rt) + ang(shift_angle)) + shift_y
500+
486501
if length > 0 and arc:
487502
# bending elements as wedge
488503
rho = length / arc
@@ -504,14 +519,15 @@ def ang(a):
504519
box = mpl.patches.Wedge(**wedge_kwargs)
505520
else:
506521
# other elements as rect
522+
507523
box = mpl.patches.Rectangle(
508524
**defaults_for(
509525
mpl.patches.Rectangle,
510526
box_style,
511527
xy=(x - width / 2, y - length / 2),
512528
width=width,
513529
height=length,
514-
angle=np.rad2deg(ang(rt - arc / 2)) - 90,
530+
angle=np.rad2deg(ang(rt + shift_angle - arc / 2)) - 90,
515531
rotation_point="center",
516532
alpha=0.5,
517533
zorder=3,

0 commit comments

Comments
 (0)