Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { ImageView, LabelStudio } from "@humansignal/frontend-test/helpers/LSF";
import { rect3Config, simpleImageData } from "../../../data/image_segmentation/tools/rect3point";
import { FF_DEV_3793 } from "../../../../../src/utils/feature-flags";
 
describe("Rect3Point tool", () => {
  beforeEach(() => {
    LabelStudio.addFeatureFlagsOnPageLoad({
      [FF_DEV_3793]: true,
    });
  });
  it("Should be able to draw region with rotation 0", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.selectRect3PointToolByHotkey();
 
    ImageView.clickAtRelative(0.1, 0.1);
    ImageView.clickAtRelative(0.2, 0.1);
    ImageView.clickAtRelative(0.2, 0.2);
 
    LabelStudio.serialize().then(([result]) => {
      expect(result.value.x).to.be.closeTo(10, 0.1);
      expect(result.value.y).to.be.closeTo(10, 0.1);
      expect(result.value.height).to.be.closeTo(10, 0.1);
      expect(result.value.width).to.be.closeTo(10, 0.1);
      expect(result.value.rotation).to.be.eq(0);
    });
  });
  it("Should be able to draw region with rotation 90", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.selectRect3PointToolByHotkey();
 
    ImageView.clickAtRelative(0.8, 0.2);
    ImageView.clickAtRelative(0.8, 0.8);
    ImageView.clickAtRelative(0.2, 0.8);
 
    LabelStudio.serialize().then(([result]) => {
      expect(result.value.x).to.be.closeTo(80, 0.2);
      expect(result.value.y).to.be.closeTo(20, 0.2);
      expect(result.value.rotation).to.be.eq(90);
    });
  });
  it("Should be able to draw region with rotation 180", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.selectRect3PointToolByHotkey();
 
    ImageView.clickAtRelative(0.6, 0.6);
    ImageView.clickAtRelative(0.4, 0.6);
    ImageView.clickAtRelative(0.4, 0.4);
 
    LabelStudio.serialize().then(([result]) => {
      expect(result.value.x).to.be.closeTo(60, 0.1);
      expect(result.value.y).to.be.closeTo(60, 0.1);
      expect(result.value.height).to.be.closeTo(20, 0.1);
      expect(result.value.width).to.be.closeTo(20, 0.1);
      expect(result.value.rotation).to.be.eq(180);
    });
  });
  it("Should be able to draw region with rotation 270", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.selectRect3PointToolByHotkey();
 
    ImageView.clickAtRelative(0.1, 0.2);
    ImageView.clickAtRelative(0.1, 0.1);
    ImageView.clickAtRelative(0.2, 0.1);
 
    LabelStudio.serialize().then(([result]) => {
      expect(result.value.x).to.be.closeTo(10, 0.2);
      expect(result.value.y).to.be.closeTo(20, 0.2);
      expect(result.value.rotation).to.be.eq(270);
    });
  });
  it("Should be able to draw region with rotation 45+90*k deg", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.selectRect3PointToolByHotkey();
    //45deg
    ImageView.clickAt(100, 50);
    ImageView.clickAt(150, 100);
    ImageView.clickAt(100, 150);
    //135deg
    ImageView.clickAt(350, 100);
    ImageView.clickAt(300, 150);
    ImageView.clickAt(250, 100);
    //225deg
    ImageView.clickAt(100, 350);
    ImageView.clickAt(50, 300);
    ImageView.clickAt(100, 250);
    //315deg
    ImageView.clickAt(250, 300);
    ImageView.clickAt(300, 250);
    ImageView.clickAt(350, 300);
 
    LabelStudio.serialize().then((result) => {
      expect(result[0].value.rotation).to.be.eq(45);
      expect(result[1].value.rotation).to.be.eq(135);
      expect(result[2].value.rotation).to.be.eq(225);
      expect(result[3].value.rotation).to.be.eq(315);
    });
  });
  it("Should display line of zero height (2 points)", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.capture("canvas");
 
    ImageView.selectRect3PointToolByHotkey();
    ImageView.clickAtRelative(0.1, 0.5);
    ImageView.clickAtRelative(0.8, 0.5);
 
    ImageView.canvasShouldChange("canvas", 0);
  });
  it("Should draw by dblclick at the target point", () => {
    LabelStudio.params().config(rect3Config).data(simpleImageData).withResult([]).init();
 
    ImageView.waitForImage();
 
    ImageView.clickAtRelative(0.5, 0.5);
    ImageView.clickAtRelative(0.5, 0.5);
 
    LabelStudio.serialize().then(([result]) => {
      expect(result.value.x).to.be.closeTo(50, 0.2);
      expect(result.value.y).to.be.closeTo(50, 0.2);
      expect(result.value.rotation).to.be.eq(0);
    });
  });
});