@labelbee/lb-annotation 1.12.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -0
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/cuboidOperation.js +733 -0
- package/es/core/toolOperation/cuboidToggleButtonClass.js +174 -0
- package/es/utils/tool/CuboidUtils.js +663 -0
- package/package.json +2 -2
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash';
|
|
2
|
+
import { ECuboidPlain, ECuboidPosition, ECuboidDirection, EDragTarget, DIAGONAL_POINT, ECuboidLineDirection, CUBOID_ROW, CUBOID_COLUMN } from '../../constant/annotation.js';
|
|
3
|
+
import AxisUtils from './AxisUtils.js';
|
|
4
|
+
import Vector from '../VectorUtils.js';
|
|
5
|
+
import LineToolUtils from './LineToolUtils.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
|
+
function getPlanePointsBasicInfo({tr, tl, br}) {
|
|
27
|
+
return {
|
|
28
|
+
width: Math.abs(tr.x - tl.x),
|
|
29
|
+
height: Math.abs(br.y - tr.y),
|
|
30
|
+
centerPoints: {
|
|
31
|
+
x: (tl.x + br.x) / 2,
|
|
32
|
+
y: (tl.y + br.y) / 2
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getCuboidBasicInfo({
|
|
37
|
+
frontPoints,
|
|
38
|
+
backPoints
|
|
39
|
+
}) {
|
|
40
|
+
const {width: frontWidth, height: frontHeight, centerPoints: frontCenter} = getPlanePointsBasicInfo(frontPoints);
|
|
41
|
+
const {width: backWidth, height: backHeight, centerPoints: backCenter} = getPlanePointsBasicInfo(backPoints);
|
|
42
|
+
return {
|
|
43
|
+
frontCenter,
|
|
44
|
+
backCenter,
|
|
45
|
+
frontWidth,
|
|
46
|
+
frontHeight,
|
|
47
|
+
backWidth,
|
|
48
|
+
backHeight,
|
|
49
|
+
isLeftSide: backCenter.x < frontCenter.x
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getPlainPointsByDiagonalPoints(p1, p2) {
|
|
53
|
+
return {
|
|
54
|
+
tl: {
|
|
55
|
+
x: Math.min(p1.x, p2.x),
|
|
56
|
+
y: Math.min(p1.y, p2.y)
|
|
57
|
+
},
|
|
58
|
+
tr: {
|
|
59
|
+
x: Math.max(p1.x, p2.x),
|
|
60
|
+
y: Math.min(p1.y, p2.y)
|
|
61
|
+
},
|
|
62
|
+
bl: {
|
|
63
|
+
x: Math.min(p1.x, p2.x),
|
|
64
|
+
y: Math.max(p1.y, p2.y)
|
|
65
|
+
},
|
|
66
|
+
br: {
|
|
67
|
+
x: Math.max(p1.x, p2.x),
|
|
68
|
+
y: Math.max(p1.y, p2.y)
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function getMaxExternalQuadrilateral(points) {
|
|
73
|
+
const minX = Object.values(points).reduce((acc, coord) => coord.x < acc ? coord.x : acc, Number.MAX_SAFE_INTEGER);
|
|
74
|
+
const maxX = Object.values(points).reduce((acc, coord) => coord.x > acc ? coord.x : acc, 0);
|
|
75
|
+
const minY = Object.values(points).reduce((acc, coord) => coord.y < acc ? coord.y : acc, Number.MAX_SAFE_INTEGER);
|
|
76
|
+
const maxY = Object.values(points).reduce((acc, coord) => coord.y > acc ? coord.y : acc, 0);
|
|
77
|
+
return {
|
|
78
|
+
tl: {
|
|
79
|
+
x: minX,
|
|
80
|
+
y: minY
|
|
81
|
+
},
|
|
82
|
+
tr: {
|
|
83
|
+
x: maxX,
|
|
84
|
+
y: minY
|
|
85
|
+
},
|
|
86
|
+
bl: {
|
|
87
|
+
x: minX,
|
|
88
|
+
y: maxY
|
|
89
|
+
},
|
|
90
|
+
br: {
|
|
91
|
+
x: maxX,
|
|
92
|
+
y: maxY
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function judgeCuboidLineIsRowOrColumn(pointList) {
|
|
97
|
+
const [firstPosition, secondPosition] = pointList;
|
|
98
|
+
if (CUBOID_ROW[firstPosition.position] === secondPosition.position) {
|
|
99
|
+
return ECuboidLineDirection.Row;
|
|
100
|
+
}
|
|
101
|
+
if (CUBOID_COLUMN[firstPosition.position] === secondPosition.position) {
|
|
102
|
+
return ECuboidLineDirection.Column;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function getPointsByBottomRightPoint({
|
|
106
|
+
coord,
|
|
107
|
+
points
|
|
108
|
+
}) {
|
|
109
|
+
const {width, height} = getPlanePointsBasicInfo(points);
|
|
110
|
+
return {
|
|
111
|
+
br: coord,
|
|
112
|
+
tr: {
|
|
113
|
+
x: coord.x,
|
|
114
|
+
y: coord.y - height
|
|
115
|
+
},
|
|
116
|
+
tl: {
|
|
117
|
+
x: coord.x - width,
|
|
118
|
+
y: coord.y - height
|
|
119
|
+
},
|
|
120
|
+
bl: {
|
|
121
|
+
x: coord.x - width,
|
|
122
|
+
y: coord.y
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function getPointsByBottomLeftPoint({
|
|
127
|
+
coord,
|
|
128
|
+
points
|
|
129
|
+
}) {
|
|
130
|
+
const {width, height} = getPlanePointsBasicInfo(points);
|
|
131
|
+
return {
|
|
132
|
+
bl: coord,
|
|
133
|
+
tr: {
|
|
134
|
+
x: coord.x + width,
|
|
135
|
+
y: coord.y - height
|
|
136
|
+
},
|
|
137
|
+
tl: {
|
|
138
|
+
x: coord.x,
|
|
139
|
+
y: coord.y - height
|
|
140
|
+
},
|
|
141
|
+
br: {
|
|
142
|
+
x: coord.x + width,
|
|
143
|
+
y: coord.y
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function getCuboidShowingSideLine({
|
|
148
|
+
frontPoints,
|
|
149
|
+
backPoints
|
|
150
|
+
}) {
|
|
151
|
+
const {isLeftSide} = getCuboidBasicInfo({frontPoints, backPoints});
|
|
152
|
+
if (isLeftSide) {
|
|
153
|
+
return {
|
|
154
|
+
top: {
|
|
155
|
+
p1: frontPoints.tl,
|
|
156
|
+
p2: backPoints.tl
|
|
157
|
+
},
|
|
158
|
+
bottom: {
|
|
159
|
+
p1: frontPoints.bl,
|
|
160
|
+
p2: backPoints.bl
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
top: {
|
|
166
|
+
p1: frontPoints.tr,
|
|
167
|
+
p2: backPoints.tr
|
|
168
|
+
},
|
|
169
|
+
bottom: {
|
|
170
|
+
p1: frontPoints.br,
|
|
171
|
+
p2: backPoints.br
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function getPointsByIntersection({
|
|
176
|
+
frontPoints,
|
|
177
|
+
backPoints
|
|
178
|
+
}) {
|
|
179
|
+
const {isLeftSide} = getCuboidBasicInfo({frontPoints, backPoints});
|
|
180
|
+
let newBackPoints = __spreadValues({}, backPoints);
|
|
181
|
+
const sideLine = getCuboidShowingSideLine({frontPoints, backPoints});
|
|
182
|
+
const intersectionPoint = LineToolUtils.lineIntersection({pointA: sideLine.bottom.p1, pointB: sideLine.bottom.p2}, {pointA: sideLine.top.p1, pointB: sideLine.top.p2});
|
|
183
|
+
if (isLeftSide) {
|
|
184
|
+
const newBRPoint = LineToolUtils.lineIntersection({pointA: backPoints.bl, pointB: backPoints.br}, {pointA: frontPoints.br, pointB: intersectionPoint});
|
|
185
|
+
if (newBRPoint) {
|
|
186
|
+
newBackPoints = __spreadProps(__spreadValues({}, backPoints), {
|
|
187
|
+
br: newBRPoint,
|
|
188
|
+
tr: {
|
|
189
|
+
x: newBRPoint.x,
|
|
190
|
+
y: backPoints.tl.y
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
const newBLPoint = LineToolUtils.lineIntersection({pointA: backPoints.bl, pointB: backPoints.br}, {pointA: frontPoints.bl, pointB: intersectionPoint});
|
|
196
|
+
if (newBLPoint) {
|
|
197
|
+
newBackPoints = __spreadProps(__spreadValues({}, backPoints), {
|
|
198
|
+
bl: newBLPoint,
|
|
199
|
+
tl: {
|
|
200
|
+
x: newBLPoint.x,
|
|
201
|
+
y: backPoints.tr.y
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
backPoints: newBackPoints
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function getBackPointsByFrontPoints({
|
|
211
|
+
frontPoints,
|
|
212
|
+
backPoints
|
|
213
|
+
}) {
|
|
214
|
+
const {isLeftSide, frontHeight, backHeight} = getCuboidBasicInfo({frontPoints, backPoints});
|
|
215
|
+
let newBackPoints = __spreadValues({}, backPoints);
|
|
216
|
+
if (isLeftSide) {
|
|
217
|
+
newBackPoints = getPointsByBottomLeftPoint({coord: backPoints.bl, points: frontPoints});
|
|
218
|
+
} else {
|
|
219
|
+
newBackPoints = getPointsByBottomRightPoint({coord: backPoints.br, points: frontPoints});
|
|
220
|
+
}
|
|
221
|
+
if (frontHeight > backHeight) {
|
|
222
|
+
newBackPoints = getPointsByIntersection({frontPoints, backPoints}).backPoints;
|
|
223
|
+
}
|
|
224
|
+
return {frontPoints, backPoints: newBackPoints};
|
|
225
|
+
}
|
|
226
|
+
function getFrontPointsByBackPoints({
|
|
227
|
+
frontPoints,
|
|
228
|
+
backPoints
|
|
229
|
+
}) {
|
|
230
|
+
const {isLeftSide, frontHeight, backHeight, frontWidth, backWidth} = getCuboidBasicInfo({
|
|
231
|
+
frontPoints,
|
|
232
|
+
backPoints
|
|
233
|
+
});
|
|
234
|
+
let newFrontPoints = __spreadValues({}, frontPoints);
|
|
235
|
+
let newBackPoints = backPoints;
|
|
236
|
+
if (isLeftSide || backWidth > frontWidth) {
|
|
237
|
+
newFrontPoints = getPointsByBottomLeftPoint({coord: frontPoints.bl, points: backPoints});
|
|
238
|
+
} else {
|
|
239
|
+
newFrontPoints = getPointsByBottomRightPoint({coord: frontPoints.br, points: backPoints});
|
|
240
|
+
}
|
|
241
|
+
if (frontHeight > backHeight) {
|
|
242
|
+
newFrontPoints.tl.y = frontPoints.tl.y;
|
|
243
|
+
newFrontPoints.tr.y = frontPoints.tr.y;
|
|
244
|
+
newBackPoints = getPointsByIntersection({backPoints, frontPoints}).backPoints;
|
|
245
|
+
}
|
|
246
|
+
if (frontWidth >= backWidth) {
|
|
247
|
+
Object.keys(newFrontPoints).forEach((key) => {
|
|
248
|
+
newFrontPoints[key].x = frontPoints[key].x;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
frontPoints: newFrontPoints,
|
|
253
|
+
backPoints: newBackPoints
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function getCuboidAllSideLine({frontPoints, backPoints}) {
|
|
257
|
+
return [
|
|
258
|
+
{
|
|
259
|
+
p1: frontPoints.bl,
|
|
260
|
+
p2: backPoints.bl
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
p1: frontPoints.tl,
|
|
264
|
+
p2: backPoints.tl
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
p1: frontPoints.tr,
|
|
268
|
+
p2: backPoints.tr
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
p1: frontPoints.br,
|
|
272
|
+
p2: backPoints.br
|
|
273
|
+
}
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
function getHighlightLines(cuboid) {
|
|
277
|
+
const {frontPoints, backPoints} = cuboid;
|
|
278
|
+
const {isLeftSide} = getCuboidBasicInfo(cuboid);
|
|
279
|
+
const frontLine = [
|
|
280
|
+
{
|
|
281
|
+
p1: frontPoints.tl,
|
|
282
|
+
p2: frontPoints.tr,
|
|
283
|
+
positions: [
|
|
284
|
+
{
|
|
285
|
+
plain: ECuboidPlain.Front,
|
|
286
|
+
position: ECuboidPosition.TL
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
plain: ECuboidPlain.Front,
|
|
290
|
+
position: ECuboidPosition.TR
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
p1: frontPoints.tr,
|
|
296
|
+
p2: frontPoints.br,
|
|
297
|
+
plain: ECuboidPlain.Front,
|
|
298
|
+
positions: [
|
|
299
|
+
{
|
|
300
|
+
plain: ECuboidPlain.Front,
|
|
301
|
+
position: ECuboidPosition.TR
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
plain: ECuboidPlain.Front,
|
|
305
|
+
position: ECuboidPosition.BR
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
p1: frontPoints.br,
|
|
311
|
+
p2: frontPoints.bl,
|
|
312
|
+
plain: ECuboidPlain.Front,
|
|
313
|
+
positions: [
|
|
314
|
+
{
|
|
315
|
+
plain: ECuboidPlain.Front,
|
|
316
|
+
position: ECuboidPosition.BR
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
plain: ECuboidPlain.Front,
|
|
320
|
+
position: ECuboidPosition.BL
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
p1: frontPoints.bl,
|
|
326
|
+
p2: frontPoints.tl,
|
|
327
|
+
plain: ECuboidPlain.Front,
|
|
328
|
+
positions: [
|
|
329
|
+
{
|
|
330
|
+
plain: ECuboidPlain.Front,
|
|
331
|
+
position: ECuboidPosition.BL
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
plain: ECuboidPlain.Front,
|
|
335
|
+
position: ECuboidPosition.TL
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
];
|
|
340
|
+
if (isLeftSide) {
|
|
341
|
+
return [
|
|
342
|
+
...frontLine,
|
|
343
|
+
{
|
|
344
|
+
p1: backPoints.tl,
|
|
345
|
+
p2: backPoints.bl,
|
|
346
|
+
positions: [
|
|
347
|
+
{
|
|
348
|
+
plain: ECuboidPlain.Back,
|
|
349
|
+
position: ECuboidPosition.TL
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
plain: ECuboidPlain.Back,
|
|
353
|
+
position: ECuboidPosition.BL
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
return [
|
|
360
|
+
...frontLine,
|
|
361
|
+
{
|
|
362
|
+
p1: backPoints.tr,
|
|
363
|
+
p2: backPoints.br,
|
|
364
|
+
positions: [
|
|
365
|
+
{
|
|
366
|
+
plain: ECuboidPlain.Back,
|
|
367
|
+
position: ECuboidPosition.TR
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
plain: ECuboidPlain.Back,
|
|
371
|
+
position: ECuboidPosition.BR
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
function getHighlightPoints(cuboid) {
|
|
378
|
+
const {backPoints} = cuboid;
|
|
379
|
+
const {isLeftSide} = getCuboidBasicInfo(cuboid);
|
|
380
|
+
const frontPointsData = Object.entries(cuboid.frontPoints).map(([position, point]) => ({
|
|
381
|
+
positions: [
|
|
382
|
+
{
|
|
383
|
+
plain: ECuboidPlain.Front,
|
|
384
|
+
position
|
|
385
|
+
}
|
|
386
|
+
],
|
|
387
|
+
point
|
|
388
|
+
}));
|
|
389
|
+
if (isLeftSide) {
|
|
390
|
+
return [
|
|
391
|
+
{point: backPoints.tl, positions: [{position: ECuboidPosition.TL, plain: ECuboidPlain.Back}]},
|
|
392
|
+
{point: backPoints.bl, positions: [{position: ECuboidPosition.BL, plain: ECuboidPlain.Back}]},
|
|
393
|
+
...frontPointsData
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
return [
|
|
397
|
+
{point: backPoints.tr, positions: [{position: ECuboidPosition.TR, plain: ECuboidPlain.Back}]},
|
|
398
|
+
{point: backPoints.br, positions: [{position: ECuboidPosition.BR, plain: ECuboidPlain.Back}]},
|
|
399
|
+
...frontPointsData
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
function getCuboidHoverRange(cuboid) {
|
|
403
|
+
const {frontPoints, backPoints} = cuboid;
|
|
404
|
+
const {backCenter, frontCenter, frontHeight, frontWidth, backHeight, backWidth, isLeftSide} = getCuboidBasicInfo(cuboid);
|
|
405
|
+
const diffWidth = Math.abs(frontWidth - backWidth);
|
|
406
|
+
const diffHeight = Math.abs(frontHeight - backHeight);
|
|
407
|
+
const diffCenterX = Math.abs(frontCenter.x - backCenter.x);
|
|
408
|
+
const diffCenterY = Math.abs(frontCenter.y - backCenter.y);
|
|
409
|
+
const isOverX = diffCenterX > diffWidth;
|
|
410
|
+
const isOverY = diffCenterY > diffHeight;
|
|
411
|
+
const isNested = !(isOverX || isOverY);
|
|
412
|
+
if (isNested) {
|
|
413
|
+
return [frontPoints.tl, frontPoints.tr, frontPoints.br, frontPoints.bl];
|
|
414
|
+
}
|
|
415
|
+
if (isOverY && !isOverX) {
|
|
416
|
+
return [frontPoints.tl, backPoints.tl, backPoints.tr, frontPoints.tr, frontPoints.br, frontPoints.bl];
|
|
417
|
+
}
|
|
418
|
+
if (isOverX && !isOverY) {
|
|
419
|
+
if (isLeftSide) {
|
|
420
|
+
return [frontPoints.tl, frontPoints.tr, frontPoints.br, frontPoints.bl, backPoints.bl, backPoints.tl];
|
|
421
|
+
}
|
|
422
|
+
return [frontPoints.tl, frontPoints.tr, backPoints.tr, backPoints.br, frontPoints.br, frontPoints.bl];
|
|
423
|
+
}
|
|
424
|
+
if (isOverX && isOverY) {
|
|
425
|
+
if (isLeftSide) {
|
|
426
|
+
return [backPoints.tl, backPoints.tr, frontPoints.tr, frontPoints.br, frontPoints.bl, backPoints.bl];
|
|
427
|
+
}
|
|
428
|
+
return [frontPoints.tl, backPoints.tl, backPoints.tr, backPoints.br, frontPoints.br, frontPoints.bl];
|
|
429
|
+
}
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
function getNewPointsAfterOffset({
|
|
433
|
+
offset,
|
|
434
|
+
frontPoints,
|
|
435
|
+
backPoints,
|
|
436
|
+
positions
|
|
437
|
+
}) {
|
|
438
|
+
let newFrontPoints = cloneDeep(frontPoints);
|
|
439
|
+
let newBackPoints = cloneDeep(backPoints);
|
|
440
|
+
if ((positions == null ? void 0 : positions.length) === 2) {
|
|
441
|
+
const isFrontPlain = positions.every((v) => v.plain === ECuboidPlain.Front);
|
|
442
|
+
const isBackPlain = !isFrontPlain;
|
|
443
|
+
const lineDirection = judgeCuboidLineIsRowOrColumn([positions[0], positions[1]]);
|
|
444
|
+
const forbidX = lineDirection === ECuboidLineDirection.Row;
|
|
445
|
+
const forbidY = lineDirection === ECuboidLineDirection.Column;
|
|
446
|
+
let newOffset = offset;
|
|
447
|
+
if (forbidX) {
|
|
448
|
+
newOffset = {
|
|
449
|
+
x: 0,
|
|
450
|
+
y: offset.y
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
if (forbidY) {
|
|
454
|
+
newOffset = {
|
|
455
|
+
y: 0,
|
|
456
|
+
x: offset.x
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (isFrontPlain) {
|
|
460
|
+
positions == null ? void 0 : positions.forEach(({position}) => {
|
|
461
|
+
const points = newFrontPoints;
|
|
462
|
+
const movePoint = points[position];
|
|
463
|
+
points[position] = {
|
|
464
|
+
x: movePoint.x + newOffset.x,
|
|
465
|
+
y: movePoint.y + newOffset.y
|
|
466
|
+
};
|
|
467
|
+
});
|
|
468
|
+
newFrontPoints = getMaxExternalQuadrilateral(newFrontPoints);
|
|
469
|
+
newBackPoints = getMaxExternalQuadrilateral(newBackPoints);
|
|
470
|
+
}
|
|
471
|
+
if (isBackPlain) {
|
|
472
|
+
Object.keys(newBackPoints).forEach((key) => {
|
|
473
|
+
newBackPoints[key] = {
|
|
474
|
+
x: newBackPoints[key].x + newOffset.x,
|
|
475
|
+
y: newBackPoints[key].y + newOffset.y
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
const getNewPlainPoints = isFrontPlain ? getBackPointsByFrontPoints : getFrontPointsByBackPoints;
|
|
480
|
+
const {frontPoints: newFrontPoints2, backPoints: newBackPoints2} = getNewPlainPoints({
|
|
481
|
+
frontPoints: newFrontPoints,
|
|
482
|
+
backPoints: newBackPoints
|
|
483
|
+
});
|
|
484
|
+
newFrontPoints = newFrontPoints2;
|
|
485
|
+
newBackPoints = newBackPoints2;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
frontPoints: newFrontPoints,
|
|
489
|
+
backPoints: newBackPoints
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function getCuboidDragMove({
|
|
493
|
+
offset,
|
|
494
|
+
cuboid,
|
|
495
|
+
dragTarget,
|
|
496
|
+
positions
|
|
497
|
+
}) {
|
|
498
|
+
const {frontPoints, backPoints} = cuboid;
|
|
499
|
+
switch (dragTarget) {
|
|
500
|
+
case EDragTarget.Cuboid: {
|
|
501
|
+
const newFrontPoints = Object.entries(frontPoints).reduce((acc, [key, point]) => {
|
|
502
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
503
|
+
[key]: {
|
|
504
|
+
x: point.x + offset.x,
|
|
505
|
+
y: point.y + offset.y
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}, {});
|
|
509
|
+
const newBackPoints = Object.entries(backPoints).reduce((acc, [key, point]) => {
|
|
510
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
511
|
+
[key]: {
|
|
512
|
+
x: point.x + offset.x,
|
|
513
|
+
y: point.y + offset.y
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}, {});
|
|
517
|
+
return __spreadProps(__spreadValues({}, cuboid), {
|
|
518
|
+
frontPoints: newFrontPoints,
|
|
519
|
+
backPoints: newBackPoints
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
case EDragTarget.Line: {
|
|
523
|
+
const {frontPoints: newFrontPoints, backPoints: newBackPoints} = getNewPointsAfterOffset({
|
|
524
|
+
offset,
|
|
525
|
+
frontPoints,
|
|
526
|
+
backPoints,
|
|
527
|
+
positions
|
|
528
|
+
});
|
|
529
|
+
return __spreadProps(__spreadValues({}, cuboid), {
|
|
530
|
+
frontPoints: newFrontPoints,
|
|
531
|
+
backPoints: newBackPoints
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
case EDragTarget.Point: {
|
|
535
|
+
if (!(positions == null ? void 0 : positions[0])) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const pointPosition = positions[0];
|
|
539
|
+
const isFrontPlain = pointPosition.plain === ECuboidPlain.Front;
|
|
540
|
+
const movePoints = isFrontPlain ? frontPoints : backPoints;
|
|
541
|
+
let movePoint = movePoints[pointPosition.position];
|
|
542
|
+
const diagonalPoint = movePoints[DIAGONAL_POINT[pointPosition.position]];
|
|
543
|
+
if (!movePoint || !diagonalPoint) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
movePoint = Vector.add(movePoint, offset);
|
|
547
|
+
const newPlainsPoints = getPlainPointsByDiagonalPoints(movePoint, diagonalPoint);
|
|
548
|
+
const getNewPlainPoints = isFrontPlain ? getBackPointsByFrontPoints : getFrontPointsByBackPoints;
|
|
549
|
+
let payload = {
|
|
550
|
+
frontPoints,
|
|
551
|
+
backPoints: newPlainsPoints
|
|
552
|
+
};
|
|
553
|
+
if (isFrontPlain) {
|
|
554
|
+
payload = {
|
|
555
|
+
frontPoints: newPlainsPoints,
|
|
556
|
+
backPoints
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
const {frontPoints: newFrontPoints, backPoints: newBackPoints} = getNewPlainPoints(payload);
|
|
560
|
+
return __spreadProps(__spreadValues({}, cuboid), {
|
|
561
|
+
frontPoints: newFrontPoints,
|
|
562
|
+
backPoints: newBackPoints
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
default: {
|
|
566
|
+
console.error("No DragTarget");
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function getPointListsByDirection({
|
|
572
|
+
direction,
|
|
573
|
+
frontPoints,
|
|
574
|
+
backPoints
|
|
575
|
+
}) {
|
|
576
|
+
if (direction && frontPoints && backPoints) {
|
|
577
|
+
let points = frontPoints;
|
|
578
|
+
switch (direction) {
|
|
579
|
+
case ECuboidDirection.Back:
|
|
580
|
+
points = backPoints;
|
|
581
|
+
break;
|
|
582
|
+
case ECuboidDirection.Left:
|
|
583
|
+
points = {
|
|
584
|
+
bl: backPoints.bl,
|
|
585
|
+
br: frontPoints.bl,
|
|
586
|
+
tl: backPoints.tl,
|
|
587
|
+
tr: frontPoints.tl
|
|
588
|
+
};
|
|
589
|
+
break;
|
|
590
|
+
case ECuboidDirection.Right:
|
|
591
|
+
points = {
|
|
592
|
+
bl: backPoints.br,
|
|
593
|
+
br: frontPoints.br,
|
|
594
|
+
tl: backPoints.tr,
|
|
595
|
+
tr: frontPoints.tr
|
|
596
|
+
};
|
|
597
|
+
break;
|
|
598
|
+
case ECuboidDirection.Top:
|
|
599
|
+
points = {
|
|
600
|
+
bl: backPoints.tl,
|
|
601
|
+
br: frontPoints.tl,
|
|
602
|
+
tl: backPoints.tr,
|
|
603
|
+
tr: frontPoints.tr
|
|
604
|
+
};
|
|
605
|
+
break;
|
|
606
|
+
default:
|
|
607
|
+
points = frontPoints;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
return AxisUtils.transformPlain2PointList(points);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function getToggleDirectionButtonOffset({
|
|
614
|
+
cuboid,
|
|
615
|
+
currentPos,
|
|
616
|
+
zoom
|
|
617
|
+
}) {
|
|
618
|
+
const {frontPoints} = cuboid;
|
|
619
|
+
const toggleSize = {
|
|
620
|
+
width: 40,
|
|
621
|
+
height: 74
|
|
622
|
+
};
|
|
623
|
+
const frontPointsCenter = {
|
|
624
|
+
x: (frontPoints.bl.x + frontPoints.tl.x) / 2,
|
|
625
|
+
y: (frontPoints.bl.y + frontPoints.tl.y) / 2
|
|
626
|
+
};
|
|
627
|
+
const leftOffset = toggleSize.width + 10;
|
|
628
|
+
const topOffset = toggleSize.height / 2;
|
|
629
|
+
const moveCoordinate = {
|
|
630
|
+
x: frontPointsCenter.x,
|
|
631
|
+
y: frontPointsCenter.y
|
|
632
|
+
};
|
|
633
|
+
const coordinate = AxisUtils.getOffsetCoordinate(moveCoordinate, currentPos, zoom);
|
|
634
|
+
return {
|
|
635
|
+
left: coordinate.x - leftOffset,
|
|
636
|
+
top: coordinate.y - topOffset
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function getCuboidTextAttributeOffset({
|
|
640
|
+
cuboid,
|
|
641
|
+
currentPos,
|
|
642
|
+
zoom,
|
|
643
|
+
leftOffset = 16,
|
|
644
|
+
topOffset = 2
|
|
645
|
+
}) {
|
|
646
|
+
const {frontPoints} = cuboid;
|
|
647
|
+
const moveCoordinate = {
|
|
648
|
+
x: frontPoints.bl.x,
|
|
649
|
+
y: frontPoints.bl.y
|
|
650
|
+
};
|
|
651
|
+
const coordinate = AxisUtils.getOffsetCoordinate(moveCoordinate, currentPos, zoom);
|
|
652
|
+
return {
|
|
653
|
+
left: coordinate.x + leftOffset,
|
|
654
|
+
top: coordinate.y + topOffset
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function isCuboidWithInLimits({cuboid, config}) {
|
|
658
|
+
const {minHeight, minWidth} = config;
|
|
659
|
+
const {width, height} = getPlanePointsBasicInfo(cuboid.frontPoints);
|
|
660
|
+
return width >= minWidth && height >= minHeight;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export { getBackPointsByFrontPoints, getCuboidAllSideLine, getCuboidBasicInfo, getCuboidDragMove, getCuboidHoverRange, getCuboidShowingSideLine, getCuboidTextAttributeOffset, getFrontPointsByBackPoints, getHighlightLines, getHighlightPoints, getMaxExternalQuadrilateral, getNewPointsAfterOffset, getPlainPointsByDiagonalPoints, getPlanePointsBasicInfo, getPointListsByDirection, getPointsByBottomLeftPoint, getPointsByBottomRightPoint, getPointsByIntersection, getToggleDirectionButtonOffset, isCuboidWithInLimits, judgeCuboidLineIsRowOrColumn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"lodash": "^4.17.20",
|
|
99
99
|
"three": ">=0.141.0"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "e9187ef6810e0475ee96c00da542e74aca2c0110"
|
|
102
102
|
}
|