@labelbee/lb-annotation 1.13.0-alpha.7 → 1.14.0-alpha.0

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 (59) hide show
  1. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
  2. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
  3. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
  4. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
  5. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
  6. package/dist/constant/annotation.js +1 -1
  7. package/dist/constant/tool.js +1 -1
  8. package/dist/core/pointCloud/annotation.js +1 -1
  9. package/dist/core/pointCloud/index.js +2 -2
  10. package/dist/core/scheduler.js +1 -1
  11. package/dist/core/toolOperation/ViewOperation.js +1 -1
  12. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  13. package/dist/core/toolOperation/cuboidOperation.js +1 -0
  14. package/dist/core/toolOperation/cuboidToggleButtonClass.js +31 -0
  15. package/dist/types/constant/annotation.d.ts +45 -1
  16. package/dist/types/constant/tool.d.ts +6 -1
  17. package/dist/types/core/index.d.ts +1 -2
  18. package/dist/types/core/pointCloud/annotation.d.ts +11 -1
  19. package/dist/types/core/pointCloud/index.d.ts +11 -1
  20. package/dist/types/core/pointCloud/matrix.d.ts +1 -0
  21. package/dist/types/core/scheduler.d.ts +7 -2
  22. package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -2
  23. package/dist/types/core/toolOperation/basicToolOperation.d.ts +11 -1
  24. package/dist/types/core/toolOperation/cuboidOperation.d.ts +155 -0
  25. package/dist/types/core/toolOperation/cuboidToggleButtonClass.d.ts +38 -0
  26. package/dist/types/utils/MathUtils.d.ts +1 -1
  27. package/dist/types/utils/tool/AttributeUtils.d.ts +7 -0
  28. package/dist/types/utils/tool/AxisUtils.d.ts +50 -1
  29. package/dist/types/utils/tool/CuboidUtils.d.ts +267 -0
  30. package/dist/types/utils/tool/DrawUtils.d.ts +12 -0
  31. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +4 -2
  32. package/dist/types/utils/tool/PolygonUtils.d.ts +5 -2
  33. package/dist/utils/MathUtils.js +2 -2
  34. package/dist/utils/tool/AttributeUtils.js +1 -1
  35. package/dist/utils/tool/AxisUtils.js +1 -1
  36. package/dist/utils/tool/CuboidUtils.js +1 -0
  37. package/dist/utils/tool/DrawUtils.js +3 -3
  38. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -1
  39. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
  40. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
  41. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
  42. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
  43. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
  44. package/es/constant/annotation.js +1 -1
  45. package/es/constant/tool.js +1 -1
  46. package/es/core/pointCloud/annotation.js +1 -1
  47. package/es/core/pointCloud/index.js +2 -2
  48. package/es/core/scheduler.js +1 -1
  49. package/es/core/toolOperation/ViewOperation.js +1 -1
  50. package/es/core/toolOperation/basicToolOperation.js +1 -1
  51. package/es/core/toolOperation/cuboidOperation.js +1 -733
  52. package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
  53. package/es/utils/MathUtils.js +2 -2
  54. package/es/utils/tool/AttributeUtils.js +1 -1
  55. package/es/utils/tool/AxisUtils.js +1 -1
  56. package/es/utils/tool/CuboidUtils.js +1 -663
  57. package/es/utils/tool/DrawUtils.js +3 -3
  58. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -1
  59. package/package.json +3 -3
@@ -1,108 +1,10 @@
1
- import { ECuboidDirection } from '../../constant/annotation.js';
2
- import cuboidFAB from '../../assets/attributeIcon/icon_cuboidFAB.svg.js';
3
- import cuboidMore from '../../assets/attributeIcon/icon_cuboidMore.svg.js';
4
- import cuboidRight from '../../assets/attributeIcon/icon_cuboidRight.svg.js';
5
- import cuboidLeft from '../../assets/attributeIcon/icon_cuboidLeft.svg.js';
6
- import cuboidTop from '../../assets/attributeIcon/icon_cuboidTop.svg.js';
7
-
8
- const MORE_ICON_LISTS = [
9
- {
10
- icon: cuboidRight,
11
- id: "cuboidRight"
12
- },
13
- {
14
- icon: cuboidLeft,
15
- id: "cuboidLeft"
16
- },
17
- {
18
- icon: cuboidTop,
19
- id: "cuboidTop"
20
- }
21
- ];
22
- class CuboidToggleButtonClass {
23
- constructor(props) {
24
- const {container, cuboidButtonMove, toggleDirection} = props;
25
- this.container = container;
26
- this.direction = ECuboidDirection.Front;
27
- this.isFrontSide = true;
28
- this.cuboidButtonMove = cuboidButtonMove;
29
- this.onToggleDirection = toggleDirection;
30
- this._cuboidButtonDOM = this.initCuboidButtonDOM();
31
- this._cuboidFABDOM = this.initcuboidFABDOM(cuboidFAB);
32
- this._cuboidMoreDOM = this.initcuboidMoreDOM(cuboidMore);
33
- this._cuboidMoreListDOM = this.initcuboidMoreListDOM();
34
- this.appendToContainer();
35
- }
36
- appendToContainer() {
37
- if (!this._cuboidButtonDOM || !this._cuboidFABDOM || !this._cuboidMoreDOM) {
38
- return;
39
- }
40
- this.container.appendChild(this._cuboidButtonDOM);
41
- this._cuboidButtonDOM.appendChild(this._cuboidFABDOM);
42
- this._cuboidButtonDOM.appendChild(this._cuboidMoreDOM);
43
- }
44
- initCuboidButtonDOM() {
45
- const _cuboidButtonDOM = document.createElement("div");
46
- _cuboidButtonDOM.setAttribute("id", "LABELBEE_CUBOID_BUTTON_BOX");
47
- _cuboidButtonDOM.setAttribute("style", `
1
+ import{ECuboidDirection as s}from"../../constant/annotation.js";import c from"../../assets/attributeIcon/icon_cuboidFAB.svg.js";import u from"../../assets/attributeIcon/icon_cuboidMore.svg.js";import a from"../../assets/attributeIcon/icon_cuboidRight.svg.js";import b from"../../assets/attributeIcon/icon_cuboidLeft.svg.js";import h from"../../assets/attributeIcon/icon_cuboidTop.svg.js";const r=[{icon:a,id:"cuboidRight"},{icon:b,id:"cuboidLeft"},{icon:h,id:"cuboidTop"}];class M{constructor(i){const{container:t,cuboidButtonMove:o,toggleDirection:e}=i;this.container=t,this.direction=s.Front,this.isFrontSide=!0,this.cuboidButtonMove=o,this.onToggleDirection=e,this._cuboidButtonDOM=this.initCuboidButtonDOM(),this._cuboidFABDOM=this.initcuboidFABDOM(c),this._cuboidMoreDOM=this.initcuboidMoreDOM(u),this._cuboidMoreListDOM=this.initcuboidMoreListDOM(),this.appendToContainer()}appendToContainer(){!this._cuboidButtonDOM||!this._cuboidFABDOM||!this._cuboidMoreDOM||(this.container.appendChild(this._cuboidButtonDOM),this._cuboidButtonDOM.appendChild(this._cuboidFABDOM),this._cuboidButtonDOM.appendChild(this._cuboidMoreDOM))}initCuboidButtonDOM(){const i=document.createElement("div");return i.setAttribute("id","LABELBEE_CUBOID_BUTTON_BOX"),i.setAttribute("style",`
48
2
  width: 40px;
49
3
  height: 74px;
50
4
  border-radius: 10px;
51
5
  background-color: #FFFFFF;
52
6
  z-index: 10;
53
- `);
54
- _cuboidButtonDOM.addEventListener("mouseover", (e) => {
55
- e.stopPropagation();
56
- setTimeout(() => {
57
- this.cuboidButtonMove("in");
58
- }, 100);
59
- });
60
- _cuboidButtonDOM.addEventListener("mouseleave", (e) => {
61
- e.stopPropagation();
62
- setTimeout(() => {
63
- this.cuboidButtonMove("out");
64
- }, 100);
65
- });
66
- return _cuboidButtonDOM;
67
- }
68
- initcuboidFABDOM(icon) {
69
- const _cuboidFAB = document.createElement("div");
70
- _cuboidFAB.setAttribute("id", "CUBOID_FORWARD_AND_BACK_SWITCH");
71
- _cuboidFAB.innerHTML = icon;
72
- _cuboidFAB.addEventListener("mouseup", (e) => {
73
- e.stopPropagation();
74
- this.isFrontSide = !this.isFrontSide;
75
- this.direction = this.isFrontSide ? ECuboidDirection.Front : ECuboidDirection.Back;
76
- this.onToggleDirection(this.direction);
77
- });
78
- return _cuboidFAB;
79
- }
80
- initcuboidMoreDOM(icon) {
81
- const _iconDOM = document.createElement("div");
82
- _iconDOM.setAttribute("id", "CUBOID_MORE_ICON");
83
- _iconDOM.innerHTML = icon;
84
- _iconDOM.addEventListener("mouseup", (e) => {
85
- if (this._cuboidButtonDOM && this._cuboidMoreListDOM) {
86
- if (this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)) {
87
- this.clearCuboidMoreListDOM();
88
- } else {
89
- this._cuboidButtonDOM.appendChild(this._cuboidMoreListDOM);
90
- }
91
- }
92
- e.stopPropagation();
93
- });
94
- _iconDOM.addEventListener("mousedown", (e) => {
95
- e.stopPropagation();
96
- });
97
- _iconDOM.addEventListener("contextmenu", (e) => {
98
- e.stopPropagation();
99
- });
100
- return _iconDOM;
101
- }
102
- initcuboidMoreListDOM() {
103
- const cuboidMoreListDOM = document.createElement("div");
104
- cuboidMoreListDOM.setAttribute("id", "CUBOID_MORE_LIST_ICON");
105
- cuboidMoreListDOM.setAttribute("style", `
7
+ `),i.addEventListener("mouseover",t=>{t.stopPropagation(),setTimeout(()=>{this.cuboidButtonMove("in")},100)}),i.addEventListener("mouseleave",t=>{t.stopPropagation(),setTimeout(()=>{this.cuboidButtonMove("out")},100)}),i}initcuboidFABDOM(i){const t=document.createElement("div");return t.setAttribute("id","CUBOID_FORWARD_AND_BACK_SWITCH"),t.innerHTML=i,t.addEventListener("mouseup",o=>{o.stopPropagation(),this.isFrontSide=!this.isFrontSide,this.direction=this.isFrontSide?s.Front:s.Back,this.onToggleDirection(this.direction)}),t}initcuboidMoreDOM(i){const t=document.createElement("div");return t.setAttribute("id","CUBOID_MORE_ICON"),t.innerHTML=i,t.addEventListener("mouseup",o=>{this._cuboidButtonDOM&&this._cuboidMoreListDOM&&(this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)?this.clearCuboidMoreListDOM():this._cuboidButtonDOM.appendChild(this._cuboidMoreListDOM)),o.stopPropagation()}),t.addEventListener("mousedown",o=>{o.stopPropagation()}),t.addEventListener("contextmenu",o=>{o.stopPropagation()}),t}initcuboidMoreListDOM(){const i=document.createElement("div");i.setAttribute("id","CUBOID_MORE_LIST_ICON"),i.setAttribute("style",`
106
8
  height: 36px;
107
9
  border-radius: 10px;
108
10
  background-color: #FFFFFF;
@@ -112,43 +14,12 @@ class CuboidToggleButtonClass {
112
14
  bottom: 0px;
113
15
  left: 44px;
114
16
  display: flex;
115
- `);
116
- let str = "";
117
- const iconStyle = `margin-left:4px;margin-right:4px;display:flex;align-items:center;`;
118
- MORE_ICON_LISTS.forEach((i, index) => {
119
- const lastIconStyle = index === MORE_ICON_LISTS.length - 1 ? "margin-left:0px;margin-right:0px;" : "";
120
- str += `<span id=${i.id} key=${index} style=${iconStyle}${lastIconStyle}>${i.icon}</span>`;
121
- });
122
- cuboidMoreListDOM.innerHTML = str;
123
- cuboidMoreListDOM.childNodes.forEach((item) => {
124
- item.addEventListener("click", (e) => {
125
- e.stopPropagation();
126
- switch (item == null ? void 0 : item.id) {
127
- case "cuboidLeft":
128
- this.onToggleDirection(ECuboidDirection.Left);
129
- break;
130
- case "cuboidRight":
131
- this.onToggleDirection(ECuboidDirection.Right);
132
- break;
133
- case "cuboidTop":
134
- this.onToggleDirection(ECuboidDirection.Top);
135
- break;
136
- }
137
- this.clearCuboidMoreListDOM();
138
- this.cuboidButtonMove("out");
139
- });
140
- });
141
- return cuboidMoreListDOM;
142
- }
143
- update(position) {
144
- var _a;
145
- const {left, top, color} = position;
146
- (_a = this._cuboidButtonDOM) == null ? void 0 : _a.setAttribute("style", `
17
+ `);let t="";const o="margin-left:4px;margin-right:4px;display:flex;align-items:center;";return r.forEach((e,n)=>{const d=n===r.length-1?"margin-left:0px;margin-right:0px;":"";t+=`<span id=${e.id} key=${n} style=${o}${d}>${e.icon}</span>`}),i.innerHTML=t,i.childNodes.forEach(e=>{e.addEventListener("click",n=>{switch(n.stopPropagation(),e==null?void 0:e.id){case"cuboidLeft":this.onToggleDirection(s.Left);break;case"cuboidRight":this.onToggleDirection(s.Right);break;case"cuboidTop":this.onToggleDirection(s.Top);break}this.clearCuboidMoreListDOM(),this.cuboidButtonMove("out")})}),i}update(i){var t;const{left:o,top:e,color:n}=i;(t=this._cuboidButtonDOM)==null||t.setAttribute("style",`
147
18
  position: absolute;
148
19
  font-size: 14px;
149
- left:${left}px;
150
- top: ${top}px;
151
- color: ${color};
20
+ left:${o}px;
21
+ top: ${e}px;
22
+ color: ${n};
152
23
  width: 41px;
153
24
  height: 74px;
154
25
  border-radius: 10px;
@@ -157,18 +28,4 @@ class CuboidToggleButtonClass {
157
28
  text-align: center;
158
29
  padding-top: 10px;
159
30
  z-index: 10;
160
- `);
161
- }
162
- clearCuboidButtonDOM() {
163
- if (this._cuboidButtonDOM && this.container.contains(this._cuboidButtonDOM)) {
164
- this.container.removeChild(this._cuboidButtonDOM);
165
- }
166
- }
167
- clearCuboidMoreListDOM() {
168
- if (this._cuboidButtonDOM && this._cuboidMoreListDOM && this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)) {
169
- this._cuboidButtonDOM.removeChild(this._cuboidMoreListDOM);
170
- }
171
- }
172
- }
173
-
174
- export { CuboidToggleButtonClass as default };
31
+ `)}clearCuboidButtonDOM(){this._cuboidButtonDOM&&this.container.contains(this._cuboidButtonDOM)&&this.container.removeChild(this._cuboidButtonDOM)}clearCuboidMoreListDOM(){this._cuboidButtonDOM&&this._cuboidMoreListDOM&&this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)&&this._cuboidButtonDOM.removeChild(this._cuboidMoreListDOM)}}export{M as default};
@@ -1,2 +1,2 @@
1
- import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,a=t.split(`
2
- `);let l=0;for(let f=0;f<a.length;f++){const u=a[f].split("");let g="";for(let y=0;y<u.length;y++){const p=g+u[y],P=i.measureText(p).width;P>o&&y>0?(g=u[y],n+=r,l=o):(g=p,P>l&&(l=P))}f!==a.length-1&&(n+=r)}return{width:l,height:n+c,lineHeight:r,fontHeight:c}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,c={x:i.x-n.x,y:i.y-n.y},a=h.add(t,c);return h.getVector(e,a)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const c=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,a=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=c,n[r]=a,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const c=h.getVector(o,n),a=h.len(c),l=c.y/a,f=c.x/a;return{x:a*M.cosAPlusB(l,f,r,i)+o.x,y:a*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,c=Math.acos(n);return r>0?Math.PI*2-c:c}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,c)=>{const{dropFoot:a}=w.getClosestPoint(n,c,T.Line,1,{isClose:!1});if(a!==n){const l=`${a.x} + ${a.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let c="";c=n.id,r.forEach((a,l)=>{if(a.id===c)return;const f=[...r];f.splice(l,1),a.pointList.forEach(u=>{i(u,f)})})}),{connectionPoints:t}}};let d=m;d.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},d.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},d.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let c=e;t&&(c=B(e,o)),c.forEach(({x:p,y:x})=>{i.push(p),n.push(x)});let a=Math.min(...i),l=Math.max(...i),f=Math.min(...n),u=Math.max(...n);const g=l-a,y=u-f;if(g<r){const p=(r-g)/2;a-=p,l+=p}if(y<r){const p=(r-y)/2;f-=p,u+=p}return{top:f,bottom:u,left:a,right:l}},d.getFootOfPerpendicular=(e,t,o,s=!1)=>{let r={x:0,y:0};const i=t.x-o.x,n=t.y-o.y;if(Math.abs(i)<1e-8&&Math.abs(n)<1e-8)return r=t,r;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=i*i+n*n,r.x=t.x+c*i,r.y=t.y+c*n;const a=m.getLineLength(e,r),l=2,f=Math.min(t.x,o.x),u=Math.max(t.x,o.x),g=Math.min(t.y,o.y),y=Math.max(t.y,o.y),p=!(m.isInRange(e.x,[f,u])||m.isInRange(e.y,[g,y])),x=e.x>u+l||e.x<f-l||e.y>y+l||e.y<g-l;return(s?p:x)?{footPoint:r,length:Infinity}:{footPoint:r,length:a}};var D=d;export{M as Trigonometric,D as default};
1
+ import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
2
+ `);let l=0;for(let f=0;f<c.length;f++){const p=c[f].split("");let g="";for(let y=0;y<p.length;y++){const u=g+p[y],d=i.measureText(u).width;d>o&&y>0?(g=p[y],n+=r,l=o):(g=u,d>l&&(l=d))}f!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=h.add(t,a);return h.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=h.getVector(o,n),c=h.len(a),l=a.y/c,f=a.x/c;return{x:c*M.cosAPlusB(l,f,r,i)+o.x,y:c*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=w.getClosestPoint(n,a,T.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const f=[...r];f.splice(l,1),c.pointList.forEach(p=>{i(p,f)})})}),{connectionPoints:t}}};let x=m;x.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},x.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},x.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=B(e,o)),a.forEach(({x:u,y:P})=>{i.push(u),n.push(P)});let c=Math.min(...i),l=Math.max(...i),f=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-f;if(g<r){const u=(r-g)/2;c-=u,l+=u}if(y<r){const u=(r-y)/2;f-=u,p+=u}return{top:f,bottom:p,left:c,right:l}},x.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=m.getLineLength(e,i),f=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y),P=!(m.isInRange(e.x,[p,g])||m.isInRange(e.y,[y,u])),d=e.x>g+f||e.x<p-f||e.y>u+f||e.y<y-f;return!r&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var D=x;export{M as Trigonometric,D as default};
@@ -1 +1 @@
1
- import{isNumber as I}from"lodash";import{ICON_ARRAY as c,NULL_ICON as O,NULL_COLOR as g,COLORS_ARRAY as o}from"../../constant/style.js";import{ETextType as u}from"../../constant/tool.js";import l from"../../locales/index.js";import{EMessage as d}from"../../locales/constants.js";import p from"../MathUtils.js";import E from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var y=Object.defineProperty,N=Object.defineProperties,R=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,v=(s,t,r)=>t in s?y(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r,b=(s,t)=>{for(var r in t||(t={}))P.call(t,r)&&v(s,r,t[r]);if(x)for(var r of x(t))w.call(t,r)&&v(s,r,t[r]);return s},h=(s,t)=>N(s,R(t));const _="^[0-9]+$",m="^[A-Za-z]+$";class T{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(A=>A.value===t);let i=(n=c[a%c.length])!=null?n:O;e||(i=E),i="";const f=new Image;return f.src=i,f}static checkString(t,r){let e="";switch(t){case u.Order:case u.NumberOnly:e=_;break;case u.EnglishOnly:e=m;break;case u.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?g:o[e%o.length]}catch(e){return g}}static getTextAttribute(t,r){try{if(r===u.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?h(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case u.Order:case u.NumberOnly:return l.getMessagesByLocale(d.TextCheckNumberErrorNotice,r);case u.EnglishOnly:return l.getMessagesByLocale(d.TextCheckEnglishErrorNotice,r);case u.CustomFormat:return l.getMessagesByLocale(d.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return h(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){if(e===!0){const a=(r==null?void 0:r.findIndex(i=>(i==null?void 0:i.value)===t))%o.length+1;return c[a]}return n}static getAttributeByKeycode(t,r){var e;let n;return p.isInRange(t,[48,57])&&(n=t-48),p.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{m as REGEXP_ENGLISH,_ as REGEXP_NUMBER,T as default};
1
+ import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{NULL_COLOR as f,COLORS_ARRAY as c,ICON_ARRAY as d,NULL_ICON as E}from"../../constant/style.js";import{ETextType as s}from"../../constant/tool.js";import g from"../../locales/index.js";import{EMessage as p}from"../../locales/constants.js";import h from"../MathUtils.js";import y from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var w=Object.defineProperty,N=Object.defineProperties,P=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,x=(l,t,r)=>t in l?w(l,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[t]=r,b=(l,t)=>{for(var r in t||(t={}))R.call(t,r)&&x(l,r,t[r]);if(v)for(var r of v(t))T.call(t,r)&&x(l,r,t[r]);return l},m=(l,t)=>N(l,P(t));const _="^[0-9]+$",A="^[A-Za-z]+$";class M{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(o=>o.value===t);let i=(n=d[a%d.length])!=null?n:E;e||(i=y),i="";const u=new Image;return u.src=i,u}static checkString(t,r){let e="";switch(t){case s.Order:case s.NumberOnly:e=_;break;case s.EnglishOnly:e=A;break;case s.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?f:c[e%c.length]}catch(e){return f}}static getTextAttribute(t,r){try{if(r===s.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?m(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case s.Order:case s.NumberOnly:return g.getMessagesByLocale(p.TextCheckNumberErrorNotice,r);case s.EnglishOnly:return g.getMessagesByLocale(p.TextCheckEnglishErrorNotice,r);case s.CustomFormat:return g.getMessagesByLocale(p.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return m(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){var a;if(e===!0){const i=(r==null?void 0:r.findIndex(o=>(o==null?void 0:o.value)===t))%c.length+1,u=(a=r==null?void 0:r.find(o=>o.value===t))==null?void 0:a.color;if(u){const o=O.rgbaStringToHex(u);return this.generateIconAttribute({fill:o})}return d[i]}return n}static generateIconAttribute({fill:t,width:r=16,height:e=16,xmlns:n="http://www.w3.org/2000/svg",xlink:a="http://www.w3.org/1999/xlink"}){return`<span style={color:${t}}><svg xmlns=${n} xmlns:xlink=${a} width=${r} height=${e} viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill='currentColor'/></g></g></svg></span>`}static getAttributeByKeycode(t,r){var e;let n;return h.isInRange(t,[48,57])&&(n=t-48),h.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{A as REGEXP_ENGLISH,_ as REGEXP_NUMBER,M as default};
@@ -1 +1 @@
1
- import{EToolName as f,ELineTypes as m}from"../../constant/tool.js";import y from"../MathUtils.js";import g from"./PolygonUtils.js";import u,{POINT_RADIUS as P}from"./LineToolUtils.js";var w=Object.defineProperty,_=Object.defineProperties,O=Object.getOwnPropertyDescriptors,p=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,I=(h,t,e)=>t in h?w(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,l=(h,t)=>{for(var e in t||(t={}))v.call(t,e)&&I(h,e,t[e]);if(p)for(var e of p(t))R.call(t,e)&&I(h,e,t[e]);return h},x=(h,t)=>_(h,O(t));class T{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,o,n,s){return typeof o=="boolean"&&!o&&(n&&s?(t.x-e.x>(n.x+n.width)*s&&(t.x=(n.x+n.width)*s+e.x),t.x-e.x<n.x*s&&(t.x=n.x*s+e.x),t.y-e.y>(n.y+n.height)*s&&(t.y=(n.y+n.height)*s+e.y),t.y-e.y<n.y*s&&(t.y=n.y*s+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:o,height:n}=i,{x:s,y:r}=t;switch(e%360){case 90:return{x:n-r,y:s};case 180:return{x:o-s,y:n-r};case 270:return{x:r,y:o-s};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return x(l({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return x(l({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(o=>this.changePointByZoom(o,e,i))}static axisArea(t,e=3){const{x:i,y:o}=t,n=[];for(let s=i-e;s<i+e;s+=e/3)for(let r=o-e;r<o+e;r+=e/3)n.push({x:s,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let o=-1;for(let n=0;n<e.length;n++){const s=e[n];this.getIsInScope(t,s,i)&&(o=n)}return o}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class D{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===f.Polygon}get isDependRect(){return this.dependToolName===f.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:o,width:n,height:s}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[o,o+s])}}getPolygonPointList(t,e){return t===m.Curve?g.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const o=this.getRenderCoord(e),n=this.getRenderCoord(t),s={pointA:o,pointB:n};return u.calcOptimalIntersection(i,s,o,P,this.zoom)}coordInsidePolygon(t,e,i,o){const{pointList:n}=i,s=o==null?void 0:o.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(s,n);if(g.isInPolygon(t,r))return t;const c=r.concat(r[0]).map(d=>this.getRenderCoord(d)),a=this.getIntersection(t,e,c);return a?this.getAbsCoord(a==null?void 0:a.point):t}coordInsideImage(t){return this.coordInsideRect(t,x(l({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:o,height:n}=this.basicResult,s=[e,e+o],r=[i,i+n];return y.isInRange(t.x,s)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return g.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{D as CoordinateUtils,T as default};
1
+ import{EToolName as u,ELineTypes as C}from"../../constant/tool.js";import y from"../MathUtils.js";import x from"./PolygonUtils.js";import _,{POINT_RADIUS as v}from"./LineToolUtils.js";import{getHighlightPoints as P,getHighlightLines as m,getCuboidHoverRange as L}from"./CuboidUtils.js";var B=Object.defineProperty,R=Object.defineProperties,D=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,w=(a,t,e)=>t in a?B(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&w(a,e,t[e]);if(O)for(var e of O(t))Z.call(t,e)&&w(a,e,t[e]);return a},c=(a,t)=>R(a,D(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:r}=t;switch(e%360){case 90:return{x:n-r,y:o};case 180:return{x:s-o,y:n-r};case 270:return{x:r,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static changePlanePointByZoom(t,e,i={x:0,y:0}){return Object.entries(t).reduce((s,[n,o])=>{const r=I.changePointByZoom(o,e,i);return c(f({},s),{[n]:r})},{})}static changeCuboidByZoom(t,e,i={x:0,y:0}){return c(f({},t),{frontPoints:this.changePlanePointByZoom(t.frontPoints,e,i),backPoints:t.backPoints?this.changePlanePointByZoom(t.backPoints,e,i):t.backPoints})}static transformPlain2PointList({tl:t,tr:e,br:i,bl:s}){return[t,e,i,s]}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let r=s-e;r<s+e;r+=e/3)n.push({x:o,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static isCloseCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5}=i;for(let r=0;r<s.length;r++){const l=s[r];if(this.getIsInScope(t,l.point,n))return!0}const o=m(e);for(let r=0;r<o.length;r++){const l=o[r],{length:p}=y.getFootOfPerpendicular(t,l.p1,l.p2,!0);if(p<n)return!0}return!!x.isInPolygon(t,L(e))}static isCloseCuboidList(t,e,i={scope:5,zoom:1}){return e.some(s=>this.isCloseCuboid(t,s,i))}static returnClosePointOrLineInCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5,zoom:o=1}=i;for(let h=0;h<s.length;h++){const g=s[h];if(this.getIsInScope(t,g.point,n))return[{type:"point",points:[this.changePointByZoom(s[h].point,o)],originCuboid:e,positions:g.positions}]}let r=n;const l=m(e);let p;for(let h=0;h<l.length;h++){const g=l[h],{length:d}=y.getFootOfPerpendicular(t,g.p1,g.p2,!0);d<r&&(r=d,p=[{type:"line",points:this.changePointListByZoom([g.p1,g.p2],o),originCuboid:e,positions:g.positions}])}if(p)return p}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class b{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===u.Polygon}get isDependRect(){return this.dependToolName===u.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===C.Curve?x.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return _.calcOptimalIntersection(i,o,s,v,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(o,n);if(x.isInPolygon(t,r))return t;const p=r.concat(r[0]).map(g=>this.getRenderCoord(g)),h=this.getIntersection(t,e,p);return h?this.getAbsCoord(h==null?void 0:h.point):t}coordInsideImage(t){return this.coordInsideRect(t,c(f({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],r=[i,i+n];return y.isInRange(t.x,o)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return x.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{b as CoordinateUtils,I as default};