Figure out a good naming position on the drawing.
(
ax: matplotlib.axes.Axes, p: Point, lines: list[Line], circles: list[Circle]
)
| 888 | |
| 889 | |
| 890 | def naming_position( |
| 891 | ax: matplotlib.axes.Axes, p: Point, lines: list[Line], circles: list[Circle] |
| 892 | ) -> tuple[float, float]: |
| 893 | """Figure out a good naming position on the drawing.""" |
| 894 | _ = ax |
| 895 | r = 0.08 |
| 896 | c = Circle(center=p, radius=r) |
| 897 | avoid = [] |
| 898 | for p1, p2 in lines: |
| 899 | try: |
| 900 | avoid.extend(circle_segment_intersect(c, p1, p2)) |
| 901 | except InvalidQuadSolveError: |
| 902 | continue |
| 903 | for x in circles: |
| 904 | try: |
| 905 | avoid.extend(circle_circle_intersection(c, x)) |
| 906 | except InvalidQuadSolveError: |
| 907 | continue |
| 908 | |
| 909 | if not avoid: |
| 910 | return [p.x + 0.01, p.y + 0.01] |
| 911 | |
| 912 | angs = sorted([ang_of(p, a) for a in avoid]) |
| 913 | angs += [angs[0] + 2 * np.pi] |
| 914 | angs = [(angs[i + 1] - a, a) for i, a in enumerate(angs[:-1])] |
| 915 | |
| 916 | d, a = max(angs) |
| 917 | ang = a + d / 2 |
| 918 | |
| 919 | name_pos = p + Point(np.cos(ang), np.sin(ang)) * r |
| 920 | |
| 921 | x, y = (name_pos.x - r / 1.5, name_pos.y - r / 1.5) |
| 922 | return x, y |
| 923 | |
| 924 | |
| 925 | def draw_point( |
no test coverage detected