回答編集履歴

1

追記

2018/08/13 21:00

投稿

退会済みユーザー
test CHANGED
@@ -7,3 +7,55 @@
7
7
 
8
8
 
9
9
  ![](6cb5affcb9203d76a20dc1305b579cf3.png)
10
+
11
+
12
+
13
+ 大きな矩形の各頂点の座標を取得したいのであれば、以下のコードを参考してみてください。
14
+
15
+
16
+
17
+ ```js
18
+
19
+ const bbox = rect.getBBox()
20
+
21
+ const viewportElement = rect.viewportElement
22
+
23
+ const screenCTM1 = rect.getScreenCTM()
24
+
25
+ const screenCTM2 = viewportElement.getScreenCTM()
26
+
27
+ .inverse()
28
+
29
+ const svgPoint = viewportElement.createSVGPoint()
30
+
31
+ svgPoint.x = bbox.x
32
+
33
+ svgPoint.y = bbox.y
34
+
35
+ const topLeft = svgPoint.matrixTransform(screenCTM1)
36
+
37
+ .matrixTransform(screenCTM2)
38
+
39
+ svgPoint.x += bbox.width
40
+
41
+ const topRight = svgPoint.matrixTransform(screenCTM1)
42
+
43
+ .matrixTransform(screenCTM2)
44
+
45
+ svgPoint.y += bbox.height
46
+
47
+ const bottomRight = svgPoint.matrixTransform(screenCTM1)
48
+
49
+ .matrixTransform(screenCTM2)
50
+
51
+ svgPoint.x = bbox.x
52
+
53
+ const bottomLeft = svgPoint.matrixTransform(screenCTM1)
54
+
55
+ .matrixTransform(screenCTM2)
56
+
57
+ ```
58
+
59
+
60
+
61
+ [https://codepen.io/anon/pen/jpJJzm](https://codepen.io/anon/pen/jpJJzm)