MCPcopy Create free account
hub / github.com/google-deepmind/alphageometry / naming_position

Function naming_position

numericals.py:890–922  ·  view source on GitHub ↗

Figure out a good naming position on the drawing.

(
    ax: matplotlib.axes.Axes, p: Point, lines: list[Line], circles: list[Circle]
)

Source from the content-addressed store, hash-verified

888
889
890def 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
925def draw_point(

Callers 1

draw_pointFunction · 0.85

Calls 7

circle_segment_intersectFunction · 0.85
ang_ofFunction · 0.85
extendMethod · 0.80
cosMethod · 0.80
CircleClass · 0.70
PointClass · 0.70

Tested by

no test coverage detected