UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 782 B
import{projectPointOnSegment as l}from"../geometry/projectPointOnSegment";import{findGraphPointsInPolygon as p}from"./graphPointResolvers";export function resolveWaypointCandidates(i,e){if(e.bounds?.length)return{candidates:p(i.dataSource,e.bounds,e.layer),offGraphEntry:null};let a=null,f=1/0;for(const t of i.dataSource.getLines()){if(t.virtual||e.layer&&t.p0.layer!==e.layer||t.p0.x===t.p1.x&&t.p0.y===t.p1.y)continue;const o=l(e,t.p0,t.p1);o.distance<f&&(f=o.distance,a={segment:t,proj:o})}if(!a)return{candidates:[],offGraphEntry:null};const{segment:n,proj:r}=a;return r.t===0?{candidates:[n.p0],offGraphEntry:null}:r.t===1?{candidates:[n.p1],offGraphEntry:null}:{candidates:[n.p0,n.p1],offGraphEntry:{segment:n,projection:{layer:n.p0.layer,x:r.projected.x,y:r.projected.y}}}}