@labelbee/lb-annotation 1.27.0-alpha.47 → 1.27.0-alpha.49

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 +1 @@
1
- "use strict";var _=require("lodash"),tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(o=>o.label===r);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const o=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(o,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new Selection(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(t),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const o={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(o);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(o=>{o.id===this.selectedID&&(o.x=n.x,o.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:f,hasClosed:v}=PolygonUtils.getClosestPoint(d,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:g});f&&(d=f),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case tool.EToolName.Rect:{h=!RectUtils.isInRect(d,this.basicResult);break}case tool.EToolName.Polygon:{h=!PolygonUtils.isInPolygon(d,this.basicResult.pointList);break}}if(h)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=__spreadProps(__spreadValues({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,o)))+1});if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.pointList.filter(g=>CommonToolUtils.isSameSourceID(g.sourceID,o)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:h})}if(this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)a=__spreadProps(__spreadValues({},a),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const c=[...this.pointList,a];this.setPointList(c),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(c),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=CommonToolUtils.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let r=[...i];s&&(r=[...r,...s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:o}=i,u=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),a=this.getColor(n),c=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,h=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:u,container:this.container,icon:this.getTextIconSvg(n),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+h,color:c,width:u})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:o}=t,u=e||t.id===this.selectedID,d=this.getColor(o),a=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:h=!1}=this.style,g=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,a,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:g.stroke,fill:g.fill});let f="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),h||DrawUtils.drawText(this.canvas,{x:a.x+c/2,y:a.y-c-4},f,{textAlign:"center",color:g.stroke}),u?this.renderTextAttribute():h||DrawUtils.drawText(this.canvas,{x:a.x+c,y:a.y+c+24},n,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(o=>{const{start:u,end:d}=o,a=AxisUtils.default.changePointListByZoom([u,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:o}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});o&&r!==o&&r!==o&&(r=o,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
1
+ "use strict";var _=require("lodash"),tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(h=>h.label===r);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const h=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(h,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new Selection(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(t.button===2&&this.rightMouseUp(t),this.dragStatus===annotation.EDragStatus.Move){const i=this.pointList.find(s=>(s==null?void 0:s.id)===this.selectedID);if(i){const{newPoint:s,hasClosed:r}=this.getNearPoint(i);s&&Object.assign(i,s),r&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",i,(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0}this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const h={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(h);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(h=>{h.id===this.selectedID&&(h.x=n.x,h.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}getNearPoint(t){var e,i,s;if(this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){const r=[tool.EToolName.Polygon,tool.EToolName.Line].includes(this.dependToolName),n=[this.basicResult];if(r){const h=this.dependToolName===tool.EToolName.Polygon,{dropFoot:a,hasClosed:d}=PolygonUtils.getClosestPoint(t,n,(s=(i=(e=this.referenceData)==null?void 0:e.config)==null?void 0:i.lineType)!=null?s:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:h});return{newPoint:a,hasClosed:d}}}return{newPoint:t,hasClosed:!1}}createPoint(t){if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:e}=this.config;if(e&&this.currentPageResult.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const i=CommonToolUtils.getSourceID(this.basicResult),s=this.getCoordinateUnderZoom(t);let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const{newPoint:n,hasClosed:h}=this.getNearPoint(r);if(n&&(r=n),h&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`),this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let o=!1;switch(this.dependToolName){case tool.EToolName.Rect:{o=!RectUtils.isInRect(r,this.basicResult);break}case tool.EToolName.Polygon:{o=!PolygonUtils.isInPolygon(r,this.basicResult.pointList);break}}if(o)return}if(s.x<0||s.y<0||s.x>this.imgInfo.width||s.y>this.imgInfo.height)return}if(this.isMinDistance(r))return;let a=__spreadProps(__spreadValues({},r),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:i,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,i)))+1});if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.pointList.filter(u=>CommonToolUtils.isSameSourceID(u.sourceID,i)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:o})}if(this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)a=__spreadProps(__spreadValues({},a),{label:o.label}),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const d=[...this.pointList,a];this.setPointList(d),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(d),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=CommonToolUtils.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let r=[...i];s&&(r=[...r,...s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(c=>c.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:h}=i,a=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),o=this.getColor(n),u=h?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,f=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:a,container:this.container,icon:this.getTextIconSvg(n),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+f,color:u,width:a})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:h}=t,a=e||t.id===this.selectedID,d=this.getColor(h),o=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:u=2,hiddenText:f=!1}=this.style,c=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:a||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,o,u,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:c.stroke,fill:c.fill});let g="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),f||DrawUtils.drawText(this.canvas,{x:o.x+u/2,y:o.y-u-4},g,{textAlign:"center",color:c.stroke}),a?this.renderTextAttribute():f||DrawUtils.drawText(this.canvas,{x:o.x+u,y:o.y+u+24},n,__spreadValues({color:c.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(h=>{const{start:a,end:d}=h,o=AxisUtils.default.changePointListByZoom([a,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,o[0],o[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=this.dependToolName===tool.EToolName.Polygon,h=[this.basicResult],{dropFoot:a}=PolygonUtils.getClosestPoint(r,h,(i=(e=(t=this.referenceData)==null?void 0:t.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});a&&r!==a&&r!==a&&(r=a,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
@@ -81,6 +81,10 @@ declare class PointOperation extends BasicToolOperation {
81
81
  onDragMove(e: MouseEvent): void;
82
82
  onKeyDown(e: KeyboardEvent): void;
83
83
  isMinDistance: (coord: ICoordinate) => boolean;
84
+ getNearPoint(coordinate: ICoordinate): {
85
+ newPoint: ICoordinate;
86
+ hasClosed: boolean;
87
+ };
84
88
  createPoint(e: MouseEvent): void;
85
89
  isInPoint(pos: ICoordinate, point: ICoordinate, zoom?: number): boolean;
86
90
  getHoverId(): string | undefined;
@@ -13,6 +13,7 @@ export default class PolygonUtils {
13
13
  */
14
14
  static calcPolygonSize(pointList?: IPolygonPoint[]): number;
15
15
  static isInPolygon(checkPoint: IPolygonPoint, polygonPoints: (IPolygonPoint | ICoordinate)[], lineType?: ELineTypes): boolean;
16
+ static isPointInOrOnPolygon(point: IPolygonPoint, polygonData: (IPolygonPoint | ICoordinate)[], errorMargin?: number): boolean;
16
17
  /**
17
18
  * 通过数据转换为平滑曲线的点提交 [{x: number, y: number}...] => [x, ...smoothCurvePoints ,y]
18
19
  * @param pointList
@@ -1 +1 @@
1
- "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",o=Infinity;const l=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&l.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<o&&(r=s.id,o=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,o,l)=>{const s=l[(o+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,o,l,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,h)=>[...a,h.x,h.y],[]),.5,!0,20)),[l]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(l.x,s.x)&&e.x<=Math.max(l.x,s.x)&&e.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(o=(e.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||e.y<=o)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var o;const l=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),u=(o=e[s])!=null?o:{};return __spreadValues(s===l?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],o=e.slice(0);let l,s,u,a,h,g,P,E,x,m,c,d,f;for(n?(o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.push(e[0]),o.push(e[1])):(o.unshift(e[1]),o.unshift(e[0]),o.push(e[e.length-2]),o.push(e[e.length-1])),f=2;f<o.length-4;f+=2)for(u=(o[f+2]-o[f-2])*t,a=(o[f+4]-o[f-0])*t,h=(o[f+3]-o[f-1])*t,g=(o[f+5]-o[f+1])*t,d=0;d<=i;d++)c=d/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),l=P*o[f]+E*o[f+2]+x*u+m*a,s=P*o[f+1]+E*o[f+3]+x*h+m*g,r.push(l),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=5){let r=[...t];n===tool.ELineTypes.Curve?r=this.createSmoothCurvePoints(t.reduce((s,u)=>[...s,u.x,u.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&r.push(r[0]);let o=-1,l=i;for(let s=0;s<r.length-1;s++){const{length:u}=MathUtils.default.getFootOfPerpendicular(e,r[s],r[s+1],!0);u<l&&(o=s,l=u)}return o===-1?-1:n===tool.ELineTypes.Curve?Math.floor(o/tool.SEGMENT_NUMBER):o}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,r){var o;let l=!1;const s=(o=r==null?void 0:r.isClose)!=null?o:!0;let u="",a=-1,h=Infinity,g=e;const P=20;let E=!1;return t.forEach(x=>{if(!E&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((c,d)=>{if(E)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,c.point1,c.point2);const y=MathUtils.default.getLineLength(c.point1,e),M=MathUtils.default.getLineLength(c.point2,e);y<i*2&&(v=c.point1,f=y,E=!0),M<i*2&&(v=c.point2,f=M,E=!0),f<h&&f<i&&(u=x.id,a=d,h=f,g=v,l=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((c,d)=>[...c,d.x,d.y],[]),.5,s,P);for(let c=0;c<m.length-1;c++){const{length:d,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[c],m[c+1]);d<h&&d<i&&(u=x.id,a=Math.floor(c/(P+1)),h=d,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:a,closestPolygonID:u,hasClosed:l}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const r=e[n].x,o=e[n===e.length-1?0:n+1].y,l=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=r*o*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(a=>[a.x,a.y]))]]),u=turf.difference(r,s);u&&(r=u)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const u=s.length,a=s.filter((h,g)=>{const P=(g+1)%u;return!AxisUtils.default.getIsInScope(h,s[P],1)});return a.length<3?l:[...l,a]},[])}catch(r){console.error(r)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),r=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),o=t[r];let l=[...t.slice(0,r),o,...e,e[0],...t.slice(r,t.length)];return n===i&&(l=[...t.slice(0,r),o,e[0],...e.reverse(),...t.slice(r,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let n,i,r,o=0,l;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,r=(n+2)%t,l=(e[i].x-e[n].x)*(e[r].y-e[i].y),l-=(e[i].y-e[n].y)*(e[r].x-e[i].x),l<0?o--:l>0&&o++;return o>0?1:o<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((r,o)=>{const l=LineToolUtils.default.calcDistance(e,r);l<n&&(n=l,i=o)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(a=>[a.x,a.y]))]]),o=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(a=>[a.x,a.y]))]]),l=turf.union(r,o),s=[],u=e;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const a=l==null?void 0:l.geometry.coordinates.map(h=>{var g;return((g=l==null?void 0:l.geometry)==null?void 0:g.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];u.pointList=a}return{newPolygon:u,unionList:s}}catch(r){console.error(r)}}static composePointList(e,t){let n=0,i=0,r=Number.MAX_VALUE;return e.forEach((o,l)=>{t.forEach((s,u)=>{const a=LineToolUtils.default.calcDistance(o,s);a<r&&(n=l+1,i=u+1,r=a)})}),[...e.slice(0,n),...t.slice(i,t.length),...t.slice(0,i),...e.slice(n,e.length)]}static composeSegmentPolygonList(e){var t,n;const i=[];for(let r=0;r<e.length;r++)for(let o=0;o<e.length;o++){const l=(t=e[r])==null?void 0:t.pointList,s=(n=e[o])==null?void 0:n.pointList;r!==o&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[r].pointList=PolygonUtils.composePointList(l,s),i.unshift(o))}return i.forEach(r=>{e.splice(r,1)}),e}}module.exports=PolygonUtils;
1
+ "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,o=3,i=tool.ELineTypes.Line){let n="",r=Infinity;const l=AxisUtils.default.axisArea(e,o);return t.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(n=s.id,r=u)})}),n}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,o=e.reduce((i,n,r,l)=>{const s=l[(r+1)%t];return i+n.x*s.y-s.x*n.y},0);return Math.abs(o)/2}static isInPolygon(e,t,o=tool.ELineTypes.Line){return t=[...t],o===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(e,t)}static isPointInOrOnPolygon(e,t,o=1e-9){const{x:i,y:n}=e;let r=!1;for(let l=0,s=t.length-1;l<t.length;s=l++){const{x:c,y:u}=t[l],{x:h,y:d}=t[s],y=i<=Math.max(c,h)&&i>=Math.min(c,h)&&n<=Math.max(u,d)&&n>=Math.min(u,d),P=(n-u)*(h-c)-(i-c)*(d-u);if(y&&Math.abs(P)<o)return!0;u>n!=d>n&&i<(h-c)*(n-u)/(d-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!1,t).map((i,n)=>{var r;const l=n/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),c=(r=e[s])!=null?r:{};return __spreadValues(s===l?__spreadValues({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,o=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const n=[],r=e.slice(0);let l,s,c,u,h,d,y,P,m,x,a,g,f;for(o?(r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.push(e[0]),r.push(e[1])):(r.unshift(e[1]),r.unshift(e[0]),r.push(e[e.length-2]),r.push(e[e.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*t,u=(r[f+4]-r[f-0])*t,h=(r[f+3]-r[f-1])*t,d=(r[f+5]-r[f+1])*t,g=0;g<=i;g++)a=g/i,y=2*Math.pow(a,3)-3*Math.pow(a,2)+1,P=-(2*Math.pow(a,3))+3*Math.pow(a,2),m=Math.pow(a,3)-2*Math.pow(a,2)+a,x=Math.pow(a,3)-Math.pow(a,2),l=y*r[f]+P*r[f+2]+m*c+x*u,s=y*r[f+1]+P*r[f+3]+m*h+x*d,n.push(l),n.push(s);const v=[];for(let E=0;E<n.length-1;E+=2)v.push({x:n[E],y:n[E+1]});if(o)for(let E=0;E<i+1;E++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(o=>o.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(o=>t.includes(o.id)):[]}static getHoverEdgeIndex(e,t,o=tool.ELineTypes.Line,i=5){let n=[...t];o===tool.ELineTypes.Curve?n=this.createSmoothCurvePoints(t.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,tool.SEGMENT_NUMBER):o===tool.ELineTypes.Line&&n.push(n[0]);let r=-1,l=i;for(let s=0;s<n.length-1;s++){const{length:c}=MathUtils.default.getFootOfPerpendicular(e,n[s],n[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:o===tool.ELineTypes.Curve?Math.floor(r/tool.SEGMENT_NUMBER):r}static getClosestPoint(e,t,o=tool.ELineTypes.Line,i=3,n){var r;let l=!1;const s=(r=n==null?void 0:n.isClose)!=null?r:!0;let c="",u=-1,h=Infinity,d=e;const y=20;let P=!1;return t.forEach(m=>{if(!P&&!!m.pointList)switch(o){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(m.pointList,s).forEach((a,g)=>{if(P)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,a.point1,a.point2);const E=MathUtils.default.getLineLength(a.point1,e),M=MathUtils.default.getLineLength(a.point2,e);E<i*2&&(v=a.point1,f=E,P=!0),M<i*2&&(v=a.point2,f=M,P=!0),f<h&&f<i&&(c=m.id,u=g,h=f,d=v,l=!0)});break;case tool.ELineTypes.Curve:{const x=this.createSmoothCurvePoints(m.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,y);for(let a=0;a<x.length-1;a++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,x[a],x[a+1]);g<h&&g<i&&(c=m.id,u=Math.floor(a/(y+1)),h=g,d=f,l=!0)}}break}}),{dropFoot:d,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(e,t,o=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,o))}static isPointListOutSidePolygon(e,t,o=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,o))}static getPolygonArea(e){let t=0;for(let o=0,i=e.length;o<i;o++){const n=e[o].x,r=e[o===e.length-1?0:o+1].y,l=e[o===e.length-1?0:o+1].x,s=e[o].y;t+=n*r*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,o){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,o)}static deletePolygonLastPoint(e,t,o,i){return o===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var o,i;try{let n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=turf.difference(n,s);c&&(n=c)}),((i=(o=n==null?void 0:n.geometry)==null?void 0:o.coordinates.map(l=>{var s;return((s=n==null?void 0:n.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,d)=>{const y=(d+1)%c;return!AxisUtils.default.getIsInScope(h,s[y],1)});return u.length<3?l:[...l,u]},[])}catch(n){console.error(n)}}static getPolygonPointList(e,t){const o=t.find(i=>i.id===e);return o&&o.pointList&&o.pointList.length>0?o.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(o=>PolygonUtils.isPointListInPolygon(e,o.pointList))}static clipPolygonFromWrapPolygon(e,t){const o=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),n=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),r=t[n];let l=[...t.slice(0,n),r,...e,e[0],...t.slice(n,t.length)];return o===i&&(l=[...t.slice(0,n),r,e[0],...e.reverse(),...t.slice(n,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let o,i,n,r=0,l;if(t<3)return 0;for(o=0;o<t;o++)i=(o+1)%t,n=(o+2)%t,l=(e[i].x-e[o].x)*(e[n].y-e[i].y),l-=(e[i].y-e[o].y)*(e[n].x-e[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let o=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((n,r)=>{const l=LineToolUtils.default.calcDistance(e,n);l<o&&(o=l,i=r)}),i}static combinePolygonWithPolygon(e,t){var o,i;try{const n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=turf.union(n,r),s=[],c=e;if(((i=(o=l==null?void 0:l.geometry)==null?void 0:o.coordinates)==null?void 0:i.length)===1){s.push(t.id);const u=l==null?void 0:l.geometry.coordinates.map(h=>{var d;return((d=l==null?void 0:l.geometry)==null?void 0:d.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(n){console.error(n)}}static composePointList(e,t){let o=0,i=0,n=Number.MAX_VALUE;return e.forEach((r,l)=>{t.forEach((s,c)=>{const u=LineToolUtils.default.calcDistance(r,s);u<n&&(o=l+1,i=c+1,n=u)})}),[...e.slice(0,o),...t.slice(i,t.length),...t.slice(0,i),...e.slice(o,e.length)]}static composeSegmentPolygonList(e){var t,o;const i=[];for(let n=0;n<e.length;n++)for(let r=0;r<e.length;r++){const l=(t=e[n])==null?void 0:t.pointList,s=(o=e[r])==null?void 0:o.pointList;n!==r&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[n].pointList=PolygonUtils.composePointList(l,s),i.unshift(r))}return i.forEach(n=>{e.splice(n,1)}),e}}module.exports=PolygonUtils;
@@ -1 +1 @@
1
- import U from"lodash";import{EToolName as v,ELineTypes as w,edgeAdsorptionScope as _}from"../../constant/tool.js";import j from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import S from"../../utils/tool/MarkerUtils.js";import z from"../../utils/MathUtils.js";import{EDragStatus as f,ESortDirection as M,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import C from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/StyleUtils.js";import Z from"../../utils/uuid.js";import{BasicToolOperation as H}from"./basicToolOperation.js";import K from"./textAttributeClass.js";import W from"./Selection.js";var F=Object.defineProperty,$=Object.defineProperties,V=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,R=Math.pow,O=(m,t,e)=>t in m?F(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,x=(m,t)=>{for(var e in t||(t={}))X.call(t,e)&&O(m,e,t[e]);if(T)for(var e of T(t))q.call(t,e)&&O(m,e,t[e]);return m},y=(m,t)=>$(m,V(t));const E=200;class G extends H{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(r=>r.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(p.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=c.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const r=c.changePointByZoom(n,this.zoom);return z.getLineLength(r,o)<.2})};var e,i;this.config=a.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new W(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=a.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=a.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return p.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=f.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>y(x({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=f.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:U.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===f.Start||this.dragStatus===f.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(t),this.dragStatus===f.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=f.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=f.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const r={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(r);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===v.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(r=>{r.id===this.selectedID&&(r.x=n.x,r.y=n.y)}),this.render())}onKeyDown(t){if(!a.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case P.Delete:this.deletePoint();break;case P.Tab:{this.onTabKeyDown(t);break}case P.Z:this.setIsHidden(!this.isHidden),this.render();break;case P.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=p.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${C.getMessagesByLocale(A.LowerLimitPoint,this.lang)}`);return}const r=a.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[v.Polygon,v.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===v.Polygon,{dropFoot:I,hasClosed:k}=L.getClosestPoint(d,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:w.Line,_/this.zoom,{isClose:b});I&&(d=I),k&&this.emit("messageSuccess",`${C.getMessagesByLocale(A.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let l=!1;switch(this.dependToolName){case v.Rect:{l=!j.isInRect(d,this.basicResult);break}case v.Polygon:{l=!L.isInPolygon(d,this.basicResult.pointList);break}}if(l)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let h=y(x({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:Z(8,62),sourceID:r,textAttribute:"",order:a.getMaxOrder(this.pointList.filter(l=>a.isSameSourceID(l.sourceID,r)))+1});if(this.config.textConfigurable){let l="";l=p.getTextAttribute(this.pointList.filter(b=>a.isSameSourceID(b.sourceID,r)),this.config.textCheckType),h=y(x({},h),{textAttribute:l})}if(this.hasMarkerConfig){const l=a.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(l)h=y(x({},h),{label:l.label}),this.markerIndex=l.index,this.emit("markIndexChange");else{this.emit("messageInfo",C.getMessagesByLocale(A.MarkerFinish,this.lang));return}}this.hoverID=h.id;const g=[...this.pointList,h];this.setPointList(g),this.emit("pointCreated",h,this.zoom),this.history.pushHistory(g),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(R(t.x-e.x,2)+R(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=a.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===f.Move||this.dragStatus===f.Start)return;let e=M.ascend;t.shiftKey&&(e=M.descend);const[i,s]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let o=[...i];s&&(o=[...o,...s]);const n=a.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=a.getRenderResultList(t,a.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===f.Move||this.dragStatus===f.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=f.Wait,{width:E*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(p.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:r}=i,u=E*this.zoom*.6,d=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),h=this.getColor(n),g=r?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,l=4;this._textAttributeInstance||(this._textAttributeInstance=new K({width:u,container:this.container,icon:this.getTextIconSvg(n),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+l,color:g,width:u})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:r}=t,u=e||t.id===this.selectedID,d=this.getColor(r),h=c.changePointByZoom(t,this.zoom,this.currentPos),{width:g=2,hiddenText:l=!1}=this.style,b=B.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});D.drawCircle(this.canvas,h,g,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let I="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(I=`${t.order}`),t.label&&this.hasMarkerConfig&&(I=`${a.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${S.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(I=`${I} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),l||D.drawText(this.canvas,{x:h.x+g/2,y:h.y-g-4},I,{textAlign:"center",color:b.stroke}),u?this.renderTextAttribute():l||D.drawText(this.canvas,{x:h.x+g,y:h.y+g+24},n,x({color:b.stroke},N))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const o=S.getAuxiliaryLineByMarkerList(this.config.markerList,"value");S.getAuxiliaryLineCoord(o,s).forEach(r=>{const{start:u,end:d}=r,h=c.changePointListByZoom([u,d],this.zoom,this.currentPos);D.drawLine(this.canvas,h[0],h[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===v.Polygon,{dropFoot:r}=L.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:w.Line,_/this.zoom,{isClose:n});r&&o!==r&&o!==r&&(o=r,D.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),D.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{G as default};
1
+ import E from"lodash";import{EToolName as b,ELineTypes as w,edgeAdsorptionScope as k}from"../../constant/tool.js";import U from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/MarkerUtils.js";import j from"../../utils/MathUtils.js";import{EDragStatus as c,ESortDirection as _,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import y from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import m from"../../utils/tool/AttributeUtils.js";import d from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/CommonToolUtils.js";import I from"../../utils/tool/DrawUtils.js";import z from"../../utils/tool/StyleUtils.js";import B from"../../utils/uuid.js";import{BasicToolOperation as Z}from"./basicToolOperation.js";import H from"./textAttributeClass.js";import K from"./Selection.js";var W=Object.defineProperty,$=Object.defineProperties,F=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,R=(g,t,e)=>t in g?W(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,x=(g,t)=>{for(var e in t||(t={}))V.call(t,e)&&R(g,e,t[e]);if(T)for(var e of T(t))X.call(t,e)&&R(g,e,t[e]);return g},C=(g,t)=>$(g,F(t));const O=200;class q extends Z{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(l=>l.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(m.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=d.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const l=d.changePointByZoom(n,this.zoom);return j.getLineLength(l,o)<.2})};var e,i;this.config=a.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new K(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=a.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=a.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return m.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=c.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>C(x({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=c.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:E.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===c.Start||this.dragStatus===c.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(t.button===2&&this.rightMouseUp(t),this.dragStatus===c.Move){const i=this.pointList.find(s=>(s==null?void 0:s.id)===this.selectedID);if(i){const{newPoint:s,hasClosed:o}=this.getNearPoint(i);s&&Object.assign(i,s),o&&this.emit("messageSuccess",`${y.getMessagesByLocale(S.SuccessfulEdgeAdsorption,this.lang)}`)}this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",i,(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0}this.dragStatus=c.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=c.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const l={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(l);return}const o=d.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):d.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===b.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(l=>{l.id===this.selectedID&&(l.x=n.x,l.y=n.y)}),this.render())}onKeyDown(t){if(!a.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case P.Delete:this.deletePoint();break;case P.Tab:{this.onTabKeyDown(t);break}case P.Z:this.setIsHidden(!this.isHidden),this.render();break;case P.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=m.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}getNearPoint(t){var e,i,s;if(this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){const o=[b.Polygon,b.Line].includes(this.dependToolName),n=[this.basicResult];if(o){const l=this.dependToolName===b.Polygon,{dropFoot:h,hasClosed:u}=L.getClosestPoint(t,n,(s=(i=(e=this.referenceData)==null?void 0:e.config)==null?void 0:i.lineType)!=null?s:w.Line,k/this.zoom,{isClose:l});return{newPoint:h,hasClosed:u}}}return{newPoint:t,hasClosed:!1}}createPoint(t){if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:e}=this.config;if(e&&this.currentPageResult.length>=e){this.emit("messageInfo",`${y.getMessagesByLocale(S.LowerLimitPoint,this.lang)}`);return}const i=a.getSourceID(this.basicResult),s=this.getCoordinateUnderZoom(t);let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const{newPoint:n,hasClosed:l}=this.getNearPoint(o);if(n&&(o=n),l&&this.emit("messageSuccess",`${y.getMessagesByLocale(S.SuccessfulEdgeAdsorption,this.lang)}`),this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let r=!1;switch(this.dependToolName){case b.Rect:{r=!U.isInRect(o,this.basicResult);break}case b.Polygon:{r=!L.isInPolygon(o,this.basicResult.pointList);break}}if(r)return}if(s.x<0||s.y<0||s.x>this.imgInfo.width||s.y>this.imgInfo.height)return}if(this.isMinDistance(o))return;let h=C(x({},o),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:B(8,62),sourceID:i,textAttribute:"",order:a.getMaxOrder(this.pointList.filter(r=>a.isSameSourceID(r.sourceID,i)))+1});if(this.config.textConfigurable){let r="";r=m.getTextAttribute(this.pointList.filter(f=>a.isSameSourceID(f.sourceID,i)),this.config.textCheckType),h=C(x({},h),{textAttribute:r})}if(this.hasMarkerConfig){const r=a.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(r)h=C(x({},h),{label:r.label}),this.markerIndex=r.index,this.emit("markIndexChange");else{this.emit("messageInfo",y.getMessagesByLocale(S.MarkerFinish,this.lang));return}}this.hoverID=h.id;const u=[...this.pointList,h];this.setPointList(u),this.emit("pointCreated",h,this.zoom),this.history.pushHistory(u),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(M(t.x-e.x,2)+M(t.y-e.y,2))}getHoverId(){var t;const e=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=a.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===c.Move||this.dragStatus===c.Start)return;let e=_.ascend;t.shiftKey&&(e=_.descend);const[i,s]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let o=[...i];s&&(o=[...o,...s]);const n=a.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=a.getRenderResultList(t,a.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===c.Move||this.dragStatus===c.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=c.Wait,{width:O*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;m.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",m.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(m.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(p=>p.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:l}=i,h=O*this.zoom*.6,u=d.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),r=this.getColor(n),f=l?r==null?void 0:r.valid.stroke:r==null?void 0:r.invalid.stroke,D=4;this._textAttributeInstance||(this._textAttributeInstance=new H({width:h,container:this.container,icon:this.getTextIconSvg(n),color:f,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:u.x,top:u.y+D,color:f,width:h})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:l}=t,h=e||t.id===this.selectedID,u=this.getColor(l),r=d.changePointByZoom(t,this.zoom,this.currentPos),{width:f=2,hiddenText:D=!1}=this.style,p=z.getStrokeAndFill(u,t.valid,{isSelected:h||t.id===this.hoverID});I.drawCircle(this.canvas,r,f,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:p.stroke,fill:p.fill});let v="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(v=`${t.order}`),t.label&&this.hasMarkerConfig&&(v=`${a.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${A.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(v=`${v} ${m.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),D||I.drawText(this.canvas,{x:r.x+f/2,y:r.y-f-4},v,{textAlign:"center",color:p.stroke}),h?this.renderTextAttribute():D||I.drawText(this.canvas,{x:r.x+f,y:r.y+f+24},n,x({color:p.stroke},N))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const o=A.getAuxiliaryLineByMarkerList(this.config.markerList,"value");A.getAuxiliaryLineCoord(o,s).forEach(l=>{const{start:h,end:u}=l,r=d.changePointListByZoom([h,u],this.zoom,this.currentPos);I.drawLine(this.canvas,r[0],r[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=this.dependToolName===b.Polygon,l=[this.basicResult],{dropFoot:h}=L.getClosestPoint(o,l,(i=(e=(t=this.referenceData)==null?void 0:t.config)==null?void 0:e.lineType)!=null?i:w.Line,k/this.zoom,{isClose:n});h&&o!==h&&o!==h&&(o=h,I.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),I.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{q as default};
@@ -1 +1 @@
1
- import{polygon as A,difference as B,union as O}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import N from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as p}from"../../constant/tool.js";import D from"./AxisUtils.js";import L from"../MathUtils.js";import b from"./LineToolUtils.js";var z=Object.defineProperty,_=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,j=(M,t,e)=>t in M?z(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,S=(M,t)=>{for(var e in t||(t={}))R.call(t,e)&&j(M,e,t[e]);if(_)for(var e of _(t))T.call(t,e)&&j(M,e,t[e]);return M};class h{static getHoverPolygonID(t,e,n=3,i=y.Line){let o="",r=Infinity;const l=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(o=s.id,r=u)})}),o}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,o,r,l)=>{const s=l[(r+1)%e];return i+o.x*s.y-s.x*o.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,o,r,l,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,d)=>[...u,d.x,d.y],[]),.5,!0,20)),[l]=e;const c=e.length;for(o=1;o<=c;o++)s=e[o%c],t.x>Math.min(l.x,s.x)&&t.x<=Math.max(l.x,s.x)&&t.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(r=(t.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||t.y<=r)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=p){return this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,e).map((i,o)=>{var r;const l=o/(p+1),s=Math.floor(l),c=(r=t[s])!=null?r:{};return S(s===l?S({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=p){if(t.length<4)return t;const o=[],r=t.slice(0);let l,s,c,u,d,m,v,E,P,I,a,g,f;for(n?(r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.push(t[0]),r.push(t[1])):(r.unshift(t[1]),r.unshift(t[0]),r.push(t[t.length-2]),r.push(t[t.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*e,u=(r[f+4]-r[f-0])*e,d=(r[f+3]-r[f-1])*e,m=(r[f+5]-r[f+1])*e,g=0;g<=i;g++)a=g/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,E=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,I=Math.pow(a,3)-Math.pow(a,2),l=v*r[f]+E*r[f+2]+P*c+I*u,s=v*r[f+1]+E*r[f+3]+P*d+I*m,o.push(l),o.push(s);const C=[];for(let x=0;x<o.length-1;x+=2)C.push({x:o[x],y:o[x+1]});if(n)for(let x=0;x<i+1;x++){const w=C.shift();C.push(w)}return C}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(n=>e.includes(n.id)):[]}static getHoverEdgeIndex(t,e,n=y.Line,i=5){let o=[...e];n===y.Curve?o=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,p):n===y.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=L.getFootOfPerpendicular(t,o[s],o[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:n===y.Curve?Math.floor(r/p):r}static getClosestPoint(t,e,n=y.Line,i=3,o){var r;let l=!1;const s=(r=o==null?void 0:o.isClose)!=null?r:!0;let c="",u=-1,d=Infinity,m=t;const v=20;let E=!1;return e.forEach(P=>{if(!E&&!!P.pointList)switch(n){case y.Line:N.findAllLine(P.pointList,s).forEach((a,g)=>{if(E)return;let{length:f,footPoint:C}=L.getFootOfPerpendicular(t,a.point1,a.point2);const x=L.getLineLength(a.point1,t),w=L.getLineLength(a.point2,t);x<i*2&&(C=a.point1,f=x,E=!0),w<i*2&&(C=a.point2,f=w,E=!0),f<d&&f<i&&(c=P.id,u=g,d=f,m=C,l=!0)});break;case y.Curve:{const I=this.createSmoothCurvePoints(P.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,v);for(let a=0;a<I.length-1;a++){const{length:g,footPoint:f}=L.getFootOfPerpendicular(t,I[a],I[a+1]);g<d&&g<i&&(c=P.id,u=Math.floor(a/(v+1)),d=g,m=f,l=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,n=y.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=y.Line){return t.some(i=>!this.isInPolygon(i,e,n))}static getPolygonArea(t){let e=0;for(let n=0,i=t.length;n<i;n++){const o=t[n].x,r=t[n===t.length-1?0:n+1].y,l=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=o*r*.5,e-=l*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===F.Anticlockwise&&(i=-1),i*=e,L.rotateRectPointList(i,n)}static deletePolygonLastPoint(t,e,n,i){return n===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var n,i;try{let o=A([[...h.concatBeginAndEnd(t.map(l=>[l.x,l.y]))]]);return e.forEach(l=>{const s=A([[...h.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=B(o,s);c&&(o=c)}),((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=o==null?void 0:o.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(h.deletePolygonLastPoint,[]):l.reduce(h.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((d,m)=>{const v=(m+1)%c;return!D.getIsInScope(d,s[v],1)});return u.length<3?l:[...l,u]},[])}catch(o){console.error(o)}}static getPolygonPointList(t,e){const n=e.find(i=>i.id===t);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(n=>h.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=h.isPolygonClosewise(e),i=h.isPolygonClosewise(t),o=h.getClosePointDistanceFromPolygon(t[0],e),r=e[o];let l=[...e.slice(0,o),r,...t,t[0],...e.slice(o,e.length)];return n===i&&(l=[...e.slice(0,o),r,t[0],...t.reverse(),...e.slice(o,e.length)]),l}static isPolygonClosewise(t){const e=t.length;let n,i,o,r=0,l;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,o=(n+2)%e,l=(t[i].x-t[n].x)*(t[o].y-t[i].y),l-=(t[i].y-t[n].y)*(t[o].x-t[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((o,r)=>{const l=b.calcDistance(t,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const o=A([[...h.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),r=A([[...h.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),l=O(o,r),s=[],c=t;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=l==null?void 0:l.geometry.coordinates.map(d=>{var m;return((m=l==null?void 0:l.geometry)==null?void 0:m.type)==="MultiPolygon"?d[0].reduce(h.deletePolygonLastPoint,[]):d.reduce(h.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(o){console.error(o)}}static composePointList(t,e){let n=0,i=0,o=Number.MAX_VALUE;return t.forEach((r,l)=>{e.forEach((s,c)=>{const u=b.calcDistance(r,s);u<o&&(n=l+1,i=c+1,o=u)})}),[...t.slice(0,n),...e.slice(i,e.length),...e.slice(0,i),...t.slice(n,t.length)]}static composeSegmentPolygonList(t){var e,n;const i=[];for(let o=0;o<t.length;o++)for(let r=0;r<t.length;r++){const l=(e=t[o])==null?void 0:e.pointList,s=(n=t[r])==null?void 0:n.pointList;o!==r&&l&&s&&h.isPointListInPolygon(s,l)&&(t[o].pointList=h.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{t.splice(o,1)}),t}}export{h as default};
1
+ import{polygon as S,difference as _,union as B}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import N from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as p}from"../../constant/tool.js";import b from"./AxisUtils.js";import L from"../MathUtils.js";import O from"./LineToolUtils.js";var z=Object.defineProperty,j=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,D=(C,t,e)=>t in C?z(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,A=(C,t)=>{for(var e in t||(t={}))R.call(t,e)&&D(C,e,t[e]);if(j)for(var e of j(t))k.call(t,e)&&D(C,e,t[e]);return C};class d{static getHoverPolygonID(t,e,o=3,i=y.Line){let n="",r=Infinity;const l=b.axisArea(t,o);return e.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(n=s.id,r=u)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,o=t.reduce((i,n,r,l)=>{const s=l[(r+1)%e];return i+n.x*s.y-s.x*n.y},0);return Math.abs(o)/2}static isInPolygon(t,e,o=y.Line){return e=[...e],o===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(t,e)}static isPointInOrOnPolygon(t,e,o=1e-9){const{x:i,y:n}=t;let r=!1;for(let l=0,s=e.length-1;l<e.length;s=l++){const{x:c,y:u}=e[l],{x:h,y:g}=e[s],P=i<=Math.max(c,h)&&i>=Math.min(c,h)&&n<=Math.max(u,g)&&n>=Math.min(u,g),x=(n-u)*(h-c)-(i-c)*(g-u);if(P&&Math.abs(x)<o)return!0;u>n!=g>n&&i<(h-c)*(n-u)/(g-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(t,e=p){return this.createSmoothCurvePoints(t.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!1,e).map((i,n)=>{var r;const l=n/(p+1),s=Math.floor(l),c=(r=t[s])!=null?r:{};return A(s===l?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,o=!1,i=p){if(t.length<4)return t;const n=[],r=t.slice(0);let l,s,c,u,h,g,P,x,v,I,a,m,f;for(o?(r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.push(t[0]),r.push(t[1])):(r.unshift(t[1]),r.unshift(t[0]),r.push(t[t.length-2]),r.push(t[t.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*e,u=(r[f+4]-r[f-0])*e,h=(r[f+3]-r[f-1])*e,g=(r[f+5]-r[f+1])*e,m=0;m<=i;m++)a=m/i,P=2*Math.pow(a,3)-3*Math.pow(a,2)+1,x=-(2*Math.pow(a,3))+3*Math.pow(a,2),v=Math.pow(a,3)-2*Math.pow(a,2)+a,I=Math.pow(a,3)-Math.pow(a,2),l=P*r[f]+x*r[f+2]+v*c+I*u,s=P*r[f+1]+x*r[f+3]+v*h+I*g,n.push(l),n.push(s);const M=[];for(let E=0;E<n.length-1;E+=2)M.push({x:n[E],y:n[E+1]});if(o)for(let E=0;E<i+1;E++){const w=M.shift();M.push(w)}return M}static getPolygonByID(t,e){return t.find(o=>o.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(o=>e.includes(o.id)):[]}static getHoverEdgeIndex(t,e,o=y.Line,i=5){let n=[...e];o===y.Curve?n=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,p):o===y.Line&&n.push(n[0]);let r=-1,l=i;for(let s=0;s<n.length-1;s++){const{length:c}=L.getFootOfPerpendicular(t,n[s],n[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:o===y.Curve?Math.floor(r/p):r}static getClosestPoint(t,e,o=y.Line,i=3,n){var r;let l=!1;const s=(r=n==null?void 0:n.isClose)!=null?r:!0;let c="",u=-1,h=Infinity,g=t;const P=20;let x=!1;return e.forEach(v=>{if(!x&&!!v.pointList)switch(o){case y.Line:N.findAllLine(v.pointList,s).forEach((a,m)=>{if(x)return;let{length:f,footPoint:M}=L.getFootOfPerpendicular(t,a.point1,a.point2);const E=L.getLineLength(a.point1,t),w=L.getLineLength(a.point2,t);E<i*2&&(M=a.point1,f=E,x=!0),w<i*2&&(M=a.point2,f=w,x=!0),f<h&&f<i&&(c=v.id,u=m,h=f,g=M,l=!0)});break;case y.Curve:{const I=this.createSmoothCurvePoints(v.pointList.reduce((a,m)=>[...a,m.x,m.y],[]),.5,s,P);for(let a=0;a<I.length-1;a++){const{length:m,footPoint:f}=L.getFootOfPerpendicular(t,I[a],I[a+1]);m<h&&m<i&&(c=v.id,u=Math.floor(a/(P+1)),h=m,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,o=y.Line){return t.every(i=>this.isInPolygon(i,e,o))}static isPointListOutSidePolygon(t,e,o=y.Line){return t.some(i=>!this.isInPolygon(i,e,o))}static getPolygonArea(t){let e=0;for(let o=0,i=t.length;o<i;o++){const n=t[o].x,r=t[o===t.length-1?0:o+1].y,l=t[o===t.length-1?0:o+1].x,s=t[o].y;e+=n*r*.5,e-=l*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,o){let i=1;return t===F.Anticlockwise&&(i=-1),i*=e,L.rotateRectPointList(i,o)}static deletePolygonLastPoint(t,e,o,i){return o===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var o,i;try{let n=S([[...d.concatBeginAndEnd(t.map(l=>[l.x,l.y]))]]);return e.forEach(l=>{const s=S([[...d.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=_(n,s);c&&(n=c)}),((i=(o=n==null?void 0:n.geometry)==null?void 0:o.coordinates.map(l=>{var s;return((s=n==null?void 0:n.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(d.deletePolygonLastPoint,[]):l.reduce(d.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,g)=>{const P=(g+1)%c;return!b.getIsInScope(h,s[P],1)});return u.length<3?l:[...l,u]},[])}catch(n){console.error(n)}}static getPolygonPointList(t,e){const o=e.find(i=>i.id===t);return o&&o.pointList&&o.pointList.length>0?o.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(o=>d.isPointListInPolygon(t,o.pointList))}static clipPolygonFromWrapPolygon(t,e){const o=d.isPolygonClosewise(e),i=d.isPolygonClosewise(t),n=d.getClosePointDistanceFromPolygon(t[0],e),r=e[n];let l=[...e.slice(0,n),r,...t,t[0],...e.slice(n,e.length)];return o===i&&(l=[...e.slice(0,n),r,t[0],...t.reverse(),...e.slice(n,e.length)]),l}static isPolygonClosewise(t){const e=t.length;let o,i,n,r=0,l;if(e<3)return 0;for(o=0;o<e;o++)i=(o+1)%e,n=(o+2)%e,l=(t[i].x-t[o].x)*(t[n].y-t[i].y),l-=(t[i].y-t[o].y)*(t[n].x-t[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let o=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((n,r)=>{const l=O.calcDistance(t,n);l<o&&(o=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var o,i;try{const n=S([[...d.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),r=S([[...d.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),l=B(n,r),s=[],c=t;if(((i=(o=l==null?void 0:l.geometry)==null?void 0:o.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=l==null?void 0:l.geometry.coordinates.map(h=>{var g;return((g=l==null?void 0:l.geometry)==null?void 0:g.type)==="MultiPolygon"?h[0].reduce(d.deletePolygonLastPoint,[]):h.reduce(d.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(n){console.error(n)}}static composePointList(t,e){let o=0,i=0,n=Number.MAX_VALUE;return t.forEach((r,l)=>{e.forEach((s,c)=>{const u=O.calcDistance(r,s);u<n&&(o=l+1,i=c+1,n=u)})}),[...t.slice(0,o),...e.slice(i,e.length),...e.slice(0,i),...t.slice(o,t.length)]}static composeSegmentPolygonList(t){var e,o;const i=[];for(let n=0;n<t.length;n++)for(let r=0;r<t.length;r++){const l=(e=t[n])==null?void 0:e.pointList,s=(o=t[r])==null?void 0:o.pointList;n!==r&&l&&s&&d.isPointListInPolygon(s,l)&&(t[n].pointList=d.composePointList(l,s),i.unshift(r))}return i.forEach(n=>{t.splice(n,1)}),t}}export{d as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.27.0-alpha.47",
3
+ "version": "1.27.0-alpha.49",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",