@labelbee/lb-annotation 1.14.0-alpha.1 → 1.14.0-alpha.3

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.
Files changed (190) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/annotation.d.ts +3 -1
  66. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  68. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  69. package/dist/types/core/toolOperation/LineToolOperation.d.ts +11 -0
  70. package/dist/types/utils/tool/DrawUtils.d.ts +0 -2
  71. package/dist/utils/ActionsHistory.js +84 -1
  72. package/dist/utils/ImgUtils.js +23 -1
  73. package/dist/utils/MathUtils.js +385 -2
  74. package/dist/utils/VectorUtils.js +25 -1
  75. package/dist/utils/tool/AttributeUtils.js +218 -1
  76. package/dist/utils/tool/AxisUtils.js +340 -1
  77. package/dist/utils/tool/CanvasUtils.js +62 -1
  78. package/dist/utils/tool/CommonToolUtils.js +174 -1
  79. package/dist/utils/tool/CuboidUtils.js +704 -1
  80. package/dist/utils/tool/DblClickEventListener.js +102 -1
  81. package/dist/utils/tool/DrawUtils.js +492 -3
  82. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  83. package/dist/utils/tool/ImgPosUtils.js +58 -1
  84. package/dist/utils/tool/LineToolUtils.js +261 -1
  85. package/dist/utils/tool/MarkerUtils.js +56 -1
  86. package/dist/utils/tool/PolygonUtils.js +460 -1
  87. package/dist/utils/tool/RectUtils.js +155 -1
  88. package/dist/utils/tool/RenderDomClass.js +57 -7
  89. package/dist/utils/tool/RenderDomUtils.js +21 -4
  90. package/dist/utils/tool/StyleUtils.js +31 -1
  91. package/dist/utils/tool/TagUtils.js +129 -1
  92. package/dist/utils/tool/UnitUtils.js +12 -1
  93. package/dist/utils/tool/ZoomUtils.js +72 -1
  94. package/dist/utils/tool/polygonTool.js +133 -1
  95. package/dist/utils/uuid.js +26 -1
  96. package/es/_virtual/MathUtilsWorker.js +6 -1
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  99. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  100. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  101. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  102. package/es/_virtual/filterBoxWorker.js +6 -1
  103. package/es/_virtual/highlightWorker.js +6 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  112. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  113. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  114. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  116. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  117. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  118. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  119. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  121. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  122. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  123. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  124. package/es/constant/annotation.js +113 -1
  125. package/es/constant/annotationTask.js +25 -1
  126. package/es/constant/defaultConfig.js +260 -1
  127. package/es/constant/keyCode.js +36 -1
  128. package/es/constant/style.js +74 -1
  129. package/es/constant/tool.js +220 -1
  130. package/es/core/index.js +148 -1
  131. package/es/core/pointCloud/OrbitControls.js +661 -1
  132. package/es/core/pointCloud/PCDLoader.js +256 -2
  133. package/es/core/pointCloud/annotation.js +211 -1
  134. package/es/core/pointCloud/cache.js +49 -1
  135. package/es/core/pointCloud/index.js +962 -5
  136. package/es/core/pointCloud/matrix.js +109 -1
  137. package/es/core/pointCloud/segmentation.js +120 -0
  138. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  139. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  140. package/es/core/scheduler.js +228 -1
  141. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  142. package/es/core/toolOperation/ScribbleTool.js +290 -1
  143. package/es/core/toolOperation/TextToolOperation.js +129 -1
  144. package/es/core/toolOperation/ViewOperation.js +549 -1
  145. package/es/core/toolOperation/basicToolOperation.js +877 -1
  146. package/es/core/toolOperation/checkOperation.js +206 -1
  147. package/es/core/toolOperation/cuboidOperation.js +752 -1
  148. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  149. package/es/core/toolOperation/eventListener.js +35 -1
  150. package/es/core/toolOperation/measureOperation.js +39 -1
  151. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  152. package/es/core/toolOperation/pointOperation.js +690 -1
  153. package/es/core/toolOperation/polygonOperation.js +1245 -1
  154. package/es/core/toolOperation/rectOperation.js +1228 -1
  155. package/es/core/toolOperation/scribbleTool2.js +249 -0
  156. package/es/core/toolOperation/segmentByRect.js +172 -1
  157. package/es/core/toolOperation/tagOperation.js +199 -3
  158. package/es/core/toolOperation/textAttributeClass.js +180 -16
  159. package/es/index.js +46 -1
  160. package/es/locales/constants.js +22 -1
  161. package/es/locales/en_US/message.js +23 -1
  162. package/es/locales/index.js +17 -1
  163. package/es/locales/zh_CN/message.js +23 -1
  164. package/es/newCore/CanvasScheduler.js +31 -1
  165. package/es/utils/ActionsHistory.js +78 -1
  166. package/es/utils/ImgUtils.js +21 -1
  167. package/es/utils/MathUtils.js +380 -2
  168. package/es/utils/VectorUtils.js +23 -1
  169. package/es/utils/tool/AttributeUtils.js +212 -1
  170. package/es/utils/tool/AxisUtils.js +335 -1
  171. package/es/utils/tool/CanvasUtils.js +60 -1
  172. package/es/utils/tool/CommonToolUtils.js +172 -1
  173. package/es/utils/tool/CuboidUtils.js +680 -1
  174. package/es/utils/tool/DblClickEventListener.js +100 -1
  175. package/es/utils/tool/DrawUtils.js +490 -3
  176. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  177. package/es/utils/tool/ImgPosUtils.js +56 -1
  178. package/es/utils/tool/LineToolUtils.js +255 -1
  179. package/es/utils/tool/MarkerUtils.js +54 -1
  180. package/es/utils/tool/PolygonUtils.js +458 -1
  181. package/es/utils/tool/RectUtils.js +153 -1
  182. package/es/utils/tool/RenderDomClass.js +55 -7
  183. package/es/utils/tool/RenderDomUtils.js +19 -4
  184. package/es/utils/tool/StyleUtils.js +29 -1
  185. package/es/utils/tool/TagUtils.js +127 -1
  186. package/es/utils/tool/UnitUtils.js +10 -1
  187. package/es/utils/tool/ZoomUtils.js +70 -1
  188. package/es/utils/tool/polygonTool.js +126 -1
  189. package/es/utils/uuid.js +24 -1
  190. package/package.json +7 -5
@@ -1 +1,458 @@
1
- import{polygon as S,difference as _,union as j}from"@turf/turf";import{ERotateDirection as B}from"../../constant/annotation.js";import F from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as M}from"../../constant/tool.js";import D from"./AxisUtils.js";import C from"../MathUtils.js";import z from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,O=(p,t,e)=>t in p?N(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,A=(p,t)=>{for(var e in t||(t={}))R.call(t,e)&&O(p,e,t[e]);if(b)for(var e of b(t))T.call(t,e)&&O(p,e,t[e]);return p};class g{static getHoverPolygonID(t,e,n=3,i=y.Line){let r="",l=Infinity;const o=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&o.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<l&&(r=s.id,l=u)})}),r}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,r,l,o)=>{const s=o[(l+1)%e];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,r,l,o,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,h)=>[...u,h.x,h.y],[]),.5,!0,20)),[o]=e;const c=e.length;for(r=1;r<=c;r++)s=e[r%c],t.x>Math.min(o.x,s.x)&&t.x<=Math.max(o.x,s.x)&&t.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(t.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||t.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=M){return this.createSmoothCurvePoints(t.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,e).map((i,r)=>{var l;const o=r/(M+1),s=Math.floor(o),c=(l=t[s])!=null?l:{};return A(s===o?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=M){if(t.length<4)return t;const r=[],l=t.slice(0);let o,s,c,u,h,m,v,L,P,E,a,d,f;for(n?(l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.push(t[0]),l.push(t[1])):(l.unshift(t[1]),l.unshift(t[0]),l.push(t[t.length-2]),l.push(t[t.length-1])),f=2;f<l.length-4;f+=2)for(c=(l[f+2]-l[f-2])*e,u=(l[f+4]-l[f-0])*e,h=(l[f+3]-l[f-1])*e,m=(l[f+5]-l[f+1])*e,d=0;d<=i;d++)a=d/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,L=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,E=Math.pow(a,3)-Math.pow(a,2),o=v*l[f]+L*l[f+2]+P*c+E*u,s=v*l[f+1]+L*l[f+3]+P*h+E*m,r.push(o),r.push(s);const I=[];for(let x=0;x<r.length-1;x+=2)I.push({x:r[x],y:r[x+1]});if(n)for(let x=0;x<i+1;x++){const w=I.shift();I.push(w)}return I}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){if(e&&(e==null?void 0:e.length)>0)return t.filter(n=>e.includes(n.id))}static getHoverEdgeIndex(t,e,n=y.Line,i=3){let r=[...e];n===y.Curve?r=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,M):n===y.Line&&r.push(r[0]);let l=-1,o=i;for(let s=0;s<r.length-1;s++){const{length:c}=C.getFootOfPerpendicular(t,r[s],r[s+1]);c<o&&(l=s,o=c)}return l===-1?-1:n===y.Curve?Math.floor(l/M):l}static getClosestPoint(t,e,n=y.Line,i=3,r){var l;let o=!1;const s=(l=r==null?void 0:r.isClose)!=null?l:!0;let c="",u=-1,h=Infinity,m=t;const v=20;let L=!1;return e.forEach(P=>{if(!L&&!!P.pointList)switch(n){case y.Line:F.findAllLine(P.pointList,s).forEach((a,d)=>{if(L)return;let{length:f,footPoint:I}=C.getFootOfPerpendicular(t,a.point1,a.point2);const x=C.getLineLength(a.point1,t),w=C.getLineLength(a.point2,t);x<i*2&&(I=a.point1,f=x,L=!0),w<i*2&&(I=a.point2,f=w,L=!0),f<h&&f<i&&(c=P.id,u=d,h=f,m=I,o=!0)});break;case y.Curve:{const E=this.createSmoothCurvePoints(P.pointList.reduce((a,d)=>[...a,d.x,d.y],[]),.5,s,v);for(let a=0;a<E.length-1;a++){const{length:d,footPoint:f}=C.getFootOfPerpendicular(t,E[a],E[a+1]);d<h&&d<i&&(c=P.id,u=Math.floor(a/(v+1)),h=d,m=f,o=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:o}}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 r=t[n].x,l=t[n===t.length-1?0:n+1].y,o=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=r*l*.5,e-=o*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===B.Anticlockwise&&(i=-1),i*=e,C.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 r=S([[...g.concatBeginAndEnd(t.map(o=>[o.x,o.y]))]]);return e.forEach(o=>{const s=S([[...g.concatBeginAndEnd(o.pointList.map(u=>[u.x,u.y]))]]),c=_(r,s);c&&(r=c)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(o=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?o[0].reduce(g.deletePolygonLastPoint,[]):o.reduce(g.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((o,s)=>{const c=s.length,u=s.filter((h,m)=>{const v=(m+1)%c;return!D.getIsInScope(h,s[v],1)});return u.length<3?o:[...o,u]},[])}catch(r){console.error(r)}}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=>g.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=g.isPolygonClosewise(e),i=g.isPolygonClosewise(t),r=g.getClosePointDistanceFromPolygon(t[0],e),l=e[r];let o=[...e.slice(0,r),l,...t,t[0],...e.slice(r,e.length)];return n===i&&(o=[...e.slice(0,r),l,t[0],...t.reverse(),...e.slice(r,e.length)]),o}static isPolygonClosewise(t){const e=t.length;let n,i,r,l=0,o;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,r=(n+2)%e,o=(t[i].x-t[n].x)*(t[r].y-t[i].y),o-=(t[i].y-t[n].y)*(t[r].x-t[i].x),o<0?l--:o>0&&l++;return l>0?1:l<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((r,l)=>{const o=z.calcDistance(t,r);o<n&&(n=o,i=l)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const r=S([[...g.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=S([[...g.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),o=j(r,l),s=[],c=t;if(((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=o==null?void 0:o.geometry.coordinates.map(h=>{var m;return((m=o==null?void 0:o.geometry)==null?void 0:m.type)==="MultiPolygon"?h[0].reduce(g.deletePolygonLastPoint,[]):h.reduce(g.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(r){console.error(r)}}}export{g as default};
1
+ import { polygon, difference, union } from '@turf/turf';
2
+ import { ERotateDirection } from '../../constant/annotation.js';
3
+ import CommonToolUtils from './CommonToolUtils.js';
4
+ import { ELineTypes, SEGMENT_NUMBER } from '../../constant/tool.js';
5
+ import AxisUtils from './AxisUtils.js';
6
+ import MathUtils from '../MathUtils.js';
7
+ import LineToolUtils from './LineToolUtils.js';
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ class PolygonUtils {
26
+ static getHoverPolygonID(checkPoint, polygonPoints, scope = 3, lineType = ELineTypes.Line) {
27
+ let hoverPolygonID = "";
28
+ let minSize = Infinity;
29
+ const axisList = AxisUtils.axisArea(checkPoint, scope);
30
+ polygonPoints.forEach((p) => {
31
+ if (p.pointList) {
32
+ axisList.forEach((v) => {
33
+ const size = this.calcPolygonSize(p.pointList);
34
+ if (this.isInPolygon(v, p.pointList, lineType) && size < minSize) {
35
+ hoverPolygonID = p.id;
36
+ minSize = size;
37
+ }
38
+ });
39
+ }
40
+ });
41
+ return hoverPolygonID;
42
+ }
43
+ static calcPolygonSize(pointList = []) {
44
+ if ((pointList == null ? void 0 : pointList.length) <= 2) {
45
+ return 0;
46
+ }
47
+ const len = pointList.length;
48
+ const size = pointList.reduce((acc, cur, index, src) => {
49
+ const nextVal = src[(index + 1) % len];
50
+ return acc + cur.x * nextVal.y - nextVal.x * cur.y;
51
+ }, 0);
52
+ return Math.abs(size) / 2;
53
+ }
54
+ static isInPolygon(checkPoint, polygonPoints, lineType = ELineTypes.Line) {
55
+ let counter = 0;
56
+ let i;
57
+ let xinters;
58
+ let p1;
59
+ let p2;
60
+ polygonPoints = [...polygonPoints];
61
+ if (lineType === ELineTypes.Curve) {
62
+ polygonPoints = this.createSmoothCurvePoints(polygonPoints.reduce((acc, cur) => {
63
+ return [...acc, cur.x, cur.y];
64
+ }, []), 0.5, true, 20);
65
+ }
66
+ [p1] = polygonPoints;
67
+ const pointCount = polygonPoints.length;
68
+ for (i = 1; i <= pointCount; i++) {
69
+ p2 = polygonPoints[i % pointCount];
70
+ if (checkPoint.x > Math.min(p1.x, p2.x) && checkPoint.x <= Math.max(p1.x, p2.x)) {
71
+ if (checkPoint.y <= Math.max(p1.y, p2.y)) {
72
+ if (p1.x !== p2.x) {
73
+ xinters = (checkPoint.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
74
+ if (p1.y === p2.y || checkPoint.y <= xinters) {
75
+ counter++;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ p1 = p2;
81
+ }
82
+ if (counter % 2 === 0) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ static createSmoothCurvePointsFromPointList(pointList, numberOfSegments = SEGMENT_NUMBER) {
88
+ const newPoints = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
89
+ return [...acc, cur.x, cur.y];
90
+ }, []), 0.5, false, numberOfSegments);
91
+ return newPoints.map((p, i) => {
92
+ var _a;
93
+ const pos = i / (SEGMENT_NUMBER + 1);
94
+ const v = Math.floor(pos);
95
+ const data = (_a = pointList[v]) != null ? _a : {};
96
+ if (v === pos) {
97
+ return __spreadValues(__spreadValues({}, data), p);
98
+ }
99
+ return __spreadValues({
100
+ specialEdge: data.specialEdge
101
+ }, p);
102
+ });
103
+ }
104
+ static createSmoothCurvePoints(points, tension = 0.5, closed = false, numberOfSegments = SEGMENT_NUMBER) {
105
+ if (points.length < 4) {
106
+ return points;
107
+ }
108
+ const result = [];
109
+ const ps = points.slice(0);
110
+ let x;
111
+ let y;
112
+ let t1x;
113
+ let t2x;
114
+ let t1y;
115
+ let t2y;
116
+ let c1;
117
+ let c2;
118
+ let c3;
119
+ let c4;
120
+ let st;
121
+ let t;
122
+ let i;
123
+ if (closed) {
124
+ ps.unshift(points[points.length - 1]);
125
+ ps.unshift(points[points.length - 2]);
126
+ ps.unshift(points[points.length - 1]);
127
+ ps.unshift(points[points.length - 2]);
128
+ ps.push(points[0]);
129
+ ps.push(points[1]);
130
+ } else {
131
+ ps.unshift(points[1]);
132
+ ps.unshift(points[0]);
133
+ ps.push(points[points.length - 2]);
134
+ ps.push(points[points.length - 1]);
135
+ }
136
+ for (i = 2; i < ps.length - 4; i += 2) {
137
+ t1x = (ps[i + 2] - ps[i - 2]) * tension;
138
+ t2x = (ps[i + 4] - ps[i - 0]) * tension;
139
+ t1y = (ps[i + 3] - ps[i - 1]) * tension;
140
+ t2y = (ps[i + 5] - ps[i + 1]) * tension;
141
+ for (t = 0; t <= numberOfSegments; t++) {
142
+ st = t / numberOfSegments;
143
+ c1 = 2 * Math.pow(st, 3) - 3 * Math.pow(st, 2) + 1;
144
+ c2 = -(2 * Math.pow(st, 3)) + 3 * Math.pow(st, 2);
145
+ c3 = Math.pow(st, 3) - 2 * Math.pow(st, 2) + st;
146
+ c4 = Math.pow(st, 3) - Math.pow(st, 2);
147
+ x = c1 * ps[i] + c2 * ps[i + 2] + c3 * t1x + c4 * t2x;
148
+ y = c1 * ps[i + 1] + c2 * ps[i + 3] + c3 * t1y + c4 * t2y;
149
+ result.push(x);
150
+ result.push(y);
151
+ }
152
+ }
153
+ const formatResult = [];
154
+ for (let j = 0; j < result.length - 1; j += 2) {
155
+ formatResult.push({
156
+ x: result[j],
157
+ y: result[j + 1]
158
+ });
159
+ }
160
+ if (closed) {
161
+ for (let m = 0; m < numberOfSegments + 1; m++) {
162
+ const d = formatResult.shift();
163
+ formatResult.push(d);
164
+ }
165
+ }
166
+ return formatResult;
167
+ }
168
+ static getPolygonByID(polygonList, id) {
169
+ return polygonList.find((p) => p.id === id);
170
+ }
171
+ static getPolygonByIDs(polygonList, ids) {
172
+ if (ids && (ids == null ? void 0 : ids.length) > 0) {
173
+ return polygonList.filter((p) => ids.includes(p.id));
174
+ }
175
+ }
176
+ static getHoverEdgeIndex(checkPoint, pointList, lineType = ELineTypes.Line, scope = 3) {
177
+ let points = [...pointList];
178
+ if (lineType === ELineTypes.Curve) {
179
+ points = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
180
+ return [...acc, cur.x, cur.y];
181
+ }, []), 0.5, true, SEGMENT_NUMBER);
182
+ } else if (lineType === ELineTypes.Line) {
183
+ points.push(points[0]);
184
+ }
185
+ let edgeIndex = -1;
186
+ let minLength = scope;
187
+ for (let i = 0; i < points.length - 1; i++) {
188
+ const {length} = MathUtils.getFootOfPerpendicular(checkPoint, points[i], points[i + 1]);
189
+ if (length < minLength) {
190
+ edgeIndex = i;
191
+ minLength = length;
192
+ }
193
+ }
194
+ if (edgeIndex === -1) {
195
+ return -1;
196
+ }
197
+ if (lineType === ELineTypes.Curve) {
198
+ return Math.floor(edgeIndex / SEGMENT_NUMBER);
199
+ }
200
+ return edgeIndex;
201
+ }
202
+ static getClosestPoint(coordinate, polygonList, lineType = ELineTypes.Line, range = 3, option) {
203
+ var _a;
204
+ let hasClosed = false;
205
+ const isClose = (_a = option == null ? void 0 : option.isClose) != null ? _a : true;
206
+ let closestPolygonID = "";
207
+ let closestEdgeIndex = -1;
208
+ let min = Infinity;
209
+ let dropFoot = coordinate;
210
+ const numberOfSegments = 20;
211
+ let isCloseNode = false;
212
+ polygonList.forEach((v) => {
213
+ if (isCloseNode) {
214
+ return;
215
+ }
216
+ if (!v.pointList) {
217
+ return;
218
+ }
219
+ switch (lineType) {
220
+ case ELineTypes.Line:
221
+ {
222
+ const allLine = CommonToolUtils.findAllLine(v.pointList, isClose);
223
+ allLine.forEach((line, lineIndex) => {
224
+ if (isCloseNode) {
225
+ return;
226
+ }
227
+ let {length, footPoint} = MathUtils.getFootOfPerpendicular(coordinate, line.point1, line.point2);
228
+ const twoPointDistance1 = MathUtils.getLineLength(line.point1, coordinate);
229
+ const twoPointDistance2 = MathUtils.getLineLength(line.point2, coordinate);
230
+ if (twoPointDistance1 < range * 2) {
231
+ footPoint = line.point1;
232
+ length = twoPointDistance1;
233
+ isCloseNode = true;
234
+ }
235
+ if (twoPointDistance2 < range * 2) {
236
+ footPoint = line.point2;
237
+ length = twoPointDistance2;
238
+ isCloseNode = true;
239
+ }
240
+ if (length < min && length < range) {
241
+ closestPolygonID = v.id;
242
+ closestEdgeIndex = lineIndex;
243
+ min = length;
244
+ dropFoot = footPoint;
245
+ hasClosed = true;
246
+ }
247
+ });
248
+ }
249
+ break;
250
+ case ELineTypes.Curve:
251
+ {
252
+ const points = this.createSmoothCurvePoints(v.pointList.reduce((acc, cur) => {
253
+ return [...acc, cur.x, cur.y];
254
+ }, []), 0.5, isClose, numberOfSegments);
255
+ for (let i = 0; i < points.length - 1; i++) {
256
+ const {length, footPoint} = MathUtils.getFootOfPerpendicular(coordinate, points[i], points[i + 1]);
257
+ if (length < min && length < range) {
258
+ closestPolygonID = v.id;
259
+ closestEdgeIndex = Math.floor(i / (numberOfSegments + 1));
260
+ min = length;
261
+ dropFoot = footPoint;
262
+ hasClosed = true;
263
+ }
264
+ }
265
+ }
266
+ break;
267
+ }
268
+ });
269
+ return {dropFoot, closestEdgeIndex, closestPolygonID, hasClosed};
270
+ }
271
+ static isPointListInPolygon(pointList, polygonPoints, lineType = ELineTypes.Line) {
272
+ return pointList.every((v) => this.isInPolygon(v, polygonPoints, lineType));
273
+ }
274
+ static isPointListOutSidePolygon(pointList, polygonPoints, lineType = ELineTypes.Line) {
275
+ return pointList.some((v) => !this.isInPolygon(v, polygonPoints, lineType));
276
+ }
277
+ static getPolygonArea(pointList) {
278
+ let total = 0;
279
+ for (let i = 0, l = pointList.length; i < l; i++) {
280
+ const addX = pointList[i].x;
281
+ const addY = pointList[i === pointList.length - 1 ? 0 : i + 1].y;
282
+ const subX = pointList[i === pointList.length - 1 ? 0 : i + 1].x;
283
+ const subY = pointList[i].y;
284
+ total += addX * addY * 0.5;
285
+ total -= subX * subY * 0.5;
286
+ }
287
+ return Math.abs(total);
288
+ }
289
+ static updatePolygonByRotate(direction, angle = 1, pointList) {
290
+ let rotate = 1;
291
+ if (direction === ERotateDirection.Anticlockwise) {
292
+ rotate = -1;
293
+ }
294
+ rotate *= angle;
295
+ return MathUtils.rotateRectPointList(rotate, pointList);
296
+ }
297
+ static deletePolygonLastPoint(acc, cur, index, array) {
298
+ if (index === array.length - 1) {
299
+ return acc;
300
+ }
301
+ return [
302
+ ...acc,
303
+ {
304
+ x: cur[0],
305
+ y: cur[1]
306
+ }
307
+ ];
308
+ }
309
+ static concatBeginAndEnd(array) {
310
+ if (array.length < 1) {
311
+ return array;
312
+ }
313
+ return [...array, array[0]];
314
+ }
315
+ static segmentPolygonByPolygon(pointList, polygonList) {
316
+ var _a, _b;
317
+ try {
318
+ let selectedPolygon = polygon([[...PolygonUtils.concatBeginAndEnd(pointList.map((v) => [v.x, v.y]))]]);
319
+ polygonList.forEach((v) => {
320
+ const backgroundPolygon = polygon([[...PolygonUtils.concatBeginAndEnd(v.pointList.map((p) => [p.x, p.y]))]]);
321
+ const diff = difference(selectedPolygon, backgroundPolygon);
322
+ if (diff) {
323
+ selectedPolygon = diff;
324
+ }
325
+ });
326
+ const resultList = (_b = (_a = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a.coordinates.map((p) => {
327
+ var _a2;
328
+ if (((_a2 = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
329
+ return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
330
+ }
331
+ return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
332
+ })) != null ? _b : [];
333
+ return resultList.reduce((acc, pointLists) => {
334
+ const len = pointLists.length;
335
+ const newPointList = pointLists.filter((point, i) => {
336
+ const nextIndex = (i + 1) % len;
337
+ if (AxisUtils.getIsInScope(point, pointLists[nextIndex], 1)) {
338
+ return false;
339
+ }
340
+ return true;
341
+ });
342
+ if (newPointList.length < 3) {
343
+ return acc;
344
+ }
345
+ return [...acc, newPointList];
346
+ }, []);
347
+ } catch (error) {
348
+ console.error(error);
349
+ }
350
+ }
351
+ static getPolygonPointList(selectedPolygonID, polygonList) {
352
+ const p = polygonList.find((v) => v.id === selectedPolygonID);
353
+ if (p && p.pointList && p.pointList.length > 0) {
354
+ return p.pointList;
355
+ }
356
+ return [];
357
+ }
358
+ static getWrapPolygonIndex(pointList, polygonList) {
359
+ return polygonList.findIndex((p) => PolygonUtils.isPointListInPolygon(pointList, p.pointList));
360
+ }
361
+ static clipPolygonFromWrapPolygon(pointList, wrapPointList) {
362
+ const wrapDirection = PolygonUtils.isPolygonClosewise(wrapPointList);
363
+ const selectedDirection = PolygonUtils.isPolygonClosewise(pointList);
364
+ const linkIndex = PolygonUtils.getClosePointDistanceFromPolygon(pointList[0], wrapPointList);
365
+ const linkPoint = wrapPointList[linkIndex];
366
+ let newPointList = [
367
+ ...wrapPointList.slice(0, linkIndex),
368
+ linkPoint,
369
+ ...pointList,
370
+ pointList[0],
371
+ ...wrapPointList.slice(linkIndex, wrapPointList.length)
372
+ ];
373
+ if (wrapDirection === selectedDirection) {
374
+ newPointList = [
375
+ ...wrapPointList.slice(0, linkIndex),
376
+ linkPoint,
377
+ pointList[0],
378
+ ...pointList.reverse(),
379
+ ...wrapPointList.slice(linkIndex, wrapPointList.length)
380
+ ];
381
+ }
382
+ return newPointList;
383
+ }
384
+ static isPolygonClosewise(p) {
385
+ const n = p.length;
386
+ let i;
387
+ let j;
388
+ let k;
389
+ let count = 0;
390
+ let z;
391
+ if (n < 3) {
392
+ return 0;
393
+ }
394
+ for (i = 0; i < n; i++) {
395
+ j = (i + 1) % n;
396
+ k = (i + 2) % n;
397
+ z = (p[j].x - p[i].x) * (p[k].y - p[j].y);
398
+ z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
399
+ if (z < 0) {
400
+ count--;
401
+ } else if (z > 0) {
402
+ count++;
403
+ }
404
+ }
405
+ if (count > 0) {
406
+ return 1;
407
+ }
408
+ if (count < 0) {
409
+ return -1;
410
+ }
411
+ return 0;
412
+ }
413
+ static getClosePointDistanceFromPolygon(point, pointList) {
414
+ let minLen = Number.MAX_SAFE_INTEGER;
415
+ let index = -1;
416
+ pointList.forEach((p, i) => {
417
+ const distance = LineToolUtils.calcDistance(point, p);
418
+ if (distance < minLen) {
419
+ minLen = distance;
420
+ index = i;
421
+ }
422
+ });
423
+ return index;
424
+ }
425
+ static combinePolygonWithPolygon(selectedPolygon, combinedPolygon) {
426
+ var _a, _b;
427
+ try {
428
+ const turfSelectedPolygon = polygon([
429
+ [...PolygonUtils.concatBeginAndEnd(selectedPolygon.pointList.map((v) => [v.x, v.y]))]
430
+ ]);
431
+ const turfCombinedPolygon = polygon([
432
+ [...PolygonUtils.concatBeginAndEnd(combinedPolygon.pointList.map((v) => [v.x, v.y]))]
433
+ ]);
434
+ const unionPolygon = union(turfSelectedPolygon, turfCombinedPolygon);
435
+ const unionList = [];
436
+ const newPolygon = selectedPolygon;
437
+ if (((_b = (_a = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a.coordinates) == null ? void 0 : _b.length) === 1) {
438
+ unionList.push(combinedPolygon.id);
439
+ const pointList = unionPolygon == null ? void 0 : unionPolygon.geometry.coordinates.map((p) => {
440
+ var _a2;
441
+ if (((_a2 = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
442
+ return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
443
+ }
444
+ return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
445
+ })[0];
446
+ newPolygon.pointList = pointList;
447
+ }
448
+ return {
449
+ newPolygon,
450
+ unionList
451
+ };
452
+ } catch (e) {
453
+ console.error(e);
454
+ }
455
+ }
456
+ }
457
+
458
+ export { PolygonUtils as default };
@@ -1 +1,153 @@
1
- import p from"./AxisUtils.js";import f from"./CommonToolUtils.js";import{isInPolygon as d}from"./polygonTool.js";var P=Object.defineProperty,_=Object.defineProperties,w=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,x=(a,t,e)=>t in a?P(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,h=(a,t)=>{for(var e in t||(t={}))O.call(t,e)&&x(a,e,t[e]);if(u)for(var e of u(t))R.call(t,e)&&x(a,e,t[e]);return a},l=(a,t)=>_(a,w(t));class v{static composeResult(t,e,r,n,s){try{const i=JSON.parse(t),o=f.getCurrentStepInfo(e,n),{dataSourceStep:y}=o,g=`step_${o.step}`;if(Object.assign(i,s),i[g]){const c=i[g];return c.result?(c.result=r,JSON.stringify(i)):JSON.stringify(l(h({},i),{[g]:l(h({},i[g]),{result:r})}))}return JSON.stringify(l(h({},i),{[g]:{dataSourceStep:y,toolName:o.tool,result:r}}))}catch(i){return t}}static changeCoordinateByRotate(t,e,r){const{x:n,y:s,width:i,height:o}=t,y=p.changeCoordinateByRotate({x:n,y:s},e,r);switch(e%360){case 90:return l(h({},t),{x:y.x-o,y:y.y,width:o,height:i});case 180:return l(h({},t),{x:y.x-i,y:y.y-o});case 270:return l(h({},t),{x:y.x,y:y.y-i,width:o,height:i});default:return t}}static translateRect2Points(t){const{x:e,y:r,width:n,height:s}=t;return[{x:e,y:r},{x:e+n,y:r},{x:e+n,y:r+s},{x:e,y:r+s}]}static translatePoints2Rect(t,e){if(t.length!==4)return;const{x:r,y:n}=t[0],s=t[1].x-t[0].x,i=t[2].y-t[1].y;return l(h({},e),{x:r,y:n,width:s,height:i})}static getRectPointList(t,e=1){return[{x:t.x*e,y:t.y*e},{x:(t.x+t.width)*e,y:t.y*e},{x:(t.x+t.width)*e,y:(t.y+t.height)*e},{x:t.x*e,y:(t.y+t.height)*e}]}static getRectEdgeList(t,e=1){const r=this.getRectPointList(t,e),n=r.length;return r.map((s,i)=>({begin:s,end:r[(i+1)%n]}))}static isInRect(t,e,r=0,n=1){return t.x>=e.x*n-r&&t.x<=(e.x+e.width)*n+r&&t.y>=e.y*n-r&&t.y<=(e.y+e.height)*n+r}static getRectUnderZoom(t,e=1){const{x:r,y:n,width:s,height:i}=t;return l(h({},t),{x:r*e,y:n*e,width:s*e,height:i*e})}static isRectNotInPolygon(t,e){return this.getRectPointList(t).some(n=>!d(n,e))}}export{v as default};
1
+ import AxisUtils from './AxisUtils.js';
2
+ import CommonToolUtils from './CommonToolUtils.js';
3
+ import { isInPolygon } from './polygonTool.js';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ class RectUtils {
25
+ static composeResult(result, currentStep, resultList, stepList, basicImgInfo) {
26
+ try {
27
+ const data = JSON.parse(result);
28
+ const currentStepInfo = CommonToolUtils.getCurrentStepInfo(currentStep, stepList);
29
+ const {dataSourceStep} = currentStepInfo;
30
+ const stepName = `step_${currentStepInfo.step}`;
31
+ Object.assign(data, basicImgInfo);
32
+ if (data[stepName]) {
33
+ const info = data[stepName];
34
+ if (info.result) {
35
+ info.result = resultList;
36
+ return JSON.stringify(data);
37
+ }
38
+ return JSON.stringify(__spreadProps(__spreadValues({}, data), {
39
+ [stepName]: __spreadProps(__spreadValues({}, data[stepName]), {
40
+ result: resultList
41
+ })
42
+ }));
43
+ }
44
+ return JSON.stringify(__spreadProps(__spreadValues({}, data), {
45
+ [stepName]: {
46
+ dataSourceStep,
47
+ toolName: currentStepInfo.tool,
48
+ result: resultList
49
+ }
50
+ }));
51
+ } catch (e) {
52
+ return result;
53
+ }
54
+ }
55
+ static changeCoordinateByRotate(rect, rotate, imgSize) {
56
+ const {x, y, width, height} = rect;
57
+ const leftTopCoordinate = AxisUtils.changeCoordinateByRotate({x, y}, rotate, imgSize);
58
+ switch (rotate % 360) {
59
+ case 90:
60
+ return __spreadProps(__spreadValues({}, rect), {
61
+ x: leftTopCoordinate.x - height,
62
+ y: leftTopCoordinate.y,
63
+ width: height,
64
+ height: width
65
+ });
66
+ case 180:
67
+ return __spreadProps(__spreadValues({}, rect), {
68
+ x: leftTopCoordinate.x - width,
69
+ y: leftTopCoordinate.y - height
70
+ });
71
+ case 270:
72
+ return __spreadProps(__spreadValues({}, rect), {
73
+ x: leftTopCoordinate.x,
74
+ y: leftTopCoordinate.y - width,
75
+ width: height,
76
+ height: width
77
+ });
78
+ default:
79
+ return rect;
80
+ }
81
+ }
82
+ static translateRect2Points(rect) {
83
+ const {x, y, width, height} = rect;
84
+ return [
85
+ {
86
+ x,
87
+ y
88
+ },
89
+ {
90
+ x: x + width,
91
+ y
92
+ },
93
+ {
94
+ x: x + width,
95
+ y: y + height
96
+ },
97
+ {
98
+ x,
99
+ y: y + height
100
+ }
101
+ ];
102
+ }
103
+ static translatePoints2Rect(points, basicRect) {
104
+ if (points.length !== 4) {
105
+ return;
106
+ }
107
+ const {x, y} = points[0];
108
+ const width = points[1].x - points[0].x;
109
+ const height = points[2].y - points[1].y;
110
+ return __spreadProps(__spreadValues({}, basicRect), {
111
+ x,
112
+ y,
113
+ width,
114
+ height
115
+ });
116
+ }
117
+ static getRectPointList(rect, zoom = 1) {
118
+ return [
119
+ {x: rect.x * zoom, y: rect.y * zoom},
120
+ {x: (rect.x + rect.width) * zoom, y: rect.y * zoom},
121
+ {x: (rect.x + rect.width) * zoom, y: (rect.y + rect.height) * zoom},
122
+ {x: rect.x * zoom, y: (rect.y + rect.height) * zoom}
123
+ ];
124
+ }
125
+ static getRectEdgeList(rect, zoom = 1) {
126
+ const pointList = this.getRectPointList(rect, zoom);
127
+ const len = pointList.length;
128
+ return pointList.map((v, i) => {
129
+ return {
130
+ begin: v,
131
+ end: pointList[(i + 1) % len]
132
+ };
133
+ });
134
+ }
135
+ static isInRect(coordinate, rect, scope = 0, zoom = 1) {
136
+ return coordinate.x >= rect.x * zoom - scope && coordinate.x <= (rect.x + rect.width) * zoom + scope && coordinate.y >= rect.y * zoom - scope && coordinate.y <= (rect.y + rect.height) * zoom + scope;
137
+ }
138
+ static getRectUnderZoom(rect, zoom = 1) {
139
+ const {x, y, width, height} = rect;
140
+ return __spreadProps(__spreadValues({}, rect), {
141
+ x: x * zoom,
142
+ y: y * zoom,
143
+ width: width * zoom,
144
+ height: height * zoom
145
+ });
146
+ }
147
+ static isRectNotInPolygon(rect, polygonPointList) {
148
+ const rectPointList = this.getRectPointList(rect);
149
+ return rectPointList.some((p) => !isInPolygon(p, polygonPointList));
150
+ }
151
+ }
152
+
153
+ export { RectUtils as default };