I made an example, which I attached.
It turned out to be quite complicated, but in general, the problem is solved.
Two things confuse me:
- slightly different mBase sizes (see logs),
- the drawn lines go slightly beyond the mBase sizes.
Perhaps it was necessary to take into account the thickness of the lines.