UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 1.28 kB
import{Rect as k}from"@expofp/renderer";import{getBounds as C}from"./canvases";export function updateLinesScale(t,n,o,e=""){let s=!1;return t.forEach((a,i)=>{let c=0;o[i].forEach(({value:h,scaleFactor:u})=>{n<u&&(c=h)}),a.fontSize!==c*n&&(s=!0),a.fontSize=c*n}),s}export function updateTextDefRotation(t,n){const o=t.bounds.size;return t.bounds.rotation+=n,t.bounds.size={x:o.y,y:o.x},t}export function updateRectRotation(t,n){const{size:o,center:e,rotation:s}=t;return new k({x:e.x-o.y/2,y:e.y-o.x/2},{x:e.x+o.y/2,y:e.y+o.x/2},s+n)}export function getRotation(t,n){const o=getAngleDiff(t,n);if(Math.abs(o)>Math.PI/4)return Math.sign(o)*Math.PI/2}export function shouldFlip(t,n){const o=getAngleDiff(t,n),e=Math.PI/2;return Math.abs(o)>e+.1}export function getAngleDiff(t,n,o=!1){const e=Math.PI,s=2*e;return((i,c)=>((i-c+e)%s+s)%s-e)(t,n)}export function flipAngle(t){return(t+Math.PI+Math.PI)%(2*Math.PI)-Math.PI}export function getClampedBoundsCanvas(t,n,o,e){const s=n.width,a=n.height,i=t.size,c=t.center,h=t.rotation,m=i.x/s,M=i.x-o*2,b=(i.y-o*2)*.8,g=0,y=M/s,I=b/a,P=Math.min(y,I,m);e=Math.min(Math.max(e,g),P);const S=s*e,z=a*e,r=Math.sin(h),f=Math.cos(h),x=i.x/2-o,d=-i.y/2+o,R=c.x+x*f-d*r,W=c.y+x*r+d*f,p=S/2,l=-z/2,B=p*f-l*r,H=p*r+l*f,X=R-B,Y=W-H;return C(X,Y,s,a,e,h)}