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