Mercurial > projects > dwt2
view org.eclipse.draw2d/src/org/eclipse/draw2d/graph/MinCross.d @ 104:88652073d1c2
More work on icu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 02 May 2009 11:27:24 +0200 |
parents | bc29606a740c |
children |
line wrap: on
line source
/******************************************************************************* * Copyright (c) 2003, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Port to the D programming language: * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module org.eclipse.draw2d.graph.MinCross; import java.lang.all; import org.eclipse.draw2d.graph.RankSorter; import org.eclipse.draw2d.graph.DirectedGraph; import org.eclipse.draw2d.graph.GraphVisitor; import org.eclipse.draw2d.graph.Rank; /** * Sweeps up and down the ranks rearranging them so as to reduce edge crossings. * @author Randy Hudson * @since 2.1.2 */ class MinCross : GraphVisitor { static const int MAX = 45; private DirectedGraph g; private RankSorter sorter; public this() { sorter = new RankSorter(); } /** * @since 3.1 */ public this(RankSorter sorter) { this(); setRankSorter(sorter); } public void setRankSorter(RankSorter sorter) { this.sorter = sorter; } void solve() { Rank rank; for (int loop = 0; loop < MAX; loop++) { for (int row = 1; row < g.ranks.size(); row++) { rank = g.ranks.getRank(row); sorter.sortRankIncoming(g, rank, row, cast(double)loop / MAX); } if (loop is MAX - 1) continue; for (int row = g.ranks.size() - 2; row >= 0; row--) { rank = g.ranks.getRank(row); sorter.sortRankOutgoing(g, rank, row, cast(double)loop / MAX); } } } /** * @see GraphVisitor#visit(org.eclipse.draw2d.graph.DirectedGraph) */ public void visit(DirectedGraph g) { sorter.init(g); this.g = g; solve(); sorter.optimize(g); } }