215 std::vector<cFigure::Rectangle> rcs;
216 std::vector<cFigure::Point> pts;
222 rcs.push_back(extendendSubmoduleBounds);
223 pts.push_back(getTopLeft(extendendSubmoduleBounds));
224 pts.push_back(getTopCenter(extendendSubmoduleBounds));
225 pts.push_back(getTopRight(extendendSubmoduleBounds));
226 pts.push_back(getCenterLeft(extendendSubmoduleBounds));
227 pts.push_back(getCenterCenter(extendendSubmoduleBounds));
228 pts.push_back(getCenterRight(extendendSubmoduleBounds));
229 pts.push_back(getBottomLeft(extendendSubmoduleBounds));
230 pts.push_back(getBottomCenter(extendendSubmoduleBounds));
231 pts.push_back(getBottomRight(extendendSubmoduleBounds));
237 auto& annotation = *it;
238 annotation.bounds.x =
NaN;
239 annotation.bounds.y =
NaN;
243 auto& annotation = *it;
244 if (!annotation.figure->isVisible())
249 double bestDistance = std::numeric_limits<double>::infinity();
250 cFigure::Rectangle bestRc;
253 for (
auto pt : pts) {
255 for (
int k = 0;
k < 9;
k++) {
256 cFigure::Rectangle candidateRc;
260 candidateRc = createRectangle(pt - cFigure::Point(0, 0), rs);
264 candidateRc = createRectangle(pt - cFigure::Point(rs.x / 2, 0), rs);
268 candidateRc = createRectangle(pt - cFigure::Point(rs.x, 0), rs);
272 candidateRc = createRectangle(pt - cFigure::Point(0, rs.y / 2), rs);
276 candidateRc = createRectangle(pt - cFigure::Point(rs.x / 2, rs.y / 2), rs);
280 candidateRc = createRectangle(pt - cFigure::Point(rs.x, rs.y / 2), rs);
284 candidateRc = createRectangle(pt - cFigure::Point(0, rs.y), rs);
288 candidateRc = createRectangle(pt - cFigure::Point(rs.x / 2, rs.y), rs);
292 candidateRc = createRectangle(pt - cFigure::Point(rs.x, rs.y), rs);
295 throw cRuntimeError(
"Invalid case");
306 bool intersects =
false;
307 for (
const auto& rc : rcs) {
308 if (intersectsRectangle(candidateRc, rc)) {
318 distance += getCenterCenter(
submoduleBounds).distanceTo(getCenterCenter(candidateRc));
319 if (distance < bestDistance) {
320 bestRc = candidateRc;
321 bestDistance = distance;
332 annotation.figure->setTransform(cFigure::Transform().translate(annotation.bounds.x, annotation.bounds.y));
335 for (
auto j = pts.begin(); j != pts.end();) {
336 if (containsPoint(bestRc, *j))
343 pushUnlessContains(pts, rcs, getTopLeft(bestRc));
344 pushUnlessContains(pts, rcs, getTopCenter(bestRc));
345 pushUnlessContains(pts, rcs, getTopRight(bestRc));
346 pushUnlessContains(pts, rcs, getCenterLeft(bestRc));
347 pushUnlessContains(pts, rcs, getCenterCenter(bestRc));
348 pushUnlessContains(pts, rcs, getCenterRight(bestRc));
349 pushUnlessContains(pts, rcs, getBottomLeft(bestRc));
350 pushUnlessContains(pts, rcs, getBottomCenter(bestRc));
351 pushUnlessContains(pts, rcs, getBottomRight(bestRc));
353 rcs.push_back(bestRc);