@labelbee/lb-annotation 1.18.0-alpha.7 → 1.18.0-alpha.8

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.
@@ -169,4 +169,11 @@ export default class MathUtils {
169
169
  static getCollectionPointByAnnotationData(annotations: TAnnotationViewData[]): {
170
170
  connectionPoints: ICoordinate[];
171
171
  };
172
+ /**
173
+ * Calculate new coordinates by given new length and width
174
+ * @param coordinates
175
+ * @param newWidth
176
+ * @param newHeight
177
+ */
178
+ static getModifiedRectangleCoordinates(coordinates: ICoordinate[], newWidth: number, newHeight: number): ICoordinate[];
172
179
  }
@@ -1,2 +1,2 @@
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,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));class Trigonometric{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const _MathUtils=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=tool.DEFAULT_TEXT_MAX_WIDTH,s=tool.DEFAULT_FONT,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=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=t.split(`
2
- `);let l=0;for(let u=0;u<c.length;u++){const p=c[u].split("");let g="";for(let y=0;y<p.length;y++){const f=g+p[y],h=i.measureText(f).width;h>o&&y>0?(g=p[y],n+=r,l=o):(g=f,h>l&&(l=h))}u!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=VectorUtils.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=VectorUtils.add(t,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=VectorUtils.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=VectorUtils.getVector(o,n),c=VectorUtils.len(a),l=a.y/c,u=a.x/c;return{x:c*Trigonometric.cosAPlusB(l,u,r,i)+o.x,y:c*Trigonometric.sinAPlusB(l,u,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=_MathUtils.getPerpendicularFootOfLine(t,e);return _MathUtils.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=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=new MathUtilsWorker;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?__spreadProps(__spreadValues({},n.annotation),{pointList:PolygonUtils.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(n,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const u=[...r];u.splice(l,1),c.pointList.forEach(p=>{i(p,u)})})}),{connectionPoints:t}}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},MathUtils.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},MathUtils.calcViewportBoundaries=(e,t=!1,o=tool.SEGMENT_NUMBER,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,o)),a.forEach(({x:f,y:d})=>{i.push(f),n.push(d)});let c=Math.min(...i),l=Math.max(...i),u=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-u;if(g<r){const f=(r-g)/2;c-=f,l+=f}if(y<r){const f=(r-y)/2;u-=f,p+=f}return{top:u,bottom:p,left:c,right:l}},MathUtils.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=_MathUtils.getLineLength(e,i),u=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),f=Math.max(t.y,o.y),d=!(_MathUtils.isInRange(e.x,[p,g])||_MathUtils.isInRange(e.y,[y,f])),h=e.x>g+u||e.x<p-u||e.y>f+u||e.y<y-u;return!r&&(s?d:h)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$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,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));class Trigonometric{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,n){return n*t+o*s}static cosAPlusB(t,o,s,n){return o*n-t*s}}const _MathUtils=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=tool.DEFAULT_TEXT_MAX_WIDTH,s=tool.DEFAULT_FONT,n){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let r=0;typeof n=="undefined"&&(n=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=t.split(`
2
+ `);let u=0;for(let l=0;l<c.length;l++){const f=c[l].split("");let p="";for(let h=0;h<f.length;h++){const y=p+f[h],g=i.measureText(y).width;g>o&&h>0?(p=f[h],r+=n,u=o):(p=y,g>u&&(u=g))}l!==c.length-1&&(r+=n)}return{width:u,height:r+a,lineHeight:n,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=VectorUtils.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,n]=o;return this.getFootOfPerpendicular(t,s,n).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,n={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,n]}static getRectPerpendicularOffset(e,t,o){const[s,n]=o,i=this.getFootOfPerpendicular(e,s,n).footPoint,r=this.getFootOfPerpendicular(t,s,n).footPoint,a={x:i.x-r.x,y:i.y-r.y},c=VectorUtils.add(t,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),n=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),r=[...e];r[t]=VectorUtils.add(r[t],o);const a=this.getFootOfPerpendicular(r[t],r[i],r[s]).footPoint,c=this.getFootOfPerpendicular(r[t],r[n],r[i]).footPoint;return r[s]=a,r[n]=c,r}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,n=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(r=>{const a=VectorUtils.getVector(o,r),c=VectorUtils.len(a),u=a.y/c,l=a.x/c;return{x:c*Trigonometric.cosAPlusB(u,l,n,i)+o.x,y:c*Trigonometric.sinAPlusB(u,l,n,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=_MathUtils.getPerpendicularFootOfLine(t,e);return _MathUtils.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,n=t.x-o.x,i=this.getLineLength(t,o),r=s/i,a=Math.acos(r);return n>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(n=>n.type==="point").map(n=>n.annotation),o=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?__spreadProps(__spreadValues({},n.annotation),{pointList:PolygonUtils.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),s=new MathUtilsWorker;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=r=>{i(r.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(r=>r.type==="point").map(r=>r.annotation),n=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),i=(r,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(r,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==r){const u=`${c.x} + ${c.y}`;o.has(u)||t.push(r),o.add(u)}};return s.forEach(r=>{i(r,n)}),n.forEach(r=>{let a="";a=r.id,n.forEach((c,u)=>{if(c.id===a)return;const l=[...n];l.splice(u,1),c.pointList.forEach(f=>{i(f,l)})})}),{connectionPoints:t}}static getModifiedRectangleCoordinates(e,t,o){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const s=e[0],n=e[1],i=e[2],r=Math.sqrt(__pow(n.x-s.x,2)+__pow(n.y-s.y,2)),a=Math.sqrt(__pow(i.x-n.x,2)+__pow(i.y-n.y,2)),c=t/r,u=o/a,l={x:s.x+(n.x-s.x)*c,y:s.y+(n.y-s.y)*c},f={x:l.x+(i.x-n.x)*u,y:l.y+(i.y-n.y)*u},p={x:s.x+(f.x-n.x),y:s.y+(f.y-n.y)};return[s,l,f,p]}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),n=r=>r<=s&&r>=o;return(Array.isArray(e)?e:[e]).every(r=>n(r))},MathUtils.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},MathUtils.calcViewportBoundaries=(e,t=!1,o=tool.SEGMENT_NUMBER,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const n=20/s,i=[],r=[];let a=e;t&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,o)),a.forEach(({x:y,y:x})=>{i.push(y),r.push(x)});let c=Math.min(...i),u=Math.max(...i),l=Math.min(...r),f=Math.max(...r);const p=u-c,h=f-l;if(p<n){const y=(n-p)/2;c-=y,u+=y}if(h<n){const y=(n-h)/2;l-=y,f+=y}return{top:l,bottom:f,left:c,right:u}},MathUtils.getFootOfPerpendicular=(e,t,o,s=!1,n=!1)=>{let i={x:0,y:0};const r=t.x-o.x,a=t.y-o.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=r*r+a*a,i.x=t.x+c*r,i.y=t.y+c*a;const u=_MathUtils.getLineLength(e,i),l=2,f=Math.min(t.x,o.x),p=Math.max(t.x,o.x),h=Math.min(t.y,o.y),y=Math.max(t.y,o.y),x=!(_MathUtils.isInRange(e.x,[f,p])||_MathUtils.isInRange(e.y,[h,y])),g=e.x>p+l||e.x<f-l||e.y>y+l||e.y<h-l;return!n&&(s?x:g)?{footPoint:i,length:Infinity}:{footPoint:i,length:u}};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$1;
@@ -1,2 +1,2 @@
1
- import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=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=t.split(`
2
- `);let l=0;for(let f=0;f<c.length;f++){const p=c[f].split("");let g="";for(let y=0;y<p.length;y++){const u=g+p[y],d=i.measureText(u).width;d>o&&y>0?(g=p[y],n+=r,l=o):(g=u,d>l&&(l=d))}f!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=h.add(t,a);return h.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=h.getVector(o,n),c=h.len(a),l=a.y/c,f=a.x/c;return{x:c*M.cosAPlusB(l,f,r,i)+o.x,y:c*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=w.getClosestPoint(n,a,T.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const f=[...r];f.splice(l,1),c.pointList.forEach(p=>{i(p,f)})})}),{connectionPoints:t}}};let x=m;x.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},x.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},x.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=B(e,o)),a.forEach(({x:u,y:P})=>{i.push(u),n.push(P)});let c=Math.min(...i),l=Math.max(...i),f=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-f;if(g<r){const u=(r-g)/2;c-=u,l+=u}if(y<r){const u=(r-y)/2;f-=u,p+=u}return{top:f,bottom:p,left:c,right:l}},x.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=m.getLineLength(e,i),f=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y),P=!(m.isInRange(e.x,[p,g])||m.isInRange(e.y,[y,u])),d=e.x>g+f||e.x<p-f||e.y>u+f||e.y<y-f;return!r&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var D=x;export{M as Trigonometric,D as default};
1
+ import R from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as E,DEFAULT_TEXT_MAX_WIDTH as I,DEFAULT_FONT as T,ELineTypes as S}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as v}from"./tool/polygonTool.js";import M from"./tool/PolygonUtils.js";import g from"./VectorUtils.js";var B=Object.defineProperty,C=Object.defineProperties,U=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,w=Math.pow,A=(e,t,o)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,L=(e,t)=>{for(var o in t||(t={}))j.call(t,o)&&A(e,o,t[o]);if(O)for(var o of O(t))D.call(t,o)&&A(e,o,t[o]);return e},F=(e,t)=>C(e,U(t));class _{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,n){return n*t+o*s}static cosAPlusB(t,o,s,n){return o*n-t*s}}const x=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=I,s=T,n){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let r=0;typeof n=="undefined"&&(n=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=t.split(`
2
+ `);let f=0;for(let l=0;l<c.length;l++){const u=c[l].split("");let p="";for(let h=0;h<u.length;h++){const y=p+u[h],d=i.measureText(y).width;d>o&&h>0?(p=u[h],r+=n,f=o):(p=y,d>f&&(f=d))}l!==c.length-1&&(r+=n)}return{width:f,height:r+a,lineHeight:n,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=g.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,n]=o;return this.getFootOfPerpendicular(t,s,n).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,n={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,n]}static getRectPerpendicularOffset(e,t,o){const[s,n]=o,i=this.getFootOfPerpendicular(e,s,n).footPoint,r=this.getFootOfPerpendicular(t,s,n).footPoint,a={x:i.x-r.x,y:i.y-r.y},c=g.add(t,a);return g.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),n=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),r=[...e];r[t]=g.add(r[t],o);const a=this.getFootOfPerpendicular(r[t],r[i],r[s]).footPoint,c=this.getFootOfPerpendicular(r[t],r[n],r[i]).footPoint;return r[s]=a,r[n]=c,r}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,n=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(r=>{const a=g.getVector(o,r),c=g.len(a),f=a.y/c,l=a.x/c;return{x:c*_.cosAPlusB(f,l,n,i)+o.x,y:c*_.sinAPlusB(f,l,n,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=x.getPerpendicularFootOfLine(t,e);return x.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,n=t.x-o.x,i=this.getLineLength(t,o),r=s/i,a=Math.acos(r);return n>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(n=>n.type==="point").map(n=>n.annotation),o=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?F(L({},n.annotation),{pointList:M.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),s=new R;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=r=>{i(r.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(r=>r.type==="point").map(r=>r.annotation),n=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?F(L({},r.annotation),{pointList:M.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),i=(r,a)=>{const{dropFoot:c}=M.getClosestPoint(r,a,S.Line,1,{isClose:!1});if(c!==r){const f=`${c.x} + ${c.y}`;o.has(f)||t.push(r),o.add(f)}};return s.forEach(r=>{i(r,n)}),n.forEach(r=>{let a="";a=r.id,n.forEach((c,f)=>{if(c.id===a)return;const l=[...n];l.splice(f,1),c.pointList.forEach(u=>{i(u,l)})})}),{connectionPoints:t}}static getModifiedRectangleCoordinates(e,t,o){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const s=e[0],n=e[1],i=e[2],r=Math.sqrt(w(n.x-s.x,2)+w(n.y-s.y,2)),a=Math.sqrt(w(i.x-n.x,2)+w(i.y-n.y,2)),c=t/r,f=o/a,l={x:s.x+(n.x-s.x)*c,y:s.y+(n.y-s.y)*c},u={x:l.x+(i.x-n.x)*f,y:l.y+(i.y-n.y)*f},p={x:s.x+(u.x-n.x),y:s.y+(u.y-n.y)};return[s,l,u,p]}};let m=x;m.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),n=r=>r<=s&&r>=o;return(Array.isArray(e)?e:[e]).every(r=>n(r))},m.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},m.calcViewportBoundaries=(e,t=!1,o=E,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const n=20/s,i=[],r=[];let a=e;t&&(a=v(e,o)),a.forEach(({x:y,y:P})=>{i.push(y),r.push(P)});let c=Math.min(...i),f=Math.max(...i),l=Math.min(...r),u=Math.max(...r);const p=f-c,h=u-l;if(p<n){const y=(n-p)/2;c-=y,f+=y}if(h<n){const y=(n-h)/2;l-=y,u+=y}return{top:l,bottom:u,left:c,right:f}},m.getFootOfPerpendicular=(e,t,o,s=!1,n=!1)=>{let i={x:0,y:0};const r=t.x-o.x,a=t.y-o.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=r*r+a*a,i.x=t.x+c*r,i.y=t.y+c*a;const f=x.getLineLength(e,i),l=2,u=Math.min(t.x,o.x),p=Math.max(t.x,o.x),h=Math.min(t.y,o.y),y=Math.max(t.y,o.y),P=!(x.isInRange(e.x,[u,p])||x.isInRange(e.y,[h,y])),d=e.x>p+l||e.x<u-l||e.y>y+l||e.y<h-l;return!n&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:f}};var V=m;export{_ as Trigonometric,V as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.18.0-alpha.7",
3
+ "version": "1.18.0-alpha.8",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",