@inweb/markup 26.4.1 → 26.5.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.
@@ -52,7 +52,22 @@ export interface IMarkupEllipseParams {
52
52
  y: number;
53
53
  };
54
54
  /**
55
- * Screen radius of the ellipse along the X and Y axes.
55
+ * Screen coordinates of the center point (position) of the ellipse.
56
+ */
57
+ position2?: {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ /**
62
+ * Screen coordinates of the center point (position) of the ellipse.
63
+ */
64
+ position3?: {
65
+ x: number;
66
+ y: number;
67
+ };
68
+ /**
69
+ * Screen radius of the ellipse along the X and Y axes. Ignored if {@link position2} and
70
+ * {@link position3} is defined.
56
71
  *
57
72
  * @default 25
58
73
  */
@@ -56,21 +56,29 @@ export interface IMarkupImageParams {
56
56
  x: number;
57
57
  y: number;
58
58
  };
59
+ /**
60
+ * Screen coordinates of the bottom-right point (position) of the image. Specify 0 to set widt and
61
+ * height of the source image.
62
+ */
63
+ position2?: {
64
+ x: number;
65
+ y: number;
66
+ };
59
67
  /**
60
68
  * Image source as a base64-encoded
61
69
  * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}.
62
70
  */
63
71
  src?: string;
64
72
  /**
65
- * Width of the image. The original image is scaled to this width. Specify 0 to set width of the source
66
- * image.
73
+ * Deprecated. Width of the image. The original image is scaled to this width. Specify 0 to set width
74
+ * of the source image. Ignored if {@link position2} is defined.
67
75
  *
68
76
  * @default 0
69
77
  */
70
78
  width?: number;
71
79
  /**
72
- * Height of the image. The original image is scaled to this height. Specify 0 to set height of the
73
- * source image.
80
+ * Deprecated. Height of the image. The original image is scaled to this height. Specify 0 to set
81
+ * height of the source image. Ignored if {@link position2} is defined.
74
82
  *
75
83
  * @default 0
76
84
  */
@@ -59,13 +59,13 @@ export interface IMarkupRectangleParams {
59
59
  y: number;
60
60
  };
61
61
  /**
62
- * Width of the rectangle.
62
+ * Width of the rectangle. Ignored if {@link position2} is defined.
63
63
  *
64
64
  * @default 200
65
65
  */
66
66
  width?: number;
67
67
  /**
68
- * Height of the rectangle.
68
+ * Height of the rectangle. Ignored if {@link position2} is defined.
69
69
  *
70
70
  * @default 200
71
71
  */
@@ -0,0 +1,7 @@
1
+ export declare function getDistanceIn2D(p1: {
2
+ x: number;
3
+ y: number;
4
+ }, p2: {
5
+ x: number;
6
+ y: number;
7
+ }): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "26.4.1",
3
+ "version": "26.5.0",
4
4
  "description": "JavaScript 2D markups",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,8 +26,8 @@
26
26
  "docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~26.4.1",
30
- "@inweb/viewer-core": "~26.4.1"
29
+ "@inweb/eventemitter2": "~26.5.0",
30
+ "@inweb/viewer-core": "~26.5.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "konva": "^9.3.18"
@@ -79,7 +79,18 @@ export interface IMarkupEllipseParams {
79
79
  position?: { x: number; y: number };
80
80
 
81
81
  /**
82
- * Screen radius of the ellipse along the X and Y axes.
82
+ * Screen coordinates of the center point (position) of the ellipse.
83
+ */
84
+ position2?: { x: number; y: number };
85
+
86
+ /**
87
+ * Screen coordinates of the center point (position) of the ellipse.
88
+ */
89
+ position3?: { x: number; y: number };
90
+
91
+ /**
92
+ * Screen radius of the ellipse along the X and Y axes. Ignored if {@link position2} and
93
+ * {@link position3} is defined.
83
94
  *
84
95
  * @default 25
85
96
  */
@@ -83,6 +83,12 @@ export interface IMarkupImageParams {
83
83
  */
84
84
  position?: { x: number; y: number };
85
85
 
86
+ /**
87
+ * Screen coordinates of the bottom-right point (position) of the image. Specify 0 to set widt and
88
+ * height of the source image.
89
+ */
90
+ position2?: { x: number; y: number };
91
+
86
92
  /**
87
93
  * Image source as a base64-encoded
88
94
  * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}.
@@ -90,16 +96,16 @@ export interface IMarkupImageParams {
90
96
  src?: string;
91
97
 
92
98
  /**
93
- * Width of the image. The original image is scaled to this width. Specify 0 to set width of the source
94
- * image.
99
+ * Deprecated. Width of the image. The original image is scaled to this width. Specify 0 to set width
100
+ * of the source image. Ignored if {@link position2} is defined.
95
101
  *
96
102
  * @default 0
97
103
  */
98
104
  width?: number;
99
105
 
100
106
  /**
101
- * Height of the image. The original image is scaled to this height. Specify 0 to set height of the
102
- * source image.
107
+ * Deprecated. Height of the image. The original image is scaled to this height. Specify 0 to set
108
+ * height of the source image. Ignored if {@link position2} is defined.
103
109
  *
104
110
  * @default 0
105
111
  */
@@ -84,14 +84,14 @@ export interface IMarkupRectangleParams {
84
84
  position2?: { x: number; y: number };
85
85
 
86
86
  /**
87
- * Width of the rectangle.
87
+ * Width of the rectangle. Ignored if {@link position2} is defined.
88
88
  *
89
89
  * @default 200
90
90
  */
91
91
  width?: number;
92
92
 
93
93
  /**
94
- * Height of the rectangle.
94
+ * Height of the rectangle. Ignored if {@link position2} is defined.
95
95
  *
96
96
  * @default 200
97
97
  */
@@ -53,8 +53,8 @@ export class KonvaCloud implements IMarkupCloud {
53
53
  if (!params) params = {};
54
54
  if (!params.position) params.position = { x: 0, y: 0 };
55
55
  if (params.position2) {
56
- params.width = params.position.x - params.position2.x;
57
- params.height = params.position.y - params.position2.y;
56
+ params.width = params.position2.x - params.position.x;
57
+ params.height = params.position2.y - params.position.y;
58
58
  } else {
59
59
  if (!params.width || !params.height) {
60
60
  params.position2 = { x: 200, y: 200 };
@@ -252,6 +252,9 @@ export class KonvaCloud implements IMarkupCloud {
252
252
  setPosition(x: number, y: number): void {
253
253
  this._ref.position({ x, y });
254
254
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
255
+ const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
256
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
257
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
255
258
  }
256
259
 
257
260
  getWidth(): number {
@@ -25,6 +25,7 @@ import Konva from "konva";
25
25
  import { IMarkupEllipse, IMarkupEllipseParams } from "../IMarkupEllipse";
26
26
  import { IWorldTransform } from "../IWorldTransform";
27
27
  import { WorldTransform } from "../WorldTransform";
28
+ import * as utils from "../Utils";
28
29
 
29
30
  export class KonvaEllipse implements IMarkupEllipse {
30
31
  private _ref: Konva.Ellipse;
@@ -60,7 +61,13 @@ export class KonvaEllipse implements IMarkupEllipse {
60
61
 
61
62
  if (!params) params = {};
62
63
  if (!params.position) params.position = { x: 0, y: 0 };
63
- if (!params.radius) params.radius = { x: 25, y: 25 };
64
+ if (params.position2) {
65
+ params.radius.x = utils.getDistanceIn2D(params.position, params.position2);
66
+ if (params.position3) params.radius.y = utils.getDistanceIn2D(params.position, params.position3);
67
+ else params.radius.x = params.radius.y;
68
+ } else {
69
+ if (!params.radius) params.radius = { x: 25, y: 25 };
70
+ }
64
71
 
65
72
  this._ref = new Konva.Ellipse({
66
73
  stroke: params.color ?? "#ff0000",
@@ -52,9 +52,17 @@ export class KonvaImage implements IMarkupImage {
52
52
  : this._ref.height() / this._ref.width();
53
53
 
54
54
  const wcsStart = this._ref.getAttr("wcsStart");
55
+ const wcsEnd = this._ref.getAttr("wcsEnd");
55
56
  if (!wcsStart) {
56
57
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: ref.x(), y: ref.y() }));
57
58
  }
59
+ if (!wcsEnd) {
60
+ const rightBottomPoint = { x: ref.x() + ref.width(), y: ref.y() + ref.height() };
61
+ this._ref.setAttr(
62
+ "wcsEnd",
63
+ this._worldTransformer.screenToWorld({ x: rightBottomPoint.x, y: rightBottomPoint.y })
64
+ );
65
+ }
58
66
 
59
67
  return;
60
68
  }
@@ -62,6 +70,10 @@ export class KonvaImage implements IMarkupImage {
62
70
  if (!params) params = {};
63
71
  if (!params.position) params.position = { x: 0, y: 0 };
64
72
  if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
73
+ if (params.position2) {
74
+ params.width = params.position2.x - params.position.x;
75
+ params.height = params.position2.y - params.position.y;
76
+ }
65
77
 
66
78
  this._canvasImage = new Image();
67
79
 
@@ -91,6 +103,12 @@ export class KonvaImage implements IMarkupImage {
91
103
  this._ref.width(params.maxHeight / this._ratio);
92
104
  this._ref.height(params.maxHeight);
93
105
  }
106
+
107
+ const wcsEnd = this._worldTransformer.screenToWorld({
108
+ x: params.position.x + this._ref.width(),
109
+ y: params.position.y + this._ref.height(),
110
+ });
111
+ this._ref.setAttr("wcsEnd", wcsEnd);
94
112
  }
95
113
  }
96
114
  };
@@ -150,12 +168,20 @@ export class KonvaImage implements IMarkupImage {
150
168
  const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
151
169
  const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
152
170
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
171
+ this._ref.setAttr(
172
+ "wcsEnd",
173
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
174
+ );
153
175
  });
154
176
 
155
177
  this._ref.on("dragend", (e) => {
156
178
  const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
157
179
  const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
158
180
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
181
+ this._ref.setAttr(
182
+ "wcsEnd",
183
+ this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() })
184
+ );
159
185
  });
160
186
 
161
187
  this._ref.id(this._ref._id.toString());
@@ -176,6 +202,10 @@ export class KonvaImage implements IMarkupImage {
176
202
  setWidth(w: number): void {
177
203
  this._ref.width(w);
178
204
  this._ref.height(w * this._ratio);
205
+
206
+ const rightLowerPoint = { x: this._ref.x() + w, y: this._ref.y() + this._ref.height() };
207
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
208
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
179
209
  }
180
210
 
181
211
  getHeight(): number {
@@ -185,6 +215,10 @@ export class KonvaImage implements IMarkupImage {
185
215
  setHeight(h: number): void {
186
216
  this._ref.height(h);
187
217
  this._ref.width(h / this._ratio);
218
+
219
+ const rightLowerPoint = { x: this._ref.x() + this._ref.width(), y: this._ref.y() + h };
220
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
221
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
188
222
  }
189
223
 
190
224
  ref() {
@@ -231,15 +265,22 @@ export class KonvaImage implements IMarkupImage {
231
265
  setPosition(x: number, y: number): void {
232
266
  this._ref.setPosition({ x, y });
233
267
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
268
+ const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
269
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
270
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
234
271
  }
235
272
 
236
273
  updateScreenCoordinates(): void {
237
274
  let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
275
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
238
276
 
239
277
  let invert = this._ref.getStage().getAbsoluteTransform().copy();
240
278
  invert = invert.invert();
241
279
  const positionStart = invert.point(screenPositionStart);
280
+ const positionEnd = invert.point(screenPositionEnd);
242
281
 
243
282
  this._ref.position({ x: positionStart.x, y: positionStart.y });
283
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
284
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
244
285
  }
245
286
  }
@@ -306,12 +306,23 @@ export class KonvaMarkup implements IMarkup {
306
306
 
307
307
  viewpoint.rectangles?.forEach((rect: IRectangle) => {
308
308
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
309
- this.addRectangle(screenPoint, null, rect.width, rect.height, rect.line_width, rect.color, rect.id);
309
+ const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
310
+ this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
310
311
  });
311
312
 
312
313
  viewpoint.ellipses?.forEach((ellipse: IEllipse) => {
313
314
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
314
- this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
315
+ const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
316
+ const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
317
+ this.addEllipse(
318
+ screenPoint,
319
+ screenPoint2,
320
+ screenPoint3,
321
+ ellipse.radius,
322
+ ellipse.line_width,
323
+ ellipse.color,
324
+ ellipse.id
325
+ );
315
326
  });
316
327
 
317
328
  viewpoint.arrows?.forEach((arrow: IArrow) => {
@@ -322,12 +333,14 @@ export class KonvaMarkup implements IMarkup {
322
333
 
323
334
  viewpoint.clouds?.forEach((cloud: ICloud) => {
324
335
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
325
- this.addCloud(screenPoint, null, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
336
+ const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
337
+ this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
326
338
  });
327
339
 
328
340
  viewpoint.images?.forEach((image: IImage) => {
329
341
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
330
- this.addImage(screenPoint, image.src, image.width, image.height, image.id);
342
+ const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
343
+ this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
331
344
  });
332
345
  }
333
346
 
@@ -515,7 +528,7 @@ export class KonvaMarkup implements IMarkup {
515
528
  if (this._markupMode === "Rectangle") {
516
529
  this.addRectangle({ x: startX, y: startY }, null, dX, dY);
517
530
  } else if (this._markupMode === "Ellipse") {
518
- this.addEllipse({ x: startX, y: startY }, { x: dX / 2, y: dY / 2 });
531
+ this.addEllipse({ x: startX, y: startY }, null, null, { x: dX / 2, y: dY / 2 });
519
532
  } else if (this._markupMode === "Arrow") {
520
533
  this.addArrow(
521
534
  { x: mouseDownPos.x, y: mouseDownPos.y },
@@ -563,7 +576,7 @@ export class KonvaMarkup implements IMarkup {
563
576
  lastObj.setPosition(startX, startY);
564
577
  lastObj.setRadiusX(dX);
565
578
  lastObj.setRadiusY(dY);
566
- } else lastObj = this.addEllipse({ x: startX, y: startY }, { x: dX, y: dY });
579
+ } else lastObj = this.addEllipse({ x: startX, y: startY }, null, null, { x: dX, y: dY });
567
580
  } else if (this._markupMode === "Cloud") {
568
581
  if (lastObj) {
569
582
  lastObj.setPosition(startX, startY);
@@ -590,6 +603,7 @@ export class KonvaMarkup implements IMarkup {
590
603
  if (this._imageInputRef && this._imageInputRef.value)
591
604
  this.addImage(
592
605
  { x: this._imageInputPos.x, y: this._imageInputPos.y },
606
+ null,
593
607
  this._imageInputRef.value,
594
608
  0,
595
609
  0,
@@ -625,7 +639,7 @@ export class KonvaMarkup implements IMarkup {
625
639
  if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
626
640
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
627
641
  if (this._imageInputRef && this._imageInputRef.value)
628
- this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0);
642
+ this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0);
629
643
  else this.createImageInput({ x: e.target.attrs.x, y: e.target.attrs.y });
630
644
  return;
631
645
  } else {
@@ -759,6 +773,7 @@ export class KonvaMarkup implements IMarkup {
759
773
  const rectangle: IRectangle = {
760
774
  id: shape.id(),
761
775
  position: wcsStart,
776
+ position2: wcsEnd,
762
777
  width: Math.abs(screenStart.x - screenEnd.x),
763
778
  height: Math.abs(screenStart.y - screenEnd.y),
764
779
  line_width: shape.getLineWidth(),
@@ -776,6 +791,8 @@ export class KonvaMarkup implements IMarkup {
776
791
 
777
792
  this.konvaLayerFind("Ellipse").forEach((ref) => {
778
793
  const wcsPosition = ref.getAttr("wcsPosition");
794
+ const wcsPosition2 = ref.getAttr("wcsRadiusX");
795
+ const wcsPosition3 = ref.getAttr("wcsRadiusY");
779
796
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
780
797
  const scale = stageAbsoluteTransform.getMatrix()[0];
781
798
 
@@ -783,6 +800,8 @@ export class KonvaMarkup implements IMarkup {
783
800
  const ellipse: IEllipse = {
784
801
  id: shape.id(),
785
802
  position: wcsPosition,
803
+ position2: wcsPosition2,
804
+ position3: wcsPosition3,
786
805
  radius: {
787
806
  x: ref.getRadiusX() * scale,
788
807
  y: ref.getRadiusY() * scale,
@@ -824,6 +843,7 @@ export class KonvaMarkup implements IMarkup {
824
843
 
825
844
  this.konvaLayerFind("Image").forEach((ref) => {
826
845
  const wcsStart = ref.getAttr("wcsStart");
846
+ const wcsEnd = ref.getAttr("wcsEnd");
827
847
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
828
848
  const scale = stageAbsoluteTransform.getMatrix()[0];
829
849
 
@@ -831,6 +851,7 @@ export class KonvaMarkup implements IMarkup {
831
851
  const image: IImage = {
832
852
  id: shape.id(),
833
853
  position: wcsStart,
854
+ position2: wcsEnd,
834
855
  src: shape.getSrc(),
835
856
  width: shape.getWidth() * scale,
836
857
  height: shape.getHeight() * scale,
@@ -855,6 +876,7 @@ export class KonvaMarkup implements IMarkup {
855
876
  const cloud: ICloud = {
856
877
  id: shape.id(),
857
878
  position: wcsStart,
879
+ position2: wcsEnd,
858
880
  width: Math.abs(screenStart.x - screenEnd.x),
859
881
  height: Math.abs(screenStart.y - screenEnd.y),
860
882
  line_width: shape.getLineWidth(),
@@ -980,7 +1002,7 @@ export class KonvaMarkup implements IMarkup {
980
1002
  this._imageInputRef.onchange = async (event) => {
981
1003
  const file = (event.target as HTMLInputElement).files[0];
982
1004
  const base64 = await convertBase64(file);
983
- this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, base64.toString(), 0, 0);
1005
+ this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, null, base64.toString(), 0, 0);
984
1006
  };
985
1007
  this._imageInputRef.oncancel = (event) => {
986
1008
  this.removeImageInput();
@@ -1074,6 +1096,8 @@ export class KonvaMarkup implements IMarkup {
1074
1096
 
1075
1097
  private addEllipse(
1076
1098
  position: Konva.Vector2d,
1099
+ position2: Konva.Vector2d,
1100
+ position3: Konva.Vector2d,
1077
1101
  radius: Konva.Vector2d,
1078
1102
  lineWidth?: number,
1079
1103
  color?: string,
@@ -1084,6 +1108,8 @@ export class KonvaMarkup implements IMarkup {
1084
1108
  const konvaEllipse = new KonvaEllipse(
1085
1109
  {
1086
1110
  position,
1111
+ position2,
1112
+ position3,
1087
1113
  radius,
1088
1114
  lineWidth,
1089
1115
  color: color || this._markupColor.asHex(),
@@ -1146,6 +1172,7 @@ export class KonvaMarkup implements IMarkup {
1146
1172
 
1147
1173
  private addImage(
1148
1174
  position: Konva.Vector2d,
1175
+ position2: Konva.Vector2d,
1149
1176
  src: string,
1150
1177
  width?: number,
1151
1178
  height?: number,
@@ -1162,6 +1189,7 @@ export class KonvaMarkup implements IMarkup {
1162
1189
  const konvaImage = new KonvaImage(
1163
1190
  {
1164
1191
  position,
1192
+ position2,
1165
1193
  src,
1166
1194
  width,
1167
1195
  height,
@@ -54,8 +54,8 @@ export class KonvaRectangle implements IMarkupRectangle {
54
54
  if (!params) params = {};
55
55
  if (!params.position) params.position = { x: 0, y: 0 };
56
56
  if (params.position2) {
57
- params.width = params.position.x - params.position2.x;
58
- params.height = params.position.y - params.position2.y;
57
+ params.width = params.position2.x - params.position.x;
58
+ params.height = params.position2.y - params.position.y;
59
59
  } else {
60
60
  if (!params.width || !params.height) {
61
61
  params.position2 = { x: 200, y: 200 };
@@ -167,6 +167,9 @@ export class KonvaRectangle implements IMarkupRectangle {
167
167
  setPosition(x: number, y: number): void {
168
168
  this._ref.setPosition({ x, y });
169
169
  this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
170
+ const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
171
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
172
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
170
173
  }
171
174
 
172
175
  ref() {
@@ -0,0 +1,3 @@
1
+ export function getDistanceIn2D(p1: { x: number; y: number }, p2: { x: number; y: number }): number {
2
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
3
+ }