@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 696 B
JavaScript
import{lineAngle as f}from"simple-geometry";import{buildNGraph as h}from"../buildNGraph";import y from"../utils/a-star/a-star";import{parseNodeId as l}from"./parseNodeId";const g=1.01;function x(){return function(n,e,t){let r=1;if(e.parent){const[,a,c]=l(e.parent.node.id),[,o,d]=l(e.node.id),[,s,u]=l(n.id),p=f({x:a,y:c},{x:o,y:d}),m=f({x:o,y:d},{x:s,y:u});p!==m&&(r=g)}return r*t.data.distance}}export function createAStarPathFinder(){let i=null,n=null;return{build(e,t){n=h(e,t),i=y(n,{oriented:t.oriented,distance:x()})},hasNode(e){return n?!!n.hasNode(e):!1},find(e,t){if(!i)return[];const r=i.find(e,t);return r.length?r.map(a=>{const[c,o,d]=l(a.id);return{id:a.id,layer:c,x:o,y:d}}):[]}}}