Skip to content

Commit 4afe683

Browse files
committed
Update imports
1 parent 4bb6976 commit 4afe683

File tree

12 files changed

+124
-80
lines changed

12 files changed

+124
-80
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (C) 2022-2025 Intel Corporation
2+
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
3+
4+
import '@wessberg/pointer-events';
5+
6+
import { Anchor } from '@geti/smart-tools';
7+
import { fireEvent, render, screen } from '@testing-library/react';
8+
9+
describe('anchor', (): void => {
10+
const properties = {
11+
x: 10,
12+
y: 10,
13+
angle: 0,
14+
size: 10,
15+
zoom: 1,
16+
label: 'test-label',
17+
cursor: 'nw-resize',
18+
onComplete: jest.fn(),
19+
moveAnchorTo: jest.fn(),
20+
};
21+
22+
it('calls moveAnchorTo when clicked upon and moved', () => {
23+
const moveAnchorCallback = jest.fn();
24+
render(
25+
<svg>
26+
<Anchor {...properties} moveAnchorTo={moveAnchorCallback}>
27+
<rect></rect>
28+
</Anchor>
29+
</svg>
30+
);
31+
const anchorActor = screen.getByLabelText(properties.label);
32+
fireEvent.pointerDown(anchorActor);
33+
fireEvent.pointerMove(anchorActor, { clientX: 10, clientY: 10 });
34+
expect(moveAnchorCallback).toHaveBeenCalledTimes(1);
35+
});
36+
37+
it('calls onComplete when clicked and released', () => {
38+
const onCompleteCallback = jest.fn();
39+
render(
40+
<svg>
41+
<Anchor {...properties} onComplete={onCompleteCallback}>
42+
<rect></rect>
43+
</Anchor>
44+
</svg>
45+
);
46+
const anchorActor = screen.getByLabelText(properties.label);
47+
fireEvent.pointerDown(anchorActor);
48+
fireEvent.pointerMove(anchorActor, { clientX: 10, clientY: 10 });
49+
fireEvent.pointerUp(anchorActor);
50+
expect(onCompleteCallback).toHaveBeenCalledTimes(1);
51+
});
52+
});

web_ui/src/pages/annotator/tools/edit-tool/edit-annotation-tool.component.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import { RefObject, useRef } from 'react';
55

6+
import { EditBoundingBox as EditBoundingBoxTool } from '@geti/smart-tools';
7+
68
import { Annotation, KeypointAnnotation } from '../../../../core/annotations/annotation.interface';
79
import { ShapeType } from '../../../../core/annotations/shapetype.enum';
810
import { useOutsideClick } from '../../../../hooks/outside-click/outside-click.hook';
@@ -16,7 +18,7 @@ import { useTask } from '../../providers/task-provider/task-provider.component';
1618
import { useZoom } from '../../zoom/zoom-provider.component';
1719
import { SelectingToolType } from '../selecting-tool/selecting-tool.enums';
1820
import { ToolAnnotationContextProps } from '../tools.interface';
19-
import { EditBoundingBox as EditBoundingBoxTool } from './edit-bounding-box/edit-bounding-box.component';
21+
import { convertToolShapeToGetiShape } from '../utils';
2022
import { EditCircle as EditCircleTool } from './edit-circle/edit-circle.component';
2123
import { EditKeypointTool } from './edit-keypoint/edit-keypoint-tool.component';
2224
import { EditPolygon as EditPolygonTool } from './edit-polygon/edit-polygon.component';
@@ -54,7 +56,13 @@ const EditAnnotationToolFactory = ({
5456
roi={roi}
5557
image={image}
5658
zoom={zoom}
57-
updateAnnotation={scene.updateAnnotation}
59+
updateAnnotation={(newAnnotation) => {
60+
scene.updateAnnotation({
61+
...newAnnotation,
62+
shape: convertToolShapeToGetiShape(newAnnotation.shape),
63+
labels: annotation.labels,
64+
});
65+
}}
5866
annotation={annotation as Annotation & { shape: { shapeType: ShapeType.Rect } }}
5967
disableTranslation={disableTranslation}
6068
disablePoints={disablePoints}

web_ui/src/pages/annotator/tools/edit-tool/edit-bounding-box/edit-bounding-box.test.tsx renamed to web_ui/src/pages/annotator/tools/edit-tool/edit-bounding-box.test.tsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33

44
import '@wessberg/pointer-events';
55

6-
import { ANCHOR_SIZE } from '@geti/smart-tools';
6+
import { ANCHOR_SIZE, EditBoundingBox as EditBoundingBoxTool } from '@geti/smart-tools';
7+
import { Annotation, RegionOfInterest } from '@geti/smart-tools/types';
78
import { fireEvent, screen } from '@testing-library/react';
89

9-
import { Annotation, RegionOfInterest } from '../../../../../core/annotations/annotation.interface';
10-
import { ShapeType } from '../../../../../core/annotations/shapetype.enum';
11-
import { getMockedImage, getMockedROI } from '../../../../../test-utils/utils';
12-
import { AnnotationToolProvider } from '../../../providers/annotation-tool-provider/annotation-tool-provider.component';
13-
import { annotatorRender as render } from '../../../test-utils/annotator-render';
14-
import { EditBoundingBox as EditBoundingBoxTool } from './edit-bounding-box.component';
10+
import { getMockedImage, getMockedROI } from '../../../../test-utils/utils';
11+
import { AnnotationToolProvider } from '../../providers/annotation-tool-provider/annotation-tool-provider.component';
12+
import { annotatorRender as render } from '../../test-utils/annotator-render';
1513

1614
const mockROI = getMockedROI({ x: 0, y: 0, width: 1000, height: 1000 });
1715
const mockImage = getMockedImage(mockROI);
@@ -21,7 +19,7 @@ const zoom = 2.0;
2119
const renderApp = async (
2220
annotation: Annotation & {
2321
shape: {
24-
shapeType: ShapeType.Rect;
22+
shapeType: 'rect';
2523
};
2624
},
2725
roi?: RegionOfInterest
@@ -45,7 +43,7 @@ describe('EditRectangleTool', (): void => {
4543
const annotation = {
4644
id: 'rect-1',
4745
labels: [],
48-
shape: { shapeType: ShapeType.Rect as const, x: 10, y: 10, width: 300, height: 200 },
46+
shape: { shapeType: 'rect' as const, x: 10, y: 10, width: 300, height: 200 },
4947
zIndex: 0,
5048
isHovered: false,
5149
isSelected: false,
@@ -106,7 +104,7 @@ describe('EditRectangleTool', (): void => {
106104
id: 'rect-1',
107105
labels: [],
108106
shape: {
109-
shapeType: ShapeType.Rect as const,
107+
shapeType: 'rect' as const,
110108
x: iRoi.x,
111109
y: iRoi.y,
112110
width: iRoi.width / 2,
@@ -207,7 +205,7 @@ describe('EditRectangleTool', (): void => {
207205
{ x: shape.x, y: shape.y },
208206
{ x: 10, y: 10 },
209207
{
210-
shapeType: ShapeType.Rect,
208+
shapeType: 'rect',
211209
x: shape.x + 10,
212210
y: shape.y + 10,
213211
width: shape.width - 10,
@@ -219,7 +217,7 @@ describe('EditRectangleTool', (): void => {
219217
{ x: shape.x, y: shape.y },
220218
{ x: -10, y: -10 },
221219
{
222-
shapeType: ShapeType.Rect,
220+
shapeType: 'rect',
223221
x: shape.x - 10,
224222
y: shape.y - 10,
225223
width: shape.width + 10,
@@ -231,7 +229,7 @@ describe('EditRectangleTool', (): void => {
231229
{ x: shape.x + shape.width / 2, y: shape.y },
232230
{ x: 10, y: 10 },
233231
{
234-
shapeType: ShapeType.Rect,
232+
shapeType: 'rect',
235233
x: shape.x,
236234
y: shape.y + 10,
237235
width: shape.width,
@@ -243,7 +241,7 @@ describe('EditRectangleTool', (): void => {
243241
{ x: shape.x, y: shape.y },
244242
{ x: -10, y: -10 },
245243
{
246-
shapeType: ShapeType.Rect,
244+
shapeType: 'rect',
247245
x: shape.x,
248246
y: shape.y - 10,
249247
width: shape.width,
@@ -255,7 +253,7 @@ describe('EditRectangleTool', (): void => {
255253
{ x: shape.x + shape.width, y: shape.y },
256254
{ x: 10, y: 10 },
257255
{
258-
shapeType: ShapeType.Rect,
256+
shapeType: 'rect',
259257
x: shape.x,
260258
y: shape.y + 10,
261259
width: shape.width + 10,
@@ -267,7 +265,7 @@ describe('EditRectangleTool', (): void => {
267265
{ x: shape.x + shape.width, y: shape.y },
268266
{ x: -10, y: -10 },
269267
{
270-
shapeType: ShapeType.Rect,
268+
shapeType: 'rect',
271269
x: shape.x,
272270
y: shape.y - 10,
273271
width: shape.width - 10,
@@ -279,7 +277,7 @@ describe('EditRectangleTool', (): void => {
279277
{ x: shape.x + shape.width, y: shape.y + shape.height / 2 },
280278
{ x: 10, y: 10 },
281279
{
282-
shapeType: ShapeType.Rect,
280+
shapeType: 'rect',
283281
x: shape.x,
284282
y: shape.y,
285283
width: shape.width + 10,
@@ -291,7 +289,7 @@ describe('EditRectangleTool', (): void => {
291289
{ x: shape.x + shape.width, y: shape.y + shape.height / 2 },
292290
{ x: -10, y: -10 },
293291
{
294-
shapeType: ShapeType.Rect,
292+
shapeType: 'rect',
295293
x: shape.x,
296294
y: shape.y,
297295
width: shape.width - 10,
@@ -303,7 +301,7 @@ describe('EditRectangleTool', (): void => {
303301
{ x: shape.x + shape.width, y: shape.y + shape.height },
304302
{ x: 10, y: 10 },
305303
{
306-
shapeType: ShapeType.Rect,
304+
shapeType: 'rect',
307305
x: shape.x,
308306
y: shape.y,
309307
width: shape.width + 10,
@@ -315,7 +313,7 @@ describe('EditRectangleTool', (): void => {
315313
{ x: shape.x + shape.width, y: shape.y + shape.height },
316314
{ x: -10, y: -10 },
317315
{
318-
shapeType: ShapeType.Rect,
316+
shapeType: 'rect',
319317
x: shape.x,
320318
y: shape.y,
321319
width: shape.width - 10,
@@ -327,7 +325,7 @@ describe('EditRectangleTool', (): void => {
327325
{ x: shape.x + shape.width / 2, y: shape.y + shape.height },
328326
{ x: 10, y: 10 },
329327
{
330-
shapeType: ShapeType.Rect,
328+
shapeType: 'rect',
331329
x: shape.x,
332330
y: shape.y,
333331
width: shape.width,
@@ -339,7 +337,7 @@ describe('EditRectangleTool', (): void => {
339337
{ x: shape.x + shape.width / 2, y: shape.y + shape.height },
340338
{ x: -10, y: -10 },
341339
{
342-
shapeType: ShapeType.Rect,
340+
shapeType: 'rect',
343341
x: shape.x,
344342
y: shape.y,
345343
width: shape.width,
@@ -351,7 +349,7 @@ describe('EditRectangleTool', (): void => {
351349
{ x: shape.x, y: shape.y + shape.height },
352350
{ x: 10, y: 10 },
353351
{
354-
shapeType: ShapeType.Rect,
352+
shapeType: 'rect',
355353
x: shape.x + 10,
356354
y: shape.y,
357355
width: shape.width - 10,
@@ -363,7 +361,7 @@ describe('EditRectangleTool', (): void => {
363361
{ x: shape.x, y: shape.y + shape.height },
364362
{ x: -10, y: -10 },
365363
{
366-
shapeType: ShapeType.Rect,
364+
shapeType: 'rect',
367365
x: shape.x - 10,
368366
y: shape.y,
369367
width: shape.width + 10,
@@ -375,7 +373,7 @@ describe('EditRectangleTool', (): void => {
375373
{ x: shape.x, y: shape.y + shape.height / 2 },
376374
{ x: 10, y: 10 },
377375
{
378-
shapeType: ShapeType.Rect,
376+
shapeType: 'rect',
379377
x: shape.x + 10,
380378
y: shape.y,
381379
width: shape.width - 10,
@@ -387,7 +385,7 @@ describe('EditRectangleTool', (): void => {
387385
{ x: shape.x, y: shape.y + shape.height / 2 },
388386
{ x: -10, y: -10 },
389387
{
390-
shapeType: ShapeType.Rect,
388+
shapeType: 'rect',
391389
x: shape.x - 10,
392390
y: shape.y,
393391
width: shape.width + 10,
@@ -400,7 +398,7 @@ describe('EditRectangleTool', (): void => {
400398
{ x: shape.x, y: shape.y },
401399
{ x: -20, y: -20 },
402400
{
403-
shapeType: ShapeType.Rect,
401+
shapeType: 'rect',
404402
x: 0,
405403
y: 0,
406404
width: shape.width + shape.x,
@@ -412,7 +410,7 @@ describe('EditRectangleTool', (): void => {
412410
{ x: shape.x + shape.width / 2, y: shape.y },
413411
{ x: 10, y: -20 },
414412
{
415-
shapeType: ShapeType.Rect,
413+
shapeType: 'rect',
416414
x: shape.x,
417415
y: 0,
418416
width: shape.width,
@@ -424,7 +422,7 @@ describe('EditRectangleTool', (): void => {
424422
{ x: shape.x + shape.width, y: shape.y },
425423
{ x: mockROI.width, y: -10 },
426424
{
427-
shapeType: ShapeType.Rect,
425+
shapeType: 'rect',
428426
x: shape.x,
429427
y: 0,
430428
width: mockROI.width - shape.x,
@@ -436,7 +434,7 @@ describe('EditRectangleTool', (): void => {
436434
{ x: shape.x + shape.width, y: shape.y + shape.height / 2 },
437435
{ x: mockROI.width, y: 10 },
438436
{
439-
shapeType: ShapeType.Rect,
437+
shapeType: 'rect',
440438
x: shape.x,
441439
y: shape.y,
442440
width: mockROI.width - shape.x,
@@ -448,7 +446,7 @@ describe('EditRectangleTool', (): void => {
448446
{ x: shape.x + shape.width, y: shape.y + shape.height },
449447
{ x: mockROI.width, y: mockROI.height },
450448
{
451-
shapeType: ShapeType.Rect,
449+
shapeType: 'rect',
452450
x: shape.x,
453451
y: shape.y,
454452
width: mockROI.width - shape.x,
@@ -460,7 +458,7 @@ describe('EditRectangleTool', (): void => {
460458
{ x: shape.x + shape.width / 2, y: shape.y + shape.height },
461459
{ x: 10, y: mockROI.height },
462460
{
463-
shapeType: ShapeType.Rect,
461+
shapeType: 'rect',
464462
x: shape.x,
465463
y: shape.y,
466464
width: shape.width,
@@ -472,7 +470,7 @@ describe('EditRectangleTool', (): void => {
472470
{ x: shape.x, y: shape.y + shape.height },
473471
{ x: -mockROI.width, y: mockROI.height },
474472
{
475-
shapeType: ShapeType.Rect,
473+
shapeType: 'rect',
476474
x: 0,
477475
y: shape.y,
478476
width: shape.width + shape.x,
@@ -484,7 +482,7 @@ describe('EditRectangleTool', (): void => {
484482
{ x: shape.x, y: shape.y + shape.height / 2 },
485483
{ x: -mockROI.width, y: mockROI.height },
486484
{
487-
shapeType: ShapeType.Rect,
485+
shapeType: 'rect',
488486
x: 0,
489487
y: shape.y,
490488
width: shape.width + shape.x,
@@ -527,7 +525,7 @@ describe('EditRectangleTool', (): void => {
527525
const gap = (2 * ANCHOR_SIZE) / zoom;
528526
const startPoint = { x: shape.x, y: shape.y };
529527
const expectedRect = {
530-
shapeType: ShapeType.Rect,
528+
shapeType: 'rect',
531529
x: shape.x + shape.width - gap,
532530
y: shape.y + shape.height - gap,
533531
width: gap,

web_ui/src/pages/annotator/tools/edit-tool/edit-circle/edit-circle.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useEffect, useState } from 'react';
66
import { ANCHOR_SIZE, ResizeAnchor } from '@geti/smart-tools';
77
import { Vec2 } from '@geti/smart-tools/utils';
88

9+
import { TranslateShape } from '../../../../../../packages/smart-tools/src/edit-bounding-box/translate-shape.component';
910
import { Annotation, RegionOfInterest } from '../../../../../core/annotations/annotation.interface';
1011
import { Point } from '../../../../../core/annotations/shapes.interface';
1112
import { ShapeType } from '../../../../../core/annotations/shapetype.enum';
@@ -16,7 +17,6 @@ import { useZoom } from '../../../zoom/zoom-provider.component';
1617
import { getMaxCircleRadius, MIN_RADIUS } from '../../circle-tool/utils';
1718
import { isShapeWithinRoi } from '../../utils';
1819
import { ResizeAnchorType } from '../resize-anchor.enum';
19-
import { TranslateShape } from '../translate-shape.component';
2020

2121
import classes from './../../../annotator-canvas.module.scss';
2222

web_ui/src/pages/annotator/tools/edit-tool/edit-keypoint/edit-keypoint-tool.component.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
import { useEffect, useRef, useState } from 'react';
55

66
import { ANCHOR_SIZE, ResizeAnchor } from '@geti/smart-tools';
7-
import { getBoundingBox } from '@geti/smart-tools/utils';
7+
import {
8+
getBoundingBox,
9+
getBoundingBoxInRoi,
10+
getBoundingBoxResizePoints,
11+
getClampedBoundingBox,
12+
} from '@geti/smart-tools/utils';
813

14+
import { TranslateShape } from '../../../../../../packages/smart-tools/src/edit-bounding-box/translate-shape.component';
915
import { KeypointAnnotation } from '../../../../../core/annotations/annotation.interface';
1016
import { Point } from '../../../../../core/annotations/shapes.interface';
1117
import { useSelected } from '../../../../../providers/selected-provider/selected-provider.component';
@@ -21,8 +27,6 @@ import {
2127
MIN_BOUNDING_BOX_SIZE,
2228
rotatePointsAroundPivot,
2329
} from '../../keypoint-tool/utils';
24-
import { TranslateShape } from '../translate-shape.component';
25-
import { getBoundingBoxInRoi, getBoundingBoxResizePoints, getClampedBoundingBox } from '../utils';
2630
import { ClosestKeypoint } from './closest-keypoint.component';
2731
import { EditPosePoint } from './edit-pose-point.component';
2832
import { RotationAnchor } from './rotation-anchor.component';

0 commit comments

Comments
 (0)