@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 397 B
JavaScript
function h(n,c,e,t,r,y){const s=r-e,i=y-t,a=n-e,l=c-t,f=s*s+i*i;if(f===0)return Math.hypot(n-e,c-t);let o=(a*s+l*i)/f;o<0?o=0:o>1&&(o=1);const u=e+o*s,b=t+o*i;return Math.hypot(n-u,c-b)}export function distancePointToRouteOnLayer(n,c){let e=1/0;for(const t of c){if(n.layer&&(t.p0.layer!==n.layer||t.p1.layer!==n.layer))continue;const r=h(n.x,n.y,t.p0.x,t.p0.y,t.p1.x,t.p1.y);r<e&&(e=r)}return e}