@labelbee/lb-annotation 1.23.0 → 1.24.0-alpha.1

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.
@@ -1,2 +1,2 @@
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};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.23.0",
3
+ "version": "1.24.0-alpha.1",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.15.0",
97
+ "@labelbee/lb-utils": "1.16.0-alpha.1",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",