An illustration annotation algorithm or why not a programmer be a little designer?
I want to bring to your attention one curious problem and several ways to solve it. Initially, the task appeared on stackoverflow, but before moving on to the point I want to emphasize the absence of any desire to impose my point of view.
So, the task: there is a series of images and a set of explanatory labels for each image, it is necessary to place the labels in the optimal way, avoiding the intersection of connecting lines and maintaining general readability.

Obviously, the task is not trivial. Moreover, I would say that any direct solution cannot guarantee the optimality of the result. In other words, a person (for which, in fact, we are trying to) will definitely notice some oddities of placing explanatory labels. In some particularly difficult cases, the result may even seem disgusting.

I will try to briefly formulate important, in my opinion, criteria:
So, at this stage, you can choose from the following:
The first way: we will find a suitable algorithm. The
options, in fact, are quite enough: iterative methods, something similar to PCB layout, genetic algorithm, etc. Regarding the layout of printed circuit boards, the following document is of interest: Algorithmic studies on PCB routing by Tan Yan

I think everyone will have their own assessment of the reliability of one of these approaches, the resource-intensive implementation, testing and making the necessary changes to correctly work out possible boundary situations.
The second way: we will try to work with the style
In other words, let's move on to the meta level, which can significantly improve the result, while simplifying implementation. Ideal option - labels and explanations remain accessible, but are not perceived as the main component of the illustration, while maintaining the maximum information provided by the main image.
This begs a solution that will ensure the shortest footnotes and their uniformity. Thus, a person who knows how to distinguish and filter out unwanted patterns quickly learns not to notice minor details. In addition, the transition from inclined lines to horizontal looks quite logical (remember anti-aliasing and additional loss of details). One possible solution is as follows:

In this case, the label placement algorithm becomes much simpler, and the result is predictable. As you can see, the style of placement of explanations will be similar even for very different images, which, I dare to assume, will have a positive effect on the impression of viewing many dozens of “annotated” illustrations.
I hope this material was interesting. I will formulate the final question as follows:
Should a programmer always remain a programmer?
Everyone decides for himself. Interesting and useful thoughts, as usual, are welcome in the comments.
The original question on stackoverflow
So, the task: there is a series of images and a set of explanatory labels for each image, it is necessary to place the labels in the optimal way, avoiding the intersection of connecting lines and maintaining general readability.

Obviously, the task is not trivial. Moreover, I would say that any direct solution cannot guarantee the optimality of the result. In other words, a person (for which, in fact, we are trying to) will definitely notice some oddities of placing explanatory labels. In some particularly difficult cases, the result may even seem disgusting.

I will try to briefly formulate important, in my opinion, criteria:
- overall cleanliness and readability
- the lack of “divert attention”, since the priority is the main image, and not labels, which play an important, but nonetheless secondary role
- ease of posting
- stable quality of the result
So, at this stage, you can choose from the following:
- try to find a suitable algorithm
- change the style, solving the problem at a different level
The first way: we will find a suitable algorithm. The
options, in fact, are quite enough: iterative methods, something similar to PCB layout, genetic algorithm, etc. Regarding the layout of printed circuit boards, the following document is of interest: Algorithmic studies on PCB routing by Tan Yan

I think everyone will have their own assessment of the reliability of one of these approaches, the resource-intensive implementation, testing and making the necessary changes to correctly work out possible boundary situations.
The second way: we will try to work with the style
In other words, let's move on to the meta level, which can significantly improve the result, while simplifying implementation. Ideal option - labels and explanations remain accessible, but are not perceived as the main component of the illustration, while maintaining the maximum information provided by the main image.
This begs a solution that will ensure the shortest footnotes and their uniformity. Thus, a person who knows how to distinguish and filter out unwanted patterns quickly learns not to notice minor details. In addition, the transition from inclined lines to horizontal looks quite logical (remember anti-aliasing and additional loss of details). One possible solution is as follows:

In this case, the label placement algorithm becomes much simpler, and the result is predictable. As you can see, the style of placement of explanations will be similar even for very different images, which, I dare to assume, will have a positive effect on the impression of viewing many dozens of “annotated” illustrations.
I hope this material was interesting. I will formulate the final question as follows:
Should a programmer always remain a programmer?
Everyone decides for himself. Interesting and useful thoughts, as usual, are welcome in the comments.
The original question on stackoverflow