Skip to content

Commit 82f4688

Browse files
committed
Fix: Add angle display to AnnotatedSegment and fix angle for AnnotatedObliqueRectangle and AnnotatedEllipse
1 parent ccffb72 commit 82f4688

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

doc/release_notes/release_2.08.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
## PlotPy Version 2.8.3 ##
44

5+
💥 New features:
6+
7+
* `AnnotatedSegment` new angle display:
8+
* Added angle display in annotation label, showing the segment's angle relative to the horizontal direction (0° to 180°)
9+
* This implements the equivalent feature submitted in [Pull Request #51](https://github.com/PlotPyStack/PlotPy/pull/51) by user @deuterium33
10+
511
🛠️ Bug fixes:
612

713
* Fixed circle/ellipse shape drawing with non-uniform aspect ratios:
814
* Axes were not perpendicular and did not connect to the ellipse edge when plot aspect ratio differed from 1.0
915
* Now uses parametric ellipse drawing that correctly handles non-perpendicular axes in pixel space
1016
* The ellipse properly passes through all four handle points regardless of aspect ratio or rotation
17+
* Fixed angle display range for `AnnotatedObliqueRectangle` and `AnnotatedEllipse`:
18+
* Angle is now displayed in the 0° to 180° range instead of -90° to 90° (the original implementation was also displaying 0° at vertical orientation -additionally to horizontal orientation- which was counter-intuitive)
19+
* This provides a more intuitive and consistent angle representation
1120

1221
## PlotPy Version 2.8.2 (2025-11-10) ##
1322

plotpy/items/annotation.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ def get_tr_center(self):
599599
"""Return segment position (middle) after applying transform matrix"""
600600
return compute_center(*self.get_transformed_coords(0, 1))
601601

602+
def get_tr_angle(self):
603+
"""Return segment angle with horizontal direction (0° to 180°),
604+
after applying transform matrix"""
605+
xcoords = self.get_transformed_coords(0, 1)
606+
_x, yr1 = self.apply_transform_matrix(1.0, 1.0)
607+
_x, yr2 = self.apply_transform_matrix(1.0, 2.0)
608+
return (compute_angle(*xcoords, reverse=yr1 > yr2) + 180) % 180
609+
602610
# ----AnnotatedShape API-----------------------------------------------------
603611
def set_label_position(self):
604612
"""Set label position, for instance based on shape position"""
@@ -616,6 +624,7 @@ def get_info(self) -> str:
616624
[
617625
_("Center:") + " " + self.get_tr_center_str(),
618626
_("Distance:") + " " + self.x_to_str(self.get_tr_length()),
627+
_("Angle:") + f" {self.get_tr_angle():.1f}°",
619628
]
620629
)
621630

@@ -1108,12 +1117,12 @@ def __init__(
11081117

11091118
# ----Public API-------------------------------------------------------------
11101119
def get_tr_angle(self):
1111-
"""Return X-diameter angle with horizontal direction,
1120+
"""Return X-diameter angle with horizontal direction (0° to 180°),
11121121
after applying transform matrix"""
11131122
xcoords = self.get_transformed_coords(0, 1)
11141123
_x, yr1 = self.apply_transform_matrix(1.0, 1.0)
11151124
_x, yr2 = self.apply_transform_matrix(1.0, 2.0)
1116-
return (compute_angle(*xcoords, reverse=yr1 > yr2) + 90) % 180 - 90
1125+
return (compute_angle(*xcoords, reverse=yr1 > yr2) + 180) % 180
11171126

11181127
def get_bounding_rect_coords(self) -> tuple[float, float, float, float]:
11191128
"""Return bounding rectangle coordinates (in plot coordinates)
@@ -1260,12 +1269,12 @@ def set_rect(self, x0, y0, x1, y1):
12601269
raise NotImplementedError
12611270

12621271
def get_tr_angle(self):
1263-
"""Return X-diameter angle with horizontal direction,
1272+
"""Return X-diameter angle with horizontal direction (0° to 180°),
12641273
after applying transform matrix"""
12651274
xcoords = self.get_transformed_coords(0, 1)
12661275
_x, yr1 = self.apply_transform_matrix(1.0, 1.0)
12671276
_x, yr2 = self.apply_transform_matrix(1.0, 2.0)
1268-
return (compute_angle(*xcoords, reverse=yr1 > yr2) + 90) % 180 - 90
1277+
return (compute_angle(*xcoords, reverse=yr1 > yr2) + 180) % 180
12691278

12701279
# ----AnnotatedShape API-----------------------------------------------------
12711280
def set_label_position(self):

0 commit comments

Comments
 (0)