@labelbee/lb-annotation 1.18.0-alpha.7 → 1.18.0-alpha.9
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.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/scheduler.js +1 -1
- package/dist/types/utils/MathUtils.d.ts +7 -0
- package/dist/utils/MathUtils.js +2 -2
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/scheduler.js +1 -1
- package/es/utils/MathUtils.js +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:s,extraProps:P,config:m,checkMode:I,toolName:u,proxyMode:v}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var o;const r=(o=i.pointList)==null?void 0:o.map(d=>__spreadValues({i:d},lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size)));return __spreadProps(__spreadValues({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(o=>{var r;const{polygon2d:d}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(o);return{id:o.id,sourceID:"",pointList:d,isRect:!0,valid:(r=o.valid)!=null?r:!0,attribute:o.attribute,trackID:o==null?void 0:o.trackID}});l&&(i=i.concat(l.map(o=>{var r;return __spreadProps(__spreadValues({},o),{pointList:(r=o==null?void 0:o.pointList)==null?void 0:r.map(d=>lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var o;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return __spreadProps(__spreadValues({},r),{id:i.id,sourceID:"",valid:(o=i.valid)!=null?o:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const L=lbUtils.PointCloudUtils.getDefaultOrthographicParams(t),O=createEmptyImage(t),c=new Image;c.src=O;const h=new scheduler.ToolScheduler({container:e,size:t,toolName:u,proxyMode:v}),f=new CanvasScheduler.CanvasScheduler({container:e}),g=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:L});s&&g.loadPCDFile(s),f.createCanvas(g.renderer.domElement);const C={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},m),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:c,checkMode:I};P&&Object.assign(C,P);let p=[];scheduler.HybridToolUtils.isSingleTool(u)?p=[u]:p=u,p.forEach((a,l)=>{let i;if(a===tool.EToolName.PointCloudPolygon){const o=h.createOperation(a,c,C);o.eventBinding(),o.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=o,this.toolInstance.eventBinding(),this.pointCloud2dOperation=o}else i=h.createOperation(a,c,__spreadProps(__spreadValues({},C),{textConfigurable:!1}));l===p.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=g,this.canvasScheduler=f,this.toolScheduler=h,this.config=m}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(lbUtils.PointCloudUtils.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const e=createEmptyImage(t),s=new Image;s.src=e,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),s=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,s)}addLineListOnTopView(t){const e=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(e)}addPointListOnTopView(t){const e=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(e)}updateData(t,e,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(e),this.addLineListOnTopView(e),this.addPointListOnTopView(e))}switchToCanvas(t){const e=this.toolScheduler.switchToCanvas(t);return e?(this.toolInstance.eventUnbinding(),e.eventBinding(),this.toolInstance=e,e):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
|
package/dist/core/scheduler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,t,o)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,__spreadValues=(i,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(i,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(i,o,t[o]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},arraySwap=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},_HybridToolUtils=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=i=>_HybridToolUtils.isHybridTool(i)?i[i.length-1]:i;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=__spreadProps(__spreadValues({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,t,o)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,__spreadValues=(i,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(i,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(i,o,t[o]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},arraySwap=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},_HybridToolUtils=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=i=>_HybridToolUtils.isHybridTool(i)?i[i.length-1]:i;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=__spreadProps(__spreadValues({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=createEmptyImage({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let s;if(!t)s=new basicToolOperation.BasicToolOperation(h),r.style.zIndex="0",s.init();else{const p=EnhanceCommonToolUtils.getCurrentOperation(t);if(!p)return;s=new p(h)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:d,imgInfo:u})=>{this.syncPosition(p,d,u,s)}),s.on("renderZoom",(p,d,u)=>{p&&d&&this.syncPosition(d,p,u,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=arraySwap(this.toolOperationList,o,e),this.toolOperationDom=arraySwap(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const s=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=arraySwap(this.toolOperationList,r,l),this.toolOperationDom=arraySwap(this.toolOperationDom,r,l),this.toolOperationNameList=arraySwap(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
|
|
@@ -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
|
}
|
package/dist/utils/MathUtils.js
CHANGED
|
@@ -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,
|
|
2
|
-
`);let
|
|
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 +1 @@
|
|
|
1
|
-
import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}
|
|
1
|
+
import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),s=d.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
|
package/es/core/scheduler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as
|
|
1
|
+
import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as w}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as D}from"./toolOperation/basicToolOperation.js";var x=Object.defineProperty,I=Object.defineProperties,M=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,b=(i,t)=>{for(var o in t||(t={}))_.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))E.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>I(i,M(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(b({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:h}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,h),l={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(l,e);let s;if(!t)s=new D(l),r.style.zIndex="0",s.init();else{const p=w(t);if(!p)return;s=new p(l)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const h=this.toolOperationNameList.indexOf(t);if(h<0||this.toolOperationList.length<1||h>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[h],l=this.toolOperationDom[r];if(!c||!l)return;const s=l.style.zIndex;return l.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,h),this.toolOperationDom=d(this.toolOperationDom,r,h),this.toolOperationNameList=d(this.toolOperationNameList,r,h),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
|
package/es/utils/MathUtils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
`);let
|
|
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};
|