ManhattanConnectionRouter.js
Summary
No overview generated for 'ManhattanConnectionRouter.js'
draw2d.ManhattanConnectionRouter=function()
{
this.MINDIST = 20;
}
draw2d.ManhattanConnectionRouter.prototype = new draw2d.ConnectionRouter;
draw2d.ManhattanConnectionRouter.prototype.type="ManhattanConnectionRouter";
draw2d.ManhattanConnectionRouter.prototype.route=function( conn)
{
var fromPt = conn.getStartPoint();
var fromDir = this.getStartDirection(conn);
var toPt = conn.getEndPoint();
var toDir = this.getEndDirection(conn);
this._route(conn,toPt, toDir, fromPt, fromDir);
}
draw2d.ManhattanConnectionRouter.prototype._route=function( conn, fromPt, fromDir, toPt, toDir)
{
var TOL = 0.1;
var TOLxTOL = 0.01;
var UP = 0;
var RIGHT= 1;
var DOWN = 2;
var LEFT = 3;
var xDiff = fromPt.x - toPt.x;
var yDiff = fromPt.y - toPt.y;
var point;
var dir;
if (((xDiff * xDiff) < (TOLxTOL)) && ((yDiff * yDiff) < (TOLxTOL)))
{
conn.addPoint(new draw2d.Point(toPt.x, toPt.y));
return;
}
if (fromDir == LEFT)
{
if ((xDiff > 0) && ((yDiff * yDiff) < TOL) && (toDir == RIGHT))
{
point = toPt;
dir = toDir;
}
else
{
if (xDiff < 0)
{
point = new draw2d.Point(fromPt.x - this.MINDIST, fromPt.y);
}
else if (((yDiff > 0) && (toDir == DOWN)) || ((yDiff < 0) && (toDir == UP)))
{
point = new draw2d.Point(toPt.x, fromPt.y);
}
else if (fromDir == toDir)
{
var pos = Math.min(fromPt.x, toPt.x) - this.MINDIST;
point = new draw2d.Point(pos, fromPt.y);
}
else
{
point = new draw2d.Point(fromPt.x - (xDiff / 2), fromPt.y);
}
if (yDiff > 0)
{
dir = UP;
}
else
{
dir = DOWN;
}
}
}
else if (fromDir == RIGHT)
{
if ((xDiff < 0) && ((yDiff * yDiff) < TOL)&& (toDir == LEFT))
{
point = toPt;
dir = toDir;
}
else
{
if (xDiff > 0)
{
point = new draw2d.Point(fromPt.x + this.MINDIST, fromPt.y);
}
else if (((yDiff > 0) && (toDir == DOWN)) || ((yDiff < 0) && (toDir == UP)))
{
point = new draw2d.Point(toPt.x, fromPt.y);
}
else if (fromDir == toDir)
{
var pos = Math.max(fromPt.x, toPt.x) + this.MINDIST;
point = new draw2d.Point(pos, fromPt.y);
}
else
{
point = new draw2d.Point(fromPt.x - (xDiff / 2), fromPt.y);
}
if (yDiff > 0)
dir = UP;
else
dir = DOWN;
}
}
else if (fromDir == DOWN)
{
if (((xDiff * xDiff) < TOL) && (yDiff < 0)&& (toDir == UP))
{
point = toPt;
dir = toDir;
}
else
{
if (yDiff > 0)
{
point = new draw2d.Point(fromPt.x, fromPt.y + this.MINDIST);
}
else if (((xDiff > 0) && (toDir == RIGHT)) || ((xDiff < 0) && (toDir == LEFT)))
{
point = new draw2d.Point(fromPt.x, toPt.y);
}
else if (fromDir == toDir)
{
var pos = Math.max(fromPt.y, toPt.y) + this.MINDIST;
point = new draw2d.Point(fromPt.x, pos);
}
else
{
point = new draw2d.Point(fromPt.x, fromPt.y - (yDiff / 2));
}
if (xDiff > 0)
dir = LEFT;
else
dir = RIGHT;
}
}
else if (fromDir == UP)
{
if (((xDiff * xDiff) < TOL) && (yDiff > 0) && (toDir == DOWN))
{
point = toPt;
dir = toDir;
}
else
{
if (yDiff < 0)
{
point = new draw2d.Point(fromPt.x, fromPt.y - this.MINDIST);
}
else if (((xDiff > 0) && (toDir == RIGHT)) || ((xDiff < 0) && (toDir == LEFT)))
{
point = new draw2d.Point(fromPt.x, toPt.y);
}
else if (fromDir == toDir)
{
var pos = Math.min(fromPt.y, toPt.y) - this.MINDIST;
point = new draw2d.Point(fromPt.x, pos);
}
else
{
point = new draw2d.Point(fromPt.x, fromPt.y - (yDiff / 2));
}
if (xDiff > 0)
dir = LEFT;
else
dir = RIGHT;
}
}
this._route(conn,point, dir, toPt, toDir);
conn.addPoint(fromPt);
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008