plugins/routers/joint.routers.manhattan.js
function router(vertices, opt, linkView) {

        resolveOptions(opt);

        // enable/disable linkView perpendicular option
        linkView.options.perpendicular = !!opt.perpendicular;

        var sourceBBox = getSourceBBox(linkView, opt);
        var targetBBox = getTargetBBox(linkView, opt);

        var sourceAnchor = getSourceAnchor(linkView, opt);
        //var targetAnchor = getTargetAnchor(linkView, opt);

        // pathfinding
        var map = (new ObstacleMap(opt)).build(linkView.paper.model, linkView.model);
        var oldVertices = util.toArray(vertices).map(g.Point);
        var newVertices = [];
        var tailPoint = sourceAnchor; // the origin of first route's grid, does not need snapping

        // find a route by concatenating all partial routes (routes need to pass through vertices)
        // source -> vertex[1] -> ... -> vertex[n] -> target
        var to, from;

        for (var i = 0, len = oldVertices.length; i <= len; i++) {

            var partialRoute = null;

            from = to || sourceBBox;
            to = oldVertices[i];

            if (!to) {
                // this is the last iteration
                // we ran through all vertices in oldVertices
                // 'to' is not a vertex.

                to = targetBBox;

                // If the target is a point (i.e. it's not an element), we
                // should use dragging route instead of main routing method if it has been provided.
                var isEndingAtPoint = !linkView.model.get('source').id || !linkView.model.get('target').id;

                if (isEndingAtPoint && util.isFunction(opt.draggingRoute)) {
                    // Make sure we are passing points only (not rects).
                    var dragFrom = (from === sourceBBox) ? sourceAnchor : from;
                    var dragTo = to.origin();

                    partialRoute = opt.draggingRoute.call(linkView, dragFrom, dragTo, opt);
                }
            }

            // if partial route has not been calculated yet use the main routing method to find one
            partialRoute = partialRoute || findRoute.call(linkView, from, to, map, opt);

            if (partialRoute === null) { // the partial route cannot be found
                return opt.fallbackRouter(vertices, opt, linkView);
            }

            var leadPoint = partialRoute[0];

            // remove the first point if the previous partial route had the same point as last
            if (leadPoint && leadPoint.equals(tailPoint)) partialRoute.shift();

            // save tailPoint for next iteration
            tailPoint = partialRoute[partialRoute.length - 1] || tailPoint;

            Array.prototype.push.apply(newVertices, partialRoute);
        }

        return newVertices;
    }
function router(vertices, opt, linkView) {

        resolveOptions(opt);

        // enable/disable linkView perpendicular option
        linkView.options.perpendicular = !!opt.perpendicular;

        var sourceBBox = getSourceBBox(linkView, opt);
        var targetBBox = getTargetBBox(linkView, opt);

        var sourceAnchor = getSourceAnchor(linkView, opt);
        //var targetAnchor = getTargetAnchor(linkView, opt);

        // pathfinding
        var map = (new ObstacleMap(opt)).build(linkView.paper.model, linkView.model);
        var oldVertices = util.toArray(vertices).map(g.Point);
        var newVertices = [];
        var tailPoint = sourceAnchor; // the origin of first route's grid, does not need snapping

        // find a route by concatenating all partial routes (routes need to pass through vertices)
        // source -> vertex[1] -> ... -> vertex[n] -> target
        var to, from;

        for (var i = 0, len = oldVertices.length; i <= len; i++) {

            var partialRoute = null;

            from = to || sourceBBox;
            to = oldVertices[i];

            if (!to) {
                // this is the last iteration
                // we ran through all vertices in oldVertices
                // 'to' is not a vertex.

                to = targetBBox;

                // If the target is a point (i.e. it's not an element), we
                // should use dragging route instead of main routing method if it has been provided.
                var isEndingAtPoint = !linkView.model.get('source').id || !linkView.model.get('target').id;

                if (isEndingAtPoint && util.isFunction(opt.draggingRoute)) {
                    // Make sure we are passing points only (not rects).
                    var dragFrom = (from === sourceBBox) ? sourceAnchor : from;
                    var dragTo = to.origin();

                    partialRoute = opt.draggingRoute.call(linkView, dragFrom, dragTo, opt);
                }
            }

            // if partial route has not been calculated yet use the main routing method to find one
            partialRoute = partialRoute || findRoute.call(linkView, from, to, map, opt);

            if (partialRoute === null) { // the partial route cannot be found
                return opt.fallbackRouter(vertices, opt, linkView);
            }

            var leadPoint = partialRoute[0];

            // remove the first point if the previous partial route had the same point as last
            if (leadPoint && leadPoint.equals(tailPoint)) partialRoute.shift();

            // save tailPoint for next iteration
            tailPoint = partialRoute[partialRoute.length - 1] || tailPoint;

            Array.prototype.push.apply(newVertices, partialRoute);
        }

        return newVertices;
    }
function router ( vertices , opt , linkView ) { resolveOptions ( opt ) ; // enable/disable linkView perpendicular option linkView . options . perpendicular = ! ! opt . perpendicular ; var sourceBBox = getSourceBBox ( linkView , opt ) ; var targetBBox = getTargetBBox ( linkView , opt ) ; var sourceAnchor = getSourceAnchor ( linkView , opt ) ; //var targetAnchor = getTargetAnchor(linkView, opt); // pathfinding var map = ( new ObstacleMap ( opt ) ) . build ( linkView . paper . model , linkView . model ) ; var oldVertices = util . toArray ( vertices ) . map ( g . Point ) ; var newVertices = [ ] ; var tailPoint = sourceAnchor ; // the origin of first route's grid, does not need snapping // find a route by concatenating all partial routes (routes need to pass through vertices) // source -> vertex[1] -> ... -> vertex[n] -> target var to , from ; for ( var i = 0 , len = oldVertices . length ; i <= len ; i ++ ) { var partialRoute = null ; from = to || sourceBBox ; to = oldVertices [ i ] ; if ( ! to ) { // this is the last iteration // we ran through all vertices in oldVertices // 'to' is not a vertex. to = targetBBox ; // If the target is a point (i.e. it's not an element), we // should use dragging route instead of main routing method if it has been provided. var isEndingAtPoint = ! linkView . model . get ( 'source' ) . id || ! linkView . model . get ( 'target' ) . id ; if ( isEndingAtPoint && util . isFunction ( opt . draggingRoute ) ) { // Make sure we are passing points only (not rects). var dragFrom = ( from === sourceBBox ) ? sourceAnchor : from ; var dragTo = to . origin ( ) ; partialRoute = opt . draggingRoute . call ( linkView , dragFrom , dragTo , opt ) ; } } // if partial route has not been calculated yet use the main routing method to find one partialRoute = partialRoute || findRoute . call ( linkView , from , to , map , opt ) ; if ( partialRoute === null ) { // the partial route cannot be found return opt . fallbackRouter ( vertices , opt , linkView ) ; } var leadPoint = partialRoute [ 0 ] ; // remove the first point if the previous partial route had the same point as last if ( leadPoint && leadPoint . equals ( tailPoint ) ) partialRoute . shift ( ) ; // save tailPoint for next iteration tailPoint = partialRoute [ partialRoute . length - 1 ] || tailPoint ; Array . prototype . push . apply ( newVertices , partialRoute ) ; } return newVertices ; }
initialization of the route finding
initialization of the route finding