double x0 = KetPanel.LEFT_BORDER_SIZE;
double y0 = KetPanel.TOP_BORDER_SIZE;
// BUG? Why isn't RIGHT_BORDER_SIZE and BOTTOM_BORDER_SIZE not used here:
double dx = panelRectangle.width - KetPanel.LEFT_BORDER_SIZE - KetPanel.RIGHT_BORDER_SIZE;
double dy = panelRectangle.height - KetPanel.TOP_BORDER_SIZE - KetPanel.BOTTOM_BORDER_SIZE - panelDecoration.getModeBoxHeight();
Position centre = new Position(x0+dx/2.0, y0+dy/2.0);
EquationList el = getMathCollection().getSelection().getEquationList();
Vector<Map.Entry<Box,Equation>> es = getEs();
if (es==null) return;
Vector<Position> ends = calcEnds(es, el);
Vector<Box> theBoxes = new Vector<Box>();
Vector<Equation> theEquations = new Vector<Equation>();
Vector<Position> thePositions = new Vector<Position>();
for (Map.Entry<Box,Equation> entry : es) {
Box box = entry.getKey();
Equation e = entry.getValue();
if (e==null) {
System.out.print("null");
boxToEquation.remove(box);
continue;
}
if (e.getEquationList()!=el) {
System.out.print("e");
boxToEquation.remove(box);
continue;
}
Position p = equationToPosition.get(e);
if (p==null) {
System.out.print("p");
boxToEquation.remove(box);
continue;
}
theBoxes.add(box);
theEquations.add(e);
thePositions.add(p);
}
for (int loop=0; loop<n; loop++) {
Vector<Position> allPs = new Vector<Position>();
Vector<Position> allQs = new Vector<Position>();
for (int i=0; i<theBoxes.size(); i++) {
Box box = theBoxes.get(i);
Equation e = theEquations.get(i);
Position p = thePositions.get(i);
Offset inner = box.getInnerRectangle();
Position q = shift(p, scale);
double costQ = calcCost(q, centre, ends, dx, dy, inner);
double costP = calcCost(p, centre, ends, dx, dy, inner);
if (costQ <= costP) {
allPs.add(p);
allQs.add(q);
}
}
for (int i=0; i<allPs.size(); i++) {
Position p = allPs.get(i);
Position q = allQs.get(i);
p.x = (1.0*q.x+2.0*p.x) / 3.0;
p.y = (1.0*q.y+2.0*p.y) / 3.0;
}
}
if (true) { //D
for (Map.Entry<Box,Equation> entry : es) {
Box box = entry.getKey();
Equation e = entry.getValue();
if (e==null) continue;
Position p = equationToPosition.get(e);
if (p==null) continue;
Vector<Position> ps = e2ps.get(e);
if (ps==null) {
ps = new Vector<Position>();
e2ps.put(e, ps);
}
ps.add(new Position(p));
if (ps.size()>HISTORY) {
ps.removeElementAt(0);
}
//D System.out.println(e.getEquationIndex() + "\t" + p.x + "\t" + p.y); //D