@labelbee/lb-annotation 1.27.0-alpha.63 → 1.27.0-alpha.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -185,5 +185,12 @@ export default class MathUtils {
185
185
  static getModifiedRectangleCoordinates(coordinates: ICoordinate[], newWidth: number, newHeight: number): ICoordinate[];
186
186
  static calculatePointsInsideBox: (params: ICalculatePointsInsideBoxParams) => number;
187
187
  static isPointInsideCube(point: I3DSpaceCoord, polygon: IPolygonPoint[], zScope: [number, number]): boolean;
188
+ static getCurrentPosFromRectCenter(size: {
189
+ width: number;
190
+ height: number;
191
+ }, centerPoint: IPolygonPoint, zoom: number): {
192
+ x: number;
193
+ y: number;
194
+ };
188
195
  }
189
196
  export {};
@@ -1,2 +1,2 @@
1
1
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MathUtilsWorker=require("../_virtual/MathUtilsWorker.js"),tool=require("../constant/tool.js"),polygonTool=require("./tool/polygonTool.js"),PolygonUtils=require("./tool/PolygonUtils.js"),VectorUtils=require("./VectorUtils.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,n,t)=>n in e?__defProp(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,__spreadValues=(e,n)=>{for(var t in n||(n={}))__hasOwnProp.call(n,t)&&__defNormalProp(e,t,n[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(n))__propIsEnum.call(n,t)&&__defNormalProp(e,t,n[t]);return e},__spreadProps=(e,n)=>__defProps(e,__getOwnPropDescs(n));class Trigonometric{static tanAPlusB(n,t){return(n+t)/(1-n*t)}static sinAPlusB(n,t,i,o){return o*n+t*i}static cosAPlusB(n,t,i,o){return t*o-n*i}}var CubePosition;(function(e){e[e.Outside=0]="Outside",e[e.PartiallyInside=1]="PartiallyInside",e[e.FullyInside=2]="FullyInside"})(CubePosition||(CubePosition={}));function getCubePosition(e,n,t){const i=[{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2}];let o=0;for(let s=0;s<i.length;s++)MathUtils.isPointInsideCube(i[s],e,n)&&o++;return o===0?0:o===8?2:1}const _MathUtils=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,n){return Math.sqrt(Math.pow(n.y-e.y,2)+Math.pow(n.x-e.x,2))}static getTextArea(e,n,t=tool.DEFAULT_TEXT_MAX_WIDTH,i=tool.DEFAULT_FONT,o){if(typeof n!="string")return{width:0,height:0};const s=e.getContext("2d");s.font=i;let r=0;typeof o=="undefined"&&(o=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=n.split(`
2
- `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let g="";for(let d=0;d<f.length;d++){const x=g+f[d],p=s.measureText(x).width;p>t&&d>0?(g=f[d],r+=o,y=t):(g=x,p>y&&(y=p))}h!==c.length-1&&(r+=o)}return{width:y,height:r+a,lineHeight:o,fontHeight:a}}static getLineCenterPoint(e){const[n,t]=e,i=VectorUtils.getVector(n,t);return{x:n.x+i.x/2,y:n.y+i.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[n,t]=e,i={x:t.x+t.y-n.y,y:t.y-(t.x-n.x)};return[t,i]}static getPerpendicularFootOfLine(e,n){if(e.length!==2)return e;const t=this.getPerpendicularLine(e);if(!t)return e;const[i,o]=t;return this.getFootOfPerpendicular(n,i,o).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[n,t,i]=e,o={x:i.x+n.x-t.x,y:i.y+n.y-t.y};return[n,t,i,o]}static getRectPerpendicularOffset(e,n,t){const[i,o]=t,s=this.getFootOfPerpendicular(e,i,o).footPoint,r=this.getFootOfPerpendicular(n,i,o).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=VectorUtils.add(n,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,n){return e<0?n+e:e>=n?e-n:e}static getPointListFromPointOffset(e,n,t){const i=this.getArrayIndex(n-1,e.length),o=this.getArrayIndex(n+1,e.length),s=this.getArrayIndex(n-2,e.length),r=[...e];r[n]=VectorUtils.add(r[n],t);const a=this.getFootOfPerpendicular(r[n],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[n],r[o],r[s]).footPoint;return r[i]=a,r[o]=c,r}static getRectCenterPoint(e){const[n,,t]=e;return{x:(n.x+t.x)/2,y:(n.y+t.y)/2}}static rotateRectPointList(e=5,n){const t=this.getRectCenterPoint(n),{PI:i}=Math,o=Math.sin(e*i/180),s=Math.cos(e*i/180);return n.map(r=>{const a=VectorUtils.getVector(t,r),c=VectorUtils.len(a),y=a.y/c,h=a.x/c;return{x:c*Trigonometric.cosAPlusB(y,h,o,s)+t.x,y:c*Trigonometric.sinAPlusB(y,h,o,s)+t.y}})}static getRectangleByRightAngle(e,n){if(n.length!==2)return n;const t=_MathUtils.getPerpendicularFootOfLine(n,e);return _MathUtils.getQuadrangleFromTriangle([...n,t])}static getRadiusFromQuadrangle(e){const[,n,t]=e,i=t.y-n.y,o=n.x-t.x,s=this.getLineLength(n,t),r=i/s,a=Math.acos(r);return o>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const n=e.filter(o=>o.type==="point").map(o=>o.annotation),t=e.filter(o=>!!["polygon","line"].includes(o.type)).map(o=>o.type==="polygon"?__spreadProps(__spreadValues({},o.annotation),{pointList:PolygonUtils.concatBeginAndEnd(o.annotation.pointList)}):o.annotation),i=new MathUtilsWorker;return{promise:new Promise(function(s){i.postMessage({points:n,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(e){const n=[],t=new Set,i=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?__spreadProps(__spreadValues({},r.annotation),{pointList:PolygonUtils.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(r,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||n.push(r),t.add(y)}};return i.forEach(r=>{s(r,o)}),o.forEach(r=>{let a="";a=r.id,o.forEach((c,y)=>{if(c.id===a)return;const h=[...o];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:n}}static getModifiedRectangleCoordinates(e,n,t){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=e[0],o=e[1],s=e[2],r=Math.sqrt(__pow(o.x-i.x,2)+__pow(o.y-i.y,2)),a=Math.sqrt(__pow(s.x-o.x,2)+__pow(s.y-o.y,2)),c=n/r,y=t/a,h={x:i.x+(o.x-i.x)*c,y:i.y+(o.y-i.y)*c},f={x:h.x+(s.x-o.x)*y,y:h.y+(s.y-o.y)*y},g={x:i.x+(f.x-o.x),y:i.y+(f.y-o.y)};return[i,h,f,g]}static isPointInsideCube(e,n,t){const[i,o]=t;return!!(polygonTool.isInPolygon({x:e.x,y:e.y},n)&&e.z>=i&&e.z<=o)}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n),o=r=>r<=i&&r>=t;return(Array.isArray(e)?e:[e]).every(r=>o(r))},MathUtils.withinRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n);return e>i?i:e<t?t:e},MathUtils.calcViewportBoundaries=(e,n=!1,t=tool.SEGMENT_NUMBER,i=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const o=20/i,s=[],r=[];let a=e;n&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,t)),a.forEach(({x,y:u})=>{s.push(x),r.push(u)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const g=y-c,d=f-h;if(g<o){const x=(o-g)/2;c-=x,y+=x}if(d<o){const x=(o-d)/2;h-=x,f+=x}return{top:h,bottom:f,left:c,right:y}},MathUtils.getFootOfPerpendicular=(e,n,t,i=!1,o=!1)=>{let s={x:0,y:0};const r=n.x-t.x,a=n.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=n,s;let c=(e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y);c/=r*r+a*a,s.x=n.x+c*r,s.y=n.y+c*a;const y=_MathUtils.getLineLength(e,s),h=2,f=Math.min(n.x,t.x),g=Math.max(n.x,t.x),d=Math.min(n.y,t.y),x=Math.max(n.y,t.y),u=!(_MathUtils.isInRange(e.x,[f,g])||_MathUtils.isInRange(e.y,[d,x])),p=e.x>g+h||e.x<f-h||e.y>x+h||e.y<d-h;return!o&&(i?u:p)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},MathUtils.calculatePointsInsideBox=e=>{const{indexMap:n,polygon:t,zScope:i,box:o}=e;let s=0;return n.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),g={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=getCubePosition(t,i,g);d===2&&(s+=r.length),(d===1||d===0&&(o.width<=1||o.height<=1))&&r.forEach(x=>{_MathUtils.isPointInsideCube(x,t,i)&&s++})}),s};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$1;
2
+ `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let g="";for(let d=0;d<f.length;d++){const x=g+f[d],p=s.measureText(x).width;p>t&&d>0?(g=f[d],r+=o,y=t):(g=x,p>y&&(y=p))}h!==c.length-1&&(r+=o)}return{width:y,height:r+a,lineHeight:o,fontHeight:a}}static getLineCenterPoint(e){const[n,t]=e,i=VectorUtils.getVector(n,t);return{x:n.x+i.x/2,y:n.y+i.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[n,t]=e,i={x:t.x+t.y-n.y,y:t.y-(t.x-n.x)};return[t,i]}static getPerpendicularFootOfLine(e,n){if(e.length!==2)return e;const t=this.getPerpendicularLine(e);if(!t)return e;const[i,o]=t;return this.getFootOfPerpendicular(n,i,o).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[n,t,i]=e,o={x:i.x+n.x-t.x,y:i.y+n.y-t.y};return[n,t,i,o]}static getRectPerpendicularOffset(e,n,t){const[i,o]=t,s=this.getFootOfPerpendicular(e,i,o).footPoint,r=this.getFootOfPerpendicular(n,i,o).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=VectorUtils.add(n,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,n){return e<0?n+e:e>=n?e-n:e}static getPointListFromPointOffset(e,n,t){const i=this.getArrayIndex(n-1,e.length),o=this.getArrayIndex(n+1,e.length),s=this.getArrayIndex(n-2,e.length),r=[...e];r[n]=VectorUtils.add(r[n],t);const a=this.getFootOfPerpendicular(r[n],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[n],r[o],r[s]).footPoint;return r[i]=a,r[o]=c,r}static getRectCenterPoint(e){const[n,,t]=e;return{x:(n.x+t.x)/2,y:(n.y+t.y)/2}}static rotateRectPointList(e=5,n){const t=this.getRectCenterPoint(n),{PI:i}=Math,o=Math.sin(e*i/180),s=Math.cos(e*i/180);return n.map(r=>{const a=VectorUtils.getVector(t,r),c=VectorUtils.len(a),y=a.y/c,h=a.x/c;return{x:c*Trigonometric.cosAPlusB(y,h,o,s)+t.x,y:c*Trigonometric.sinAPlusB(y,h,o,s)+t.y}})}static getRectangleByRightAngle(e,n){if(n.length!==2)return n;const t=_MathUtils.getPerpendicularFootOfLine(n,e);return _MathUtils.getQuadrangleFromTriangle([...n,t])}static getRadiusFromQuadrangle(e){const[,n,t]=e,i=t.y-n.y,o=n.x-t.x,s=this.getLineLength(n,t),r=i/s,a=Math.acos(r);return o>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const n=e.filter(o=>o.type==="point").map(o=>o.annotation),t=e.filter(o=>!!["polygon","line"].includes(o.type)).map(o=>o.type==="polygon"?__spreadProps(__spreadValues({},o.annotation),{pointList:PolygonUtils.concatBeginAndEnd(o.annotation.pointList)}):o.annotation),i=new MathUtilsWorker;return{promise:new Promise(function(s){i.postMessage({points:n,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(e){const n=[],t=new Set,i=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?__spreadProps(__spreadValues({},r.annotation),{pointList:PolygonUtils.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(r,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||n.push(r),t.add(y)}};return i.forEach(r=>{s(r,o)}),o.forEach(r=>{let a="";a=r.id,o.forEach((c,y)=>{if(c.id===a)return;const h=[...o];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:n}}static getModifiedRectangleCoordinates(e,n,t){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=e[0],o=e[1],s=e[2],r=Math.sqrt(__pow(o.x-i.x,2)+__pow(o.y-i.y,2)),a=Math.sqrt(__pow(s.x-o.x,2)+__pow(s.y-o.y,2)),c=n/r,y=t/a,h={x:i.x+(o.x-i.x)*c,y:i.y+(o.y-i.y)*c},f={x:h.x+(s.x-o.x)*y,y:h.y+(s.y-o.y)*y},g={x:i.x+(f.x-o.x),y:i.y+(f.y-o.y)};return[i,h,f,g]}static isPointInsideCube(e,n,t){const[i,o]=t;return!!(polygonTool.isInPolygon({x:e.x,y:e.y},n)&&e.z>=i&&e.z<=o)}static getCurrentPosFromRectCenter(e,n,t){return{x:e.width/2-n.x*t,y:e.height/2-n.y*t}}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n),o=r=>r<=i&&r>=t;return(Array.isArray(e)?e:[e]).every(r=>o(r))},MathUtils.withinRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n);return e>i?i:e<t?t:e},MathUtils.calcViewportBoundaries=(e,n=!1,t=tool.SEGMENT_NUMBER,i=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const o=20/i,s=[],r=[];let a=e;n&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,t)),a.forEach(({x,y:u})=>{s.push(x),r.push(u)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const g=y-c,d=f-h;if(g<o){const x=(o-g)/2;c-=x,y+=x}if(d<o){const x=(o-d)/2;h-=x,f+=x}return{top:h,bottom:f,left:c,right:y}},MathUtils.getFootOfPerpendicular=(e,n,t,i=!1,o=!1)=>{let s={x:0,y:0};const r=n.x-t.x,a=n.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=n,s;let c=(e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y);c/=r*r+a*a,s.x=n.x+c*r,s.y=n.y+c*a;const y=_MathUtils.getLineLength(e,s),h=2,f=Math.min(n.x,t.x),g=Math.max(n.x,t.x),d=Math.min(n.y,t.y),x=Math.max(n.y,t.y),u=!(_MathUtils.isInRange(e.x,[f,g])||_MathUtils.isInRange(e.y,[d,x])),p=e.x>g+h||e.x<f-h||e.y>x+h||e.y<d-h;return!o&&(i?u:p)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},MathUtils.calculatePointsInsideBox=e=>{const{indexMap:n,polygon:t,zScope:i,box:o}=e;let s=0;return n.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),g={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=getCubePosition(t,i,g);d===2&&(s+=r.length),(d===1||d===0&&(o.width<=1||o.height<=1))&&r.forEach(x=>{_MathUtils.isPointInsideCube(x,t,i)&&s++})}),s};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$1;
@@ -1,2 +1,2 @@
1
- import z from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as E,DEFAULT_TEXT_MAX_WIDTH as R,DEFAULT_FONT as T,ELineTypes as S}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as v,isInPolygon as B}from"./tool/polygonTool.js";import O from"./tool/PolygonUtils.js";import P from"./VectorUtils.js";var U=Object.defineProperty,j=Object.defineProperties,N=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,I=(n,o,t)=>o in n?U(n,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[o]=t,A=(n,o)=>{for(var t in o||(o={}))V.call(o,t)&&I(n,t,o[t]);if(_)for(var t of _(o))X.call(o,t)&&I(n,t,o[t]);return n},F=(n,o)=>j(n,N(o));class m{static tanAPlusB(o,t){return(o+t)/(1-o*t)}static sinAPlusB(o,t,i,e){return e*o+t*i}static cosAPlusB(o,t,i,e){return t*e-o*i}}var L;(function(n){n[n.Outside=0]="Outside",n[n.PartiallyInside=1]="PartiallyInside",n[n.FullyInside=2]="FullyInside"})(L||(L={}));function D(n,o,t){const i=[{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2}];let e=0;for(let s=0;s<i.length;s++)u.isPointInsideCube(i[s],n,o)&&e++;return e===0?0:e===8?2:1}const g=class{static getRotate(n){return n+90>=360?n+90-360:n+90}static getLineLength(n,o){return Math.sqrt(Math.pow(o.y-n.y,2)+Math.pow(o.x-n.x,2))}static getTextArea(n,o,t=R,i=T,e){if(typeof o!="string")return{width:0,height:0};const s=n.getContext("2d");s.font=i;let r=0;typeof e=="undefined"&&(e=n&&parseInt(window.getComputedStyle(n).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=n&&parseInt(window.getComputedStyle(n).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=o.split(`
2
- `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let x="";for(let d=0;d<f.length;d++){const p=x+f[d],l=s.measureText(p).width;l>t&&d>0?(x=f[d],r+=e,y=t):(x=p,l>y&&(y=l))}h!==c.length-1&&(r+=e)}return{width:y,height:r+a,lineHeight:e,fontHeight:a}}static getLineCenterPoint(n){const[o,t]=n,i=P.getVector(o,t);return{x:o.x+i.x/2,y:o.y+i.y/2}}static getPerpendicularLine(n){if(n.length!==2)return;const[o,t]=n,i={x:t.x+t.y-o.y,y:t.y-(t.x-o.x)};return[t,i]}static getPerpendicularFootOfLine(n,o){if(n.length!==2)return n;const t=this.getPerpendicularLine(n);if(!t)return n;const[i,e]=t;return this.getFootOfPerpendicular(o,i,e).footPoint}static getQuadrangleFromTriangle(n){if(n.length!==3)return n;const[o,t,i]=n,e={x:i.x+o.x-t.x,y:i.y+o.y-t.y};return[o,t,i,e]}static getRectPerpendicularOffset(n,o,t){const[i,e]=t,s=this.getFootOfPerpendicular(n,i,e).footPoint,r=this.getFootOfPerpendicular(o,i,e).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=P.add(o,a);return P.getVector(n,c)}static getArrayIndex(n,o){return n<0?o+n:n>=o?n-o:n}static getPointListFromPointOffset(n,o,t){const i=this.getArrayIndex(o-1,n.length),e=this.getArrayIndex(o+1,n.length),s=this.getArrayIndex(o-2,n.length),r=[...n];r[o]=P.add(r[o],t);const a=this.getFootOfPerpendicular(r[o],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[o],r[e],r[s]).footPoint;return r[i]=a,r[e]=c,r}static getRectCenterPoint(n){const[o,,t]=n;return{x:(o.x+t.x)/2,y:(o.y+t.y)/2}}static rotateRectPointList(n=5,o){const t=this.getRectCenterPoint(o),{PI:i}=Math,e=Math.sin(n*i/180),s=Math.cos(n*i/180);return o.map(r=>{const a=P.getVector(t,r),c=P.len(a),y=a.y/c,h=a.x/c;return{x:c*m.cosAPlusB(y,h,e,s)+t.x,y:c*m.sinAPlusB(y,h,e,s)+t.y}})}static getRectangleByRightAngle(n,o){if(o.length!==2)return o;const t=g.getPerpendicularFootOfLine(o,n);return g.getQuadrangleFromTriangle([...o,t])}static getRadiusFromQuadrangle(n){const[,o,t]=n,i=t.y-o.y,e=o.x-t.x,s=this.getLineLength(o,t),r=i/s,a=Math.acos(r);return e>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(n){const o=n.filter(e=>e.type==="point").map(e=>e.annotation),t=n.filter(e=>!!["polygon","line"].includes(e.type)).map(e=>e.type==="polygon"?F(A({},e.annotation),{pointList:O.concatBeginAndEnd(e.annotation.pointList)}):e.annotation),i=new z;return{promise:new Promise(function(s){i.postMessage({points:o,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(n){const o=[],t=new Set,i=n.filter(r=>r.type==="point").map(r=>r.annotation),e=n.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?F(A({},r.annotation),{pointList:O.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=O.getClosestPoint(r,a,S.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||o.push(r),t.add(y)}};return i.forEach(r=>{s(r,e)}),e.forEach(r=>{let a="";a=r.id,e.forEach((c,y)=>{if(c.id===a)return;const h=[...e];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:o}}static getModifiedRectangleCoordinates(n,o,t){if(n.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=n[0],e=n[1],s=n[2],r=Math.sqrt(M(e.x-i.x,2)+M(e.y-i.y,2)),a=Math.sqrt(M(s.x-e.x,2)+M(s.y-e.y,2)),c=o/r,y=t/a,h={x:i.x+(e.x-i.x)*c,y:i.y+(e.y-i.y)*c},f={x:h.x+(s.x-e.x)*y,y:h.y+(s.y-e.y)*y},x={x:i.x+(f.x-e.x),y:i.y+(f.y-e.y)};return[i,h,f,x]}static isPointInsideCube(n,o,t){const[i,e]=t;return!!(B({x:n.x,y:n.y},o)&&n.z>=i&&n.z<=e)}};let u=g;u.isInRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o),e=r=>r<=i&&r>=t;return(Array.isArray(n)?n:[n]).every(r=>e(r))},u.withinRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o);return n>i?i:n<t?t:n},u.calcViewportBoundaries=(n,o=!1,t=E,i=1)=>{if(!n)return{top:0,bottom:0,left:0,right:0};const e=20/i,s=[],r=[];let a=n;o&&(a=v(n,t)),a.forEach(({x:p,y:w})=>{s.push(p),r.push(w)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const x=y-c,d=f-h;if(x<e){const p=(e-x)/2;c-=p,y+=p}if(d<e){const p=(e-d)/2;h-=p,f+=p}return{top:h,bottom:f,left:c,right:y}},u.getFootOfPerpendicular=(n,o,t,i=!1,e=!1)=>{let s={x:0,y:0};const r=o.x-t.x,a=o.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=o,s;let c=(n.x-o.x)*(o.x-t.x)+(n.y-o.y)*(o.y-t.y);c/=r*r+a*a,s.x=o.x+c*r,s.y=o.y+c*a;const y=g.getLineLength(n,s),h=2,f=Math.min(o.x,t.x),x=Math.max(o.x,t.x),d=Math.min(o.y,t.y),p=Math.max(o.y,t.y),w=!(g.isInRange(n.x,[f,x])||g.isInRange(n.y,[d,p])),l=n.x>x+h||n.x<f-h||n.y>p+h||n.y<d-h;return!e&&(i?w:l)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},u.calculatePointsInsideBox=n=>{const{indexMap:o,polygon:t,zScope:i,box:e}=n;let s=0;return o.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),x={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=D(t,i,x);d===2&&(s+=r.length),(d===1||d===0&&(e.width<=1||e.height<=1))&&r.forEach(p=>{g.isPointInsideCube(p,t,i)&&s++})}),s};var W=u;export{m as Trigonometric,W as default};
1
+ import z from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as E,DEFAULT_TEXT_MAX_WIDTH as R,DEFAULT_FONT as T,ELineTypes as S}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as v,isInPolygon as B}from"./tool/polygonTool.js";import O from"./tool/PolygonUtils.js";import P from"./VectorUtils.js";var U=Object.defineProperty,j=Object.defineProperties,N=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,F=(n,o,t)=>o in n?U(n,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[o]=t,I=(n,o)=>{for(var t in o||(o={}))V.call(o,t)&&F(n,t,o[t]);if(_)for(var t of _(o))X.call(o,t)&&F(n,t,o[t]);return n},A=(n,o)=>j(n,N(o));class m{static tanAPlusB(o,t){return(o+t)/(1-o*t)}static sinAPlusB(o,t,i,e){return e*o+t*i}static cosAPlusB(o,t,i,e){return t*e-o*i}}var L;(function(n){n[n.Outside=0]="Outside",n[n.PartiallyInside=1]="PartiallyInside",n[n.FullyInside=2]="FullyInside"})(L||(L={}));function D(n,o,t){const i=[{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2}];let e=0;for(let s=0;s<i.length;s++)u.isPointInsideCube(i[s],n,o)&&e++;return e===0?0:e===8?2:1}const p=class{static getRotate(n){return n+90>=360?n+90-360:n+90}static getLineLength(n,o){return Math.sqrt(Math.pow(o.y-n.y,2)+Math.pow(o.x-n.x,2))}static getTextArea(n,o,t=R,i=T,e){if(typeof o!="string")return{width:0,height:0};const s=n.getContext("2d");s.font=i;let r=0;typeof e=="undefined"&&(e=n&&parseInt(window.getComputedStyle(n).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=n&&parseInt(window.getComputedStyle(n).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=o.split(`
2
+ `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let g="";for(let d=0;d<f.length;d++){const x=g+f[d],l=s.measureText(x).width;l>t&&d>0?(g=f[d],r+=e,y=t):(g=x,l>y&&(y=l))}h!==c.length-1&&(r+=e)}return{width:y,height:r+a,lineHeight:e,fontHeight:a}}static getLineCenterPoint(n){const[o,t]=n,i=P.getVector(o,t);return{x:o.x+i.x/2,y:o.y+i.y/2}}static getPerpendicularLine(n){if(n.length!==2)return;const[o,t]=n,i={x:t.x+t.y-o.y,y:t.y-(t.x-o.x)};return[t,i]}static getPerpendicularFootOfLine(n,o){if(n.length!==2)return n;const t=this.getPerpendicularLine(n);if(!t)return n;const[i,e]=t;return this.getFootOfPerpendicular(o,i,e).footPoint}static getQuadrangleFromTriangle(n){if(n.length!==3)return n;const[o,t,i]=n,e={x:i.x+o.x-t.x,y:i.y+o.y-t.y};return[o,t,i,e]}static getRectPerpendicularOffset(n,o,t){const[i,e]=t,s=this.getFootOfPerpendicular(n,i,e).footPoint,r=this.getFootOfPerpendicular(o,i,e).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=P.add(o,a);return P.getVector(n,c)}static getArrayIndex(n,o){return n<0?o+n:n>=o?n-o:n}static getPointListFromPointOffset(n,o,t){const i=this.getArrayIndex(o-1,n.length),e=this.getArrayIndex(o+1,n.length),s=this.getArrayIndex(o-2,n.length),r=[...n];r[o]=P.add(r[o],t);const a=this.getFootOfPerpendicular(r[o],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[o],r[e],r[s]).footPoint;return r[i]=a,r[e]=c,r}static getRectCenterPoint(n){const[o,,t]=n;return{x:(o.x+t.x)/2,y:(o.y+t.y)/2}}static rotateRectPointList(n=5,o){const t=this.getRectCenterPoint(o),{PI:i}=Math,e=Math.sin(n*i/180),s=Math.cos(n*i/180);return o.map(r=>{const a=P.getVector(t,r),c=P.len(a),y=a.y/c,h=a.x/c;return{x:c*m.cosAPlusB(y,h,e,s)+t.x,y:c*m.sinAPlusB(y,h,e,s)+t.y}})}static getRectangleByRightAngle(n,o){if(o.length!==2)return o;const t=p.getPerpendicularFootOfLine(o,n);return p.getQuadrangleFromTriangle([...o,t])}static getRadiusFromQuadrangle(n){const[,o,t]=n,i=t.y-o.y,e=o.x-t.x,s=this.getLineLength(o,t),r=i/s,a=Math.acos(r);return e>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(n){const o=n.filter(e=>e.type==="point").map(e=>e.annotation),t=n.filter(e=>!!["polygon","line"].includes(e.type)).map(e=>e.type==="polygon"?A(I({},e.annotation),{pointList:O.concatBeginAndEnd(e.annotation.pointList)}):e.annotation),i=new z;return{promise:new Promise(function(s){i.postMessage({points:o,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(n){const o=[],t=new Set,i=n.filter(r=>r.type==="point").map(r=>r.annotation),e=n.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?A(I({},r.annotation),{pointList:O.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=O.getClosestPoint(r,a,S.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||o.push(r),t.add(y)}};return i.forEach(r=>{s(r,e)}),e.forEach(r=>{let a="";a=r.id,e.forEach((c,y)=>{if(c.id===a)return;const h=[...e];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:o}}static getModifiedRectangleCoordinates(n,o,t){if(n.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=n[0],e=n[1],s=n[2],r=Math.sqrt(M(e.x-i.x,2)+M(e.y-i.y,2)),a=Math.sqrt(M(s.x-e.x,2)+M(s.y-e.y,2)),c=o/r,y=t/a,h={x:i.x+(e.x-i.x)*c,y:i.y+(e.y-i.y)*c},f={x:h.x+(s.x-e.x)*y,y:h.y+(s.y-e.y)*y},g={x:i.x+(f.x-e.x),y:i.y+(f.y-e.y)};return[i,h,f,g]}static isPointInsideCube(n,o,t){const[i,e]=t;return!!(B({x:n.x,y:n.y},o)&&n.z>=i&&n.z<=e)}static getCurrentPosFromRectCenter(n,o,t){return{x:n.width/2-o.x*t,y:n.height/2-o.y*t}}};let u=p;u.isInRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o),e=r=>r<=i&&r>=t;return(Array.isArray(n)?n:[n]).every(r=>e(r))},u.withinRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o);return n>i?i:n<t?t:n},u.calcViewportBoundaries=(n,o=!1,t=E,i=1)=>{if(!n)return{top:0,bottom:0,left:0,right:0};const e=20/i,s=[],r=[];let a=n;o&&(a=v(n,t)),a.forEach(({x,y:w})=>{s.push(x),r.push(w)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const g=y-c,d=f-h;if(g<e){const x=(e-g)/2;c-=x,y+=x}if(d<e){const x=(e-d)/2;h-=x,f+=x}return{top:h,bottom:f,left:c,right:y}},u.getFootOfPerpendicular=(n,o,t,i=!1,e=!1)=>{let s={x:0,y:0};const r=o.x-t.x,a=o.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=o,s;let c=(n.x-o.x)*(o.x-t.x)+(n.y-o.y)*(o.y-t.y);c/=r*r+a*a,s.x=o.x+c*r,s.y=o.y+c*a;const y=p.getLineLength(n,s),h=2,f=Math.min(o.x,t.x),g=Math.max(o.x,t.x),d=Math.min(o.y,t.y),x=Math.max(o.y,t.y),w=!(p.isInRange(n.x,[f,g])||p.isInRange(n.y,[d,x])),l=n.x>g+h||n.x<f-h||n.y>x+h||n.y<d-h;return!e&&(i?w:l)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},u.calculatePointsInsideBox=n=>{const{indexMap:o,polygon:t,zScope:i,box:e}=n;let s=0;return o.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),g={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=D(t,i,g);d===2&&(s+=r.length),(d===1||d===0&&(e.width<=1||e.height<=1))&&r.forEach(x=>{p.isPointInsideCube(x,t,i)&&s++})}),s};var W=u;export{m as Trigonometric,W as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.27.0-alpha.63",
3
+ "version": "1.27.0-alpha.64",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",