for (Box b : boxSet) { // Move boxes away from edges.
Equation e = boxToEquation.get(b);
if (e==null) continue;
Position p = equationToPosition.get(e);
if (p==null) continue;
Offset inner = b.getInnerRectangle();
double mx = panelRectangle.width-KetPanel.LEFT_BORDER_SIZE-KetPanel.RIGHT_BORDER_SIZE - inner.width;
double my = panelRectangle.height-KetPanel.TOP_BORDER_SIZE-KetPanel.BOTTOM_BORDER_SIZE - inner.height - panelDecoration.getModeBoxHeight();
//- p.x = bound(p.x, KetPanel.LEFT_BORDER_SIZE, mx);
if (p.x<KetPanel.LEFT_BORDER_SIZE) {
return true;
} else if (p.x>mx) {
return true;
}
//- p.y = bound(p.y, KetPanel.TOP_BORDER_SIZE, my);
if (p.y<KetPanel.TOP_BORDER_SIZE) {
return true;
} else if (p.y>my) {
return true;
}
}
Vector<Box> bs = new Vector<Box>(boxSet);
for (int i=0; i<bs.size(); i++) { // Move boxses apart.
Box bA = bs.get(i);
Equation eA = boxToEquation.get(bA);
if (eA==null) continue;
Position pA = equationToPosition.get(eA);
if (pA==null) continue;
Offset innerA = bA.getInnerRectangle();
for (int j=i+1; j<bs.size(); j++) { // Move boxses apart.
Box bB = bs.get(j);
Equation eB = boxToEquation.get(bB);
if (eB==null) continue;
Position pB = equationToPosition.get(eB);
if (pB==null) continue;
Offset innerB = bB.getInnerRectangle();
Position rA = bA.getPosition(pA);
Position rB = bB.getPosition(pB);
Offset iA = bA.getInnerRectangle();
Offset iB = bB.getInnerRectangle();
// Positive overlap values are errors.
boolean overlap1 = rB.x + iB.width + ADDITIONAL_EQUATION_GAP > rA.x;
boolean overlap2 = rA.x + iA.width + ADDITIONAL_EQUATION_GAP > rB.x;
boolean overlap3 = rB.y + iB.height + ADDITIONAL_EQUATION_GAP > rA.y;