UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 328 B
export function projectPointOnSegment(c,t,x){const e=x.x-t.x,n=x.y-t.y,y=e*e+n*n;if(y===0){const j=Math.hypot(c.x-t.x,c.y-t.y);return{projected:{x:t.x,y:t.y},distance:j,t:0}}const d=((c.x-t.x)*e+(c.y-t.y)*n)/y,o=Math.max(0,Math.min(1,d)),s=t.x+e*o,r=t.y+n*o,h=Math.hypot(c.x-s,c.y-r);return{projected:{x:s,y:r},distance:h,t:o}}