UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 848 B
import{getRouteLength as p}from"../routing/getRouteLength";import{buildRouteSegments as P,findLineByEndpoints as b,toNodeId as m}from"./graphHelpers";import{linkCost as x}from"./linkCost";function y(t,o,n){return{layer:t,x:o,y:n}}export function computeWeightedPathCost(t,o){let n=0;for(let e=1;e<t.length;e++){const i=b(o,t[e-1],t[e]);i&&(n+=x(i))}return n}export function findShortestPath(t,o,n){const e=t.dataSource.getLines();let i=null,d=1/0;for(const a of o)for(const g of n){const s=m(a),r=m(g);if(!t.finder.hasNode(s)||!t.finder.hasNode(r)){console.debug(`WF. findShortestPath: node not in graph, skipping pair ${s} \u2192 ${r}`);continue}const u=t.finder.find(s,r);if(!u.length)continue;const l=u.map(c=>y(c.layer,c.x,c.y)),f=P(l,e);if(!f.length)continue;const h=computeWeightedPathCost(l,e);h<d&&(d=h,i={lines:f,distance:p(f)})}return i}