@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 905 B
JavaScript
import{flipAngle as h,getQuarterTurns as f,shouldFlip as y}from"../update-def";export function isInnerInsideOuter(t,o){if(!o)return!1;const n=Math.cos(o.rotation??0),s=Math.sin(o.rotation??0),r=o.size.x/2,c=o.size.y/2;return l(t,t.rotation+Math.PI/2).every(a=>{const i=a.x-o.center.x,u=a.y-o.center.y,e=i*n+u*s,x=u*n-i*s;return Math.abs(e)<=r&&Math.abs(x)<=c})}function l(t,o=t.rotation){const n=t.size.x/2,s=t.size.y/2,r=Math.sin(o),c=Math.cos(o),a=t.center.x,i=t.center.y;return[{x:-n,y:-s},{x:n,y:-s},{x:n,y:s},{x:-n,y:s}].map(e=>({x:a+e.x*c-e.y*r,y:i+e.x*r+e.y*c}))}export function flipImageDef(t,o){const n=t.bounds;return y(o,n.rotation)?(n.rotate(h(n.rotation)-n.rotation,n),!0):!1}export function attachCardinalSnap(t){return t.onRoll=({roll:o})=>rotateImageDef(t,o)?[t]:void 0,t}export function rotateImageDef(t,o){const n=t.bounds,s=f(o,n.rotation);return s===0?!1:(n.rotate(s*Math.PI/2,n),!0)}