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