MCPcopy
hub / github.com/clientIO/joint / findRoute

Function findRoute

packages/joint-core/src/routers/manhattan.mjs:560–743  ·  view source on GitHub ↗
(from, to, isPointObstacle, opt)

Source from the content-addressed store, hash-verified

558// finds the route between two points/rectangles (`from`, `to`) implementing A* algorithm
559// rectangles get rect points assigned by getRectPoints()
560function findRoute(from, to, isPointObstacle, opt) {
561
562 var precision = opt.precision;
563
564 // Get grid for this route.
565
566 var sourceAnchor, targetAnchor;
567
568 if (from instanceof g.Rect) { // `from` is sourceBBox
569 sourceAnchor = round(getSourceAnchor(this, opt).clone(), precision);
570 } else {
571 sourceAnchor = round(from.clone(), precision);
572 }
573
574 if (to instanceof g.Rect) { // `to` is targetBBox
575 targetAnchor = round(getTargetAnchor(this, opt).clone(), precision);
576 } else {
577 targetAnchor = round(to.clone(), precision);
578 }
579
580 var grid = getGrid(opt.step, sourceAnchor, targetAnchor);
581
582 // Get pathfinding points.
583
584 var start, end; // aligned with grid by definition
585 var startPoints, endPoints; // assumed to be aligned with grid already
586
587 // set of points we start pathfinding from
588 if (from instanceof g.Rect) { // `from` is sourceBBox
589 start = sourceAnchor;
590 startPoints = getRectPoints(start, from, opt.startDirections, grid, opt);
591
592 } else {
593 start = sourceAnchor;
594 startPoints = [start];
595 }
596
597 // set of points we want the pathfinding to finish at
598 if (to instanceof g.Rect) { // `to` is targetBBox
599 end = targetAnchor;
600 endPoints = getRectPoints(targetAnchor, to, opt.endDirections, grid, opt);
601
602 } else {
603 end = targetAnchor;
604 endPoints = [end];
605 }
606
607 // take into account only accessible rect points (those not under obstacles)
608 startPoints = startPoints.filter(p => !isPointObstacle(p));
609 endPoints = endPoints.filter(p => !isPointObstacle(p));
610
611 // Check that there is an accessible route point on both sides.
612 // Otherwise, use fallbackRoute().
613 if (startPoints.length > 0 && endPoints.length > 0) {
614
615 // The set of tentative points to be evaluated, initially containing the start points.
616 // Rounded to nearest integer for simplicity.
617 var openSet = new SortedSet();

Callers

nothing calls this directly

Calls 15

roundFunction · 0.85
getGridFunction · 0.85
getRectPointsFunction · 0.85
getKeyFunction · 0.85
estimateCostFunction · 0.85
getGridOffsetsFunction · 0.85
getDirectionAngleFunction · 0.85
reconstructRouteFunction · 0.85
getDirectionChangeFunction · 0.85
alignFunction · 0.85
cloneMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected