@antv/g6 5.0.0-beta.31 → 5.0.0-beta.33

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.
Files changed (738) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/brush-select.d.ts +104 -0
  3. package/dist/lib/behaviors/click-element.d.ts +77 -0
  4. package/dist/lib/behaviors/collapse-expand.d.ts +4 -5
  5. package/dist/lib/behaviors/create-edge.d.ts +55 -0
  6. package/dist/lib/behaviors/drag-canvas.d.ts +6 -6
  7. package/dist/lib/behaviors/drag-element-force.d.ts +14 -0
  8. package/dist/lib/behaviors/drag-element.d.ts +17 -14
  9. package/dist/lib/behaviors/focus-element.d.ts +4 -3
  10. package/dist/lib/behaviors/hover-element.d.ts +4 -5
  11. package/dist/lib/behaviors/index.d.ts +10 -0
  12. package/dist/lib/behaviors/lasso-select.d.ts +20 -0
  13. package/dist/lib/behaviors/types.d.ts +1 -0
  14. package/dist/lib/behaviors/zoom-canvas.d.ts +7 -6
  15. package/dist/lib/constants/change.d.ts +1 -1
  16. package/dist/lib/constants/events/graph.d.ts +9 -15
  17. package/dist/lib/constants/index.d.ts +1 -0
  18. package/dist/lib/constants/registry.d.ts +22 -0
  19. package/dist/lib/elements/combos/base-combo.d.ts +64 -6
  20. package/dist/lib/elements/combos/circle.d.ts +8 -12
  21. package/dist/lib/elements/combos/rect.d.ts +5 -9
  22. package/dist/lib/elements/edges/base-edge.d.ts +85 -10
  23. package/dist/lib/elements/edges/cubic-horizontal.d.ts +2 -2
  24. package/dist/lib/elements/edges/cubic-vertical.d.ts +2 -2
  25. package/dist/lib/elements/edges/cubic.d.ts +2 -2
  26. package/dist/lib/elements/edges/polyline.d.ts +2 -2
  27. package/dist/lib/elements/edges/quadratic.d.ts +2 -2
  28. package/dist/lib/elements/nodes/base-node.d.ts +125 -13
  29. package/dist/lib/elements/nodes/circle.d.ts +5 -8
  30. package/dist/lib/elements/nodes/diamond.d.ts +2 -4
  31. package/dist/lib/elements/nodes/ellipse.d.ts +5 -8
  32. package/dist/lib/elements/nodes/hexagon.d.ts +6 -9
  33. package/dist/lib/elements/nodes/image.d.ts +9 -11
  34. package/dist/lib/elements/nodes/polygon.d.ts +9 -8
  35. package/dist/lib/elements/nodes/rect.d.ts +2 -3
  36. package/dist/lib/elements/nodes/star.d.ts +7 -10
  37. package/dist/lib/elements/nodes/triangle.d.ts +7 -10
  38. package/dist/lib/exports.d.ts +18 -14
  39. package/dist/lib/layouts/index.d.ts +1 -1
  40. package/dist/lib/layouts/types.d.ts +6 -6
  41. package/dist/lib/palettes/index.d.ts +1 -0
  42. package/dist/lib/plugins/camera-setting.d.ts +95 -0
  43. package/dist/lib/plugins/contextmenu.d.ts +8 -5
  44. package/dist/lib/plugins/history/events.d.ts +21 -0
  45. package/dist/lib/plugins/history/index.d.ts +82 -0
  46. package/dist/lib/plugins/history/utils.d.ts +31 -0
  47. package/dist/lib/plugins/hull/index.d.ts +59 -0
  48. package/dist/lib/plugins/hull/shape.d.ts +49 -0
  49. package/dist/lib/plugins/hull/util.d.ts +12 -0
  50. package/dist/lib/plugins/index.d.ts +8 -0
  51. package/dist/lib/plugins/legend.d.ts +49 -0
  52. package/dist/lib/plugins/tooltip.d.ts +12 -10
  53. package/dist/lib/registry/extension/index.d.ts +3 -3
  54. package/dist/lib/registry/index.d.ts +6 -4
  55. package/dist/lib/registry/types.d.ts +4 -6
  56. package/dist/lib/runtime/batch.d.ts +11 -0
  57. package/dist/lib/runtime/behavior.d.ts +1 -1
  58. package/dist/lib/runtime/canvas.d.ts +15 -4
  59. package/dist/lib/runtime/data.d.ts +4 -4
  60. package/dist/lib/runtime/element.d.ts +6 -23
  61. package/dist/lib/runtime/graph.d.ts +71 -6
  62. package/dist/lib/runtime/layout.d.ts +5 -11
  63. package/dist/lib/runtime/plugin.d.ts +2 -1
  64. package/dist/lib/runtime/transform.d.ts +11 -0
  65. package/dist/lib/runtime/types.d.ts +14 -0
  66. package/dist/lib/spec/index.d.ts +1 -0
  67. package/dist/lib/spec/spec.d.ts +7 -0
  68. package/dist/lib/spec/transform.d.ts +12 -0
  69. package/dist/lib/transforms/arrange-draw-order.d.ts +10 -0
  70. package/dist/lib/transforms/base-transform.d.ts +7 -0
  71. package/dist/lib/transforms/collapse-expand-combo.d.ts +10 -0
  72. package/dist/lib/transforms/index.d.ts +6 -0
  73. package/dist/lib/transforms/process-parallel-edges.d.ts +84 -0
  74. package/dist/lib/transforms/types.d.ts +20 -0
  75. package/dist/lib/transforms/update-related-edge.d.ts +9 -0
  76. package/dist/lib/types/canvas.d.ts +1 -1
  77. package/dist/lib/types/change.d.ts +27 -10
  78. package/dist/lib/types/element.d.ts +6 -140
  79. package/dist/lib/types/event.d.ts +42 -7
  80. package/dist/lib/types/index.d.ts +0 -1
  81. package/dist/lib/types/node.d.ts +3 -3
  82. package/dist/lib/types/point.d.ts +1 -0
  83. package/dist/lib/utils/animation.d.ts +1 -1
  84. package/dist/lib/utils/bbox.d.ts +1 -1
  85. package/dist/lib/utils/behaviors/brush.d.ts +19 -0
  86. package/dist/lib/utils/behaviors/lasso.d.ts +13 -0
  87. package/dist/lib/utils/behaviors/utils.d.ts +21 -0
  88. package/dist/lib/utils/change.d.ts +9 -1
  89. package/dist/lib/utils/combo.d.ts +5 -4
  90. package/dist/lib/utils/edge.d.ts +11 -0
  91. package/dist/lib/utils/element.d.ts +19 -11
  92. package/dist/lib/utils/event/events.d.ts +9 -14
  93. package/dist/lib/utils/extension.d.ts +1 -1
  94. package/dist/lib/utils/id.d.ts +3 -8
  95. package/dist/lib/utils/line.d.ts +21 -0
  96. package/dist/lib/utils/path.d.ts +35 -0
  97. package/dist/lib/utils/point.d.ts +74 -20
  98. package/dist/lib/utils/polygon.d.ts +17 -0
  99. package/dist/lib/utils/position.d.ts +14 -1
  100. package/dist/lib/utils/prefix.d.ts +1 -1
  101. package/dist/lib/utils/shortcut.d.ts +11 -0
  102. package/dist/lib/utils/vector.d.ts +3 -2
  103. package/esm/behaviors/brush-select.d.ts +104 -0
  104. package/esm/behaviors/brush-select.js +199 -0
  105. package/esm/behaviors/brush-select.js.map +1 -0
  106. package/esm/behaviors/click-element.d.ts +77 -0
  107. package/esm/behaviors/click-element.js +108 -0
  108. package/esm/behaviors/click-element.js.map +1 -0
  109. package/esm/behaviors/collapse-expand.d.ts +4 -5
  110. package/esm/behaviors/collapse-expand.js +8 -4
  111. package/esm/behaviors/collapse-expand.js.map +1 -1
  112. package/esm/behaviors/create-edge.d.ts +55 -0
  113. package/esm/behaviors/create-edge.js +141 -0
  114. package/esm/behaviors/create-edge.js.map +1 -0
  115. package/esm/behaviors/drag-canvas.d.ts +6 -6
  116. package/esm/behaviors/drag-canvas.js +15 -7
  117. package/esm/behaviors/drag-canvas.js.map +1 -1
  118. package/esm/behaviors/drag-element-force.d.ts +14 -0
  119. package/esm/behaviors/drag-element-force.js +55 -0
  120. package/esm/behaviors/drag-element-force.js.map +1 -0
  121. package/esm/behaviors/drag-element.d.ts +17 -14
  122. package/esm/behaviors/drag-element.js +17 -9
  123. package/esm/behaviors/drag-element.js.map +1 -1
  124. package/esm/behaviors/focus-element.d.ts +4 -3
  125. package/esm/behaviors/focus-element.js.map +1 -1
  126. package/esm/behaviors/hover-element.d.ts +4 -5
  127. package/esm/behaviors/hover-element.js +2 -2
  128. package/esm/behaviors/hover-element.js.map +1 -1
  129. package/esm/behaviors/index.d.ts +10 -0
  130. package/esm/behaviors/index.js +5 -0
  131. package/esm/behaviors/index.js.map +1 -1
  132. package/esm/behaviors/lasso-select.d.ts +20 -0
  133. package/esm/behaviors/lasso-select.js +79 -0
  134. package/esm/behaviors/lasso-select.js.map +1 -0
  135. package/esm/behaviors/types.d.ts +1 -0
  136. package/esm/behaviors/zoom-canvas.d.ts +7 -6
  137. package/esm/behaviors/zoom-canvas.js +6 -2
  138. package/esm/behaviors/zoom-canvas.js.map +1 -1
  139. package/esm/constants/change.d.ts +1 -1
  140. package/esm/constants/change.js +12 -12
  141. package/esm/constants/change.js.map +1 -1
  142. package/esm/constants/events/graph.d.ts +9 -15
  143. package/esm/constants/events/graph.js +8 -16
  144. package/esm/constants/events/graph.js.map +1 -1
  145. package/esm/constants/index.d.ts +1 -0
  146. package/esm/constants/index.js +1 -0
  147. package/esm/constants/index.js.map +1 -1
  148. package/esm/constants/registry.d.ts +22 -0
  149. package/esm/constants/registry.js +24 -0
  150. package/esm/constants/registry.js.map +1 -0
  151. package/esm/elements/combos/base-combo.d.ts +64 -6
  152. package/esm/elements/combos/base-combo.js +21 -0
  153. package/esm/elements/combos/base-combo.js.map +1 -1
  154. package/esm/elements/combos/circle.d.ts +8 -12
  155. package/esm/elements/combos/circle.js.map +1 -1
  156. package/esm/elements/combos/rect.d.ts +5 -9
  157. package/esm/elements/combos/rect.js.map +1 -1
  158. package/esm/elements/edges/base-edge.d.ts +85 -10
  159. package/esm/elements/edges/base-edge.js +21 -0
  160. package/esm/elements/edges/base-edge.js.map +1 -1
  161. package/esm/elements/edges/cubic-horizontal.d.ts +2 -2
  162. package/esm/elements/edges/cubic-vertical.d.ts +2 -2
  163. package/esm/elements/edges/cubic.d.ts +2 -2
  164. package/esm/elements/edges/polyline.d.ts +2 -2
  165. package/esm/elements/edges/quadratic.d.ts +2 -2
  166. package/esm/elements/nodes/base-node.d.ts +125 -13
  167. package/esm/elements/nodes/base-node.js +25 -1
  168. package/esm/elements/nodes/base-node.js.map +1 -1
  169. package/esm/elements/nodes/circle.d.ts +5 -8
  170. package/esm/elements/nodes/circle.js.map +1 -1
  171. package/esm/elements/nodes/diamond.d.ts +2 -4
  172. package/esm/elements/nodes/diamond.js +2 -2
  173. package/esm/elements/nodes/diamond.js.map +1 -1
  174. package/esm/elements/nodes/ellipse.d.ts +5 -8
  175. package/esm/elements/nodes/ellipse.js +1 -1
  176. package/esm/elements/nodes/ellipse.js.map +1 -1
  177. package/esm/elements/nodes/hexagon.d.ts +6 -9
  178. package/esm/elements/nodes/hexagon.js.map +1 -1
  179. package/esm/elements/nodes/image.d.ts +9 -11
  180. package/esm/elements/nodes/image.js.map +1 -1
  181. package/esm/elements/nodes/polygon.d.ts +9 -8
  182. package/esm/elements/nodes/polygon.js +4 -1
  183. package/esm/elements/nodes/polygon.js.map +1 -1
  184. package/esm/elements/nodes/rect.d.ts +2 -3
  185. package/esm/elements/nodes/rect.js.map +1 -1
  186. package/esm/elements/nodes/star.d.ts +7 -10
  187. package/esm/elements/nodes/star.js.map +1 -1
  188. package/esm/elements/nodes/triangle.d.ts +7 -10
  189. package/esm/elements/nodes/triangle.js.map +1 -1
  190. package/esm/exports.d.ts +18 -14
  191. package/esm/exports.js +8 -6
  192. package/esm/exports.js.map +1 -1
  193. package/esm/layouts/index.d.ts +1 -1
  194. package/esm/layouts/index.js +1 -1
  195. package/esm/layouts/index.js.map +1 -1
  196. package/esm/layouts/types.d.ts +6 -6
  197. package/esm/palettes/index.d.ts +1 -0
  198. package/esm/palettes/index.js +12 -0
  199. package/esm/palettes/index.js.map +1 -1
  200. package/esm/plugins/camera-setting.d.ts +95 -0
  201. package/esm/plugins/camera-setting.js +65 -0
  202. package/esm/plugins/camera-setting.js.map +1 -0
  203. package/esm/plugins/contextmenu.d.ts +8 -5
  204. package/esm/plugins/contextmenu.js.map +1 -1
  205. package/esm/plugins/history/events.d.ts +21 -0
  206. package/esm/plugins/history/events.js +16 -0
  207. package/esm/plugins/history/events.js.map +1 -0
  208. package/esm/plugins/history/index.d.ts +82 -0
  209. package/esm/plugins/history/index.js +168 -0
  210. package/esm/plugins/history/index.js.map +1 -0
  211. package/esm/plugins/history/utils.d.ts +31 -0
  212. package/esm/plugins/history/utils.js +79 -0
  213. package/esm/plugins/history/utils.js.map +1 -0
  214. package/esm/plugins/hull/index.d.ts +59 -0
  215. package/esm/plugins/hull/index.js +107 -0
  216. package/esm/plugins/hull/index.js.map +1 -0
  217. package/esm/plugins/hull/shape.d.ts +49 -0
  218. package/esm/plugins/hull/shape.js +35 -0
  219. package/esm/plugins/hull/shape.js.map +1 -0
  220. package/esm/plugins/hull/util.d.ts +12 -0
  221. package/esm/plugins/hull/util.js +203 -0
  222. package/esm/plugins/hull/util.js.map +1 -0
  223. package/esm/plugins/index.d.ts +8 -0
  224. package/esm/plugins/index.js +4 -0
  225. package/esm/plugins/index.js.map +1 -1
  226. package/esm/plugins/legend.d.ts +49 -0
  227. package/esm/plugins/legend.js +267 -0
  228. package/esm/plugins/legend.js.map +1 -0
  229. package/esm/plugins/tooltip.d.ts +12 -10
  230. package/esm/plugins/tooltip.js +0 -1
  231. package/esm/plugins/tooltip.js.map +1 -1
  232. package/esm/preset.js +2 -5
  233. package/esm/preset.js.map +1 -1
  234. package/esm/registry/build-in.js +21 -4
  235. package/esm/registry/build-in.js.map +1 -1
  236. package/esm/registry/extension/index.d.ts +3 -3
  237. package/esm/registry/extension/index.js.map +1 -1
  238. package/esm/registry/index.d.ts +6 -4
  239. package/esm/registry/index.js +1 -0
  240. package/esm/registry/index.js.map +1 -1
  241. package/esm/registry/types.d.ts +4 -6
  242. package/esm/runtime/batch.d.ts +11 -0
  243. package/esm/runtime/batch.js +31 -0
  244. package/esm/runtime/batch.js.map +1 -0
  245. package/esm/runtime/behavior.d.ts +1 -1
  246. package/esm/runtime/behavior.js +3 -2
  247. package/esm/runtime/behavior.js.map +1 -1
  248. package/esm/runtime/canvas.d.ts +15 -4
  249. package/esm/runtime/canvas.js +103 -41
  250. package/esm/runtime/canvas.js.map +1 -1
  251. package/esm/runtime/data.d.ts +4 -4
  252. package/esm/runtime/data.js +23 -25
  253. package/esm/runtime/data.js.map +1 -1
  254. package/esm/runtime/element.d.ts +6 -23
  255. package/esm/runtime/element.js +48 -150
  256. package/esm/runtime/element.js.map +1 -1
  257. package/esm/runtime/graph.d.ts +71 -6
  258. package/esm/runtime/graph.js +105 -10
  259. package/esm/runtime/graph.js.map +1 -1
  260. package/esm/runtime/layout.d.ts +5 -11
  261. package/esm/runtime/layout.js +29 -75
  262. package/esm/runtime/layout.js.map +1 -1
  263. package/esm/runtime/plugin.d.ts +2 -1
  264. package/esm/runtime/plugin.js +3 -0
  265. package/esm/runtime/plugin.js.map +1 -1
  266. package/esm/runtime/transform.d.ts +11 -0
  267. package/esm/runtime/transform.js +20 -0
  268. package/esm/runtime/transform.js.map +1 -0
  269. package/esm/runtime/types.d.ts +14 -0
  270. package/esm/spec/index.d.ts +1 -0
  271. package/esm/spec/spec.d.ts +7 -0
  272. package/esm/spec/transform.d.ts +12 -0
  273. package/esm/spec/transform.js +2 -0
  274. package/esm/spec/transform.js.map +1 -0
  275. package/esm/themes/base.js +9 -1
  276. package/esm/themes/base.js.map +1 -1
  277. package/esm/transforms/arrange-draw-order.d.ts +10 -0
  278. package/esm/transforms/arrange-draw-order.js +27 -0
  279. package/esm/transforms/arrange-draw-order.js.map +1 -0
  280. package/esm/transforms/base-transform.d.ts +7 -0
  281. package/esm/transforms/base-transform.js +7 -0
  282. package/esm/transforms/base-transform.js.map +1 -0
  283. package/esm/transforms/collapse-expand-combo.d.ts +10 -0
  284. package/esm/transforms/collapse-expand-combo.js +82 -0
  285. package/esm/transforms/collapse-expand-combo.js.map +1 -0
  286. package/esm/transforms/index.d.ts +6 -0
  287. package/esm/transforms/index.js +6 -0
  288. package/esm/transforms/index.js.map +1 -0
  289. package/esm/transforms/process-parallel-edges.d.ts +84 -0
  290. package/esm/transforms/process-parallel-edges.js +215 -0
  291. package/esm/transforms/process-parallel-edges.js.map +1 -0
  292. package/esm/transforms/types.d.ts +20 -0
  293. package/esm/transforms/types.js +11 -0
  294. package/esm/transforms/types.js.map +1 -0
  295. package/esm/transforms/update-related-edge.d.ts +9 -0
  296. package/esm/transforms/update-related-edge.js +20 -0
  297. package/esm/transforms/update-related-edge.js.map +1 -0
  298. package/esm/types/canvas.d.ts +1 -1
  299. package/esm/types/change.d.ts +27 -10
  300. package/esm/types/element.d.ts +6 -140
  301. package/esm/types/event.d.ts +42 -7
  302. package/esm/types/index.d.ts +0 -1
  303. package/esm/types/node.d.ts +3 -3
  304. package/esm/types/point.d.ts +1 -0
  305. package/esm/utils/animation.d.ts +1 -1
  306. package/esm/utils/animation.js +6 -0
  307. package/esm/utils/animation.js.map +1 -1
  308. package/esm/utils/bbox.d.ts +1 -1
  309. package/esm/utils/behaviors/brush.d.ts +19 -0
  310. package/esm/utils/behaviors/brush.js +25 -0
  311. package/esm/utils/behaviors/brush.js.map +1 -0
  312. package/esm/utils/behaviors/lasso.d.ts +13 -0
  313. package/esm/utils/behaviors/lasso.js +112 -0
  314. package/esm/utils/behaviors/lasso.js.map +1 -0
  315. package/esm/utils/behaviors/utils.d.ts +21 -0
  316. package/esm/utils/behaviors/utils.js +42 -0
  317. package/esm/utils/behaviors/utils.js.map +1 -0
  318. package/esm/utils/change.d.ts +9 -1
  319. package/esm/utils/change.js +28 -0
  320. package/esm/utils/change.js.map +1 -1
  321. package/esm/utils/combo.d.ts +5 -4
  322. package/esm/utils/combo.js.map +1 -1
  323. package/esm/utils/edge.d.ts +11 -0
  324. package/esm/utils/edge.js +1 -1
  325. package/esm/utils/edge.js.map +1 -1
  326. package/esm/utils/element.d.ts +19 -11
  327. package/esm/utils/element.js +19 -9
  328. package/esm/utils/element.js.map +1 -1
  329. package/esm/utils/event/events.d.ts +9 -14
  330. package/esm/utils/event/events.js +3 -8
  331. package/esm/utils/event/events.js.map +1 -1
  332. package/esm/utils/extension.d.ts +1 -1
  333. package/esm/utils/extension.js.map +1 -1
  334. package/esm/utils/id.d.ts +3 -8
  335. package/esm/utils/id.js +8 -2
  336. package/esm/utils/id.js.map +1 -1
  337. package/esm/utils/line.d.ts +21 -0
  338. package/esm/utils/line.js +41 -0
  339. package/esm/utils/line.js.map +1 -0
  340. package/esm/utils/path.d.ts +35 -0
  341. package/esm/utils/path.js +143 -0
  342. package/esm/utils/path.js.map +1 -0
  343. package/esm/utils/point.d.ts +74 -20
  344. package/esm/utils/point.js +168 -44
  345. package/esm/utils/point.js.map +1 -1
  346. package/esm/utils/polygon.d.ts +17 -0
  347. package/esm/utils/polygon.js +62 -0
  348. package/esm/utils/polygon.js.map +1 -0
  349. package/esm/utils/position.d.ts +14 -1
  350. package/esm/utils/position.js +16 -0
  351. package/esm/utils/position.js.map +1 -1
  352. package/esm/utils/prefix.d.ts +1 -1
  353. package/esm/utils/prefix.js.map +1 -1
  354. package/esm/utils/shortcut.d.ts +11 -0
  355. package/esm/utils/shortcut.js +37 -5
  356. package/esm/utils/shortcut.js.map +1 -1
  357. package/esm/utils/style.js.map +1 -1
  358. package/esm/utils/vector.d.ts +3 -2
  359. package/esm/utils/vector.js +10 -3
  360. package/esm/utils/vector.js.map +1 -1
  361. package/lib/behaviors/brush-select.d.ts +104 -0
  362. package/lib/behaviors/brush-select.js +203 -0
  363. package/lib/behaviors/brush-select.js.map +1 -0
  364. package/lib/behaviors/click-element.d.ts +77 -0
  365. package/lib/behaviors/click-element.js +112 -0
  366. package/lib/behaviors/click-element.js.map +1 -0
  367. package/lib/behaviors/collapse-expand.d.ts +4 -5
  368. package/lib/behaviors/collapse-expand.js +8 -4
  369. package/lib/behaviors/collapse-expand.js.map +1 -1
  370. package/lib/behaviors/create-edge.d.ts +55 -0
  371. package/lib/behaviors/create-edge.js +145 -0
  372. package/lib/behaviors/create-edge.js.map +1 -0
  373. package/lib/behaviors/drag-canvas.d.ts +6 -6
  374. package/lib/behaviors/drag-canvas.js +15 -7
  375. package/lib/behaviors/drag-canvas.js.map +1 -1
  376. package/lib/behaviors/drag-element-force.d.ts +14 -0
  377. package/lib/behaviors/drag-element-force.js +59 -0
  378. package/lib/behaviors/drag-element-force.js.map +1 -0
  379. package/lib/behaviors/drag-element.d.ts +17 -14
  380. package/lib/behaviors/drag-element.js +17 -9
  381. package/lib/behaviors/drag-element.js.map +1 -1
  382. package/lib/behaviors/focus-element.d.ts +4 -3
  383. package/lib/behaviors/focus-element.js.map +1 -1
  384. package/lib/behaviors/hover-element.d.ts +4 -5
  385. package/lib/behaviors/hover-element.js +1 -1
  386. package/lib/behaviors/hover-element.js.map +1 -1
  387. package/lib/behaviors/index.d.ts +10 -0
  388. package/lib/behaviors/index.js +11 -1
  389. package/lib/behaviors/index.js.map +1 -1
  390. package/lib/behaviors/lasso-select.d.ts +20 -0
  391. package/lib/behaviors/lasso-select.js +83 -0
  392. package/lib/behaviors/lasso-select.js.map +1 -0
  393. package/lib/behaviors/types.d.ts +1 -0
  394. package/lib/behaviors/zoom-canvas.d.ts +7 -6
  395. package/lib/behaviors/zoom-canvas.js +6 -2
  396. package/lib/behaviors/zoom-canvas.js.map +1 -1
  397. package/lib/constants/change.d.ts +1 -1
  398. package/lib/constants/change.js +13 -13
  399. package/lib/constants/change.js.map +1 -1
  400. package/lib/constants/events/graph.d.ts +9 -15
  401. package/lib/constants/events/graph.js +9 -17
  402. package/lib/constants/events/graph.js.map +1 -1
  403. package/lib/constants/index.d.ts +1 -0
  404. package/lib/constants/index.js +1 -0
  405. package/lib/constants/index.js.map +1 -1
  406. package/lib/constants/registry.d.ts +22 -0
  407. package/lib/constants/registry.js +27 -0
  408. package/lib/constants/registry.js.map +1 -0
  409. package/lib/elements/combos/base-combo.d.ts +64 -6
  410. package/lib/elements/combos/base-combo.js +21 -0
  411. package/lib/elements/combos/base-combo.js.map +1 -1
  412. package/lib/elements/combos/circle.d.ts +8 -12
  413. package/lib/elements/combos/circle.js.map +1 -1
  414. package/lib/elements/combos/rect.d.ts +5 -9
  415. package/lib/elements/combos/rect.js.map +1 -1
  416. package/lib/elements/edges/base-edge.d.ts +85 -10
  417. package/lib/elements/edges/base-edge.js +21 -0
  418. package/lib/elements/edges/base-edge.js.map +1 -1
  419. package/lib/elements/edges/cubic-horizontal.d.ts +2 -2
  420. package/lib/elements/edges/cubic-vertical.d.ts +2 -2
  421. package/lib/elements/edges/cubic.d.ts +2 -2
  422. package/lib/elements/edges/polyline.d.ts +2 -2
  423. package/lib/elements/edges/quadratic.d.ts +2 -2
  424. package/lib/elements/nodes/base-node.d.ts +125 -13
  425. package/lib/elements/nodes/base-node.js +25 -1
  426. package/lib/elements/nodes/base-node.js.map +1 -1
  427. package/lib/elements/nodes/circle.d.ts +5 -8
  428. package/lib/elements/nodes/circle.js.map +1 -1
  429. package/lib/elements/nodes/diamond.d.ts +2 -4
  430. package/lib/elements/nodes/diamond.js +2 -2
  431. package/lib/elements/nodes/diamond.js.map +1 -1
  432. package/lib/elements/nodes/ellipse.d.ts +5 -8
  433. package/lib/elements/nodes/ellipse.js +1 -1
  434. package/lib/elements/nodes/ellipse.js.map +1 -1
  435. package/lib/elements/nodes/hexagon.d.ts +6 -9
  436. package/lib/elements/nodes/hexagon.js.map +1 -1
  437. package/lib/elements/nodes/image.d.ts +9 -11
  438. package/lib/elements/nodes/image.js.map +1 -1
  439. package/lib/elements/nodes/polygon.d.ts +9 -8
  440. package/lib/elements/nodes/polygon.js +4 -1
  441. package/lib/elements/nodes/polygon.js.map +1 -1
  442. package/lib/elements/nodes/rect.d.ts +2 -3
  443. package/lib/elements/nodes/rect.js.map +1 -1
  444. package/lib/elements/nodes/star.d.ts +7 -10
  445. package/lib/elements/nodes/star.js.map +1 -1
  446. package/lib/elements/nodes/triangle.d.ts +7 -10
  447. package/lib/elements/nodes/triangle.js.map +1 -1
  448. package/lib/exports.d.ts +18 -14
  449. package/lib/exports.js +26 -1
  450. package/lib/exports.js.map +1 -1
  451. package/lib/layouts/index.d.ts +1 -1
  452. package/lib/layouts/index.js +2 -1
  453. package/lib/layouts/index.js.map +1 -1
  454. package/lib/layouts/types.d.ts +6 -6
  455. package/lib/palettes/index.d.ts +1 -0
  456. package/lib/palettes/index.js +13 -1
  457. package/lib/palettes/index.js.map +1 -1
  458. package/lib/plugins/camera-setting.d.ts +95 -0
  459. package/lib/plugins/camera-setting.js +69 -0
  460. package/lib/plugins/camera-setting.js.map +1 -0
  461. package/lib/plugins/contextmenu.d.ts +8 -5
  462. package/lib/plugins/contextmenu.js.map +1 -1
  463. package/lib/plugins/history/events.d.ts +21 -0
  464. package/lib/plugins/history/events.js +19 -0
  465. package/lib/plugins/history/events.js.map +1 -0
  466. package/lib/plugins/history/index.d.ts +82 -0
  467. package/lib/plugins/history/index.js +175 -0
  468. package/lib/plugins/history/index.js.map +1 -0
  469. package/lib/plugins/history/utils.d.ts +31 -0
  470. package/lib/plugins/history/utils.js +84 -0
  471. package/lib/plugins/history/utils.js.map +1 -0
  472. package/lib/plugins/hull/index.d.ts +59 -0
  473. package/lib/plugins/hull/index.js +114 -0
  474. package/lib/plugins/hull/index.js.map +1 -0
  475. package/lib/plugins/hull/shape.d.ts +49 -0
  476. package/lib/plugins/hull/shape.js +39 -0
  477. package/lib/plugins/hull/shape.js.map +1 -0
  478. package/lib/plugins/hull/util.d.ts +12 -0
  479. package/lib/plugins/hull/util.js +207 -0
  480. package/lib/plugins/hull/util.js.map +1 -0
  481. package/lib/plugins/index.d.ts +8 -0
  482. package/lib/plugins/index.js +9 -1
  483. package/lib/plugins/index.js.map +1 -1
  484. package/lib/plugins/legend.d.ts +49 -0
  485. package/lib/plugins/legend.js +271 -0
  486. package/lib/plugins/legend.js.map +1 -0
  487. package/lib/plugins/tooltip.d.ts +12 -10
  488. package/lib/plugins/tooltip.js +0 -1
  489. package/lib/plugins/tooltip.js.map +1 -1
  490. package/lib/preset.js +2 -5
  491. package/lib/preset.js.map +1 -1
  492. package/lib/registry/build-in.js +17 -0
  493. package/lib/registry/build-in.js.map +1 -1
  494. package/lib/registry/extension/index.d.ts +3 -3
  495. package/lib/registry/extension/index.js.map +1 -1
  496. package/lib/registry/index.d.ts +6 -4
  497. package/lib/registry/index.js +1 -0
  498. package/lib/registry/index.js.map +1 -1
  499. package/lib/registry/types.d.ts +4 -6
  500. package/lib/runtime/batch.d.ts +11 -0
  501. package/lib/runtime/batch.js +35 -0
  502. package/lib/runtime/batch.js.map +1 -0
  503. package/lib/runtime/behavior.d.ts +1 -1
  504. package/lib/runtime/behavior.js +3 -2
  505. package/lib/runtime/behavior.js.map +1 -1
  506. package/lib/runtime/canvas.d.ts +15 -4
  507. package/lib/runtime/canvas.js +101 -39
  508. package/lib/runtime/canvas.js.map +1 -1
  509. package/lib/runtime/data.d.ts +4 -4
  510. package/lib/runtime/data.js +22 -24
  511. package/lib/runtime/data.js.map +1 -1
  512. package/lib/runtime/element.d.ts +6 -23
  513. package/lib/runtime/element.js +47 -149
  514. package/lib/runtime/element.js.map +1 -1
  515. package/lib/runtime/graph.d.ts +71 -6
  516. package/lib/runtime/graph.js +104 -9
  517. package/lib/runtime/graph.js.map +1 -1
  518. package/lib/runtime/layout.d.ts +5 -11
  519. package/lib/runtime/layout.js +27 -73
  520. package/lib/runtime/layout.js.map +1 -1
  521. package/lib/runtime/plugin.d.ts +2 -1
  522. package/lib/runtime/plugin.js +3 -0
  523. package/lib/runtime/plugin.js.map +1 -1
  524. package/lib/runtime/transform.d.ts +11 -0
  525. package/lib/runtime/transform.js +24 -0
  526. package/lib/runtime/transform.js.map +1 -0
  527. package/lib/runtime/types.d.ts +14 -0
  528. package/lib/spec/index.d.ts +1 -0
  529. package/lib/spec/spec.d.ts +7 -0
  530. package/lib/spec/transform.d.ts +12 -0
  531. package/lib/{types/behavior.js → spec/transform.js} +1 -1
  532. package/lib/spec/transform.js.map +1 -0
  533. package/lib/themes/base.js +9 -1
  534. package/lib/themes/base.js.map +1 -1
  535. package/lib/transforms/arrange-draw-order.d.ts +10 -0
  536. package/lib/transforms/arrange-draw-order.js +31 -0
  537. package/lib/transforms/arrange-draw-order.js.map +1 -0
  538. package/lib/transforms/base-transform.d.ts +7 -0
  539. package/lib/transforms/base-transform.js +11 -0
  540. package/lib/transforms/base-transform.js.map +1 -0
  541. package/lib/transforms/collapse-expand-combo.d.ts +10 -0
  542. package/lib/transforms/collapse-expand-combo.js +86 -0
  543. package/lib/transforms/collapse-expand-combo.js.map +1 -0
  544. package/lib/transforms/index.d.ts +6 -0
  545. package/lib/transforms/index.js +14 -0
  546. package/lib/transforms/index.js.map +1 -0
  547. package/lib/transforms/process-parallel-edges.d.ts +84 -0
  548. package/lib/transforms/process-parallel-edges.js +222 -0
  549. package/lib/transforms/process-parallel-edges.js.map +1 -0
  550. package/lib/transforms/types.d.ts +20 -0
  551. package/lib/transforms/types.js +15 -0
  552. package/lib/transforms/types.js.map +1 -0
  553. package/lib/transforms/update-related-edge.d.ts +9 -0
  554. package/lib/transforms/update-related-edge.js +24 -0
  555. package/lib/transforms/update-related-edge.js.map +1 -0
  556. package/lib/types/canvas.d.ts +1 -1
  557. package/lib/types/change.d.ts +27 -10
  558. package/lib/types/element.d.ts +6 -140
  559. package/lib/types/event.d.ts +42 -7
  560. package/lib/types/index.d.ts +0 -1
  561. package/lib/types/node.d.ts +3 -3
  562. package/lib/types/point.d.ts +1 -0
  563. package/lib/utils/animation.d.ts +1 -1
  564. package/lib/utils/animation.js +6 -0
  565. package/lib/utils/animation.js.map +1 -1
  566. package/lib/utils/bbox.d.ts +1 -1
  567. package/lib/utils/behaviors/brush.d.ts +19 -0
  568. package/lib/utils/behaviors/brush.js +30 -0
  569. package/lib/utils/behaviors/brush.js.map +1 -0
  570. package/lib/utils/behaviors/lasso.d.ts +13 -0
  571. package/lib/utils/behaviors/lasso.js +116 -0
  572. package/lib/utils/behaviors/lasso.js.map +1 -0
  573. package/lib/utils/behaviors/utils.d.ts +21 -0
  574. package/lib/utils/behaviors/utils.js +47 -0
  575. package/lib/utils/behaviors/utils.js.map +1 -0
  576. package/lib/utils/change.d.ts +9 -1
  577. package/lib/utils/change.js +30 -1
  578. package/lib/utils/change.js.map +1 -1
  579. package/lib/utils/combo.d.ts +5 -4
  580. package/lib/utils/combo.js.map +1 -1
  581. package/lib/utils/edge.d.ts +11 -0
  582. package/lib/utils/edge.js +2 -1
  583. package/lib/utils/edge.js.map +1 -1
  584. package/lib/utils/element.d.ts +19 -11
  585. package/lib/utils/element.js +21 -10
  586. package/lib/utils/element.js.map +1 -1
  587. package/lib/utils/event/events.d.ts +9 -14
  588. package/lib/utils/event/events.js +4 -10
  589. package/lib/utils/event/events.js.map +1 -1
  590. package/lib/utils/extension.d.ts +1 -1
  591. package/lib/utils/extension.js.map +1 -1
  592. package/lib/utils/id.d.ts +3 -8
  593. package/lib/utils/id.js +10 -4
  594. package/lib/utils/id.js.map +1 -1
  595. package/lib/utils/line.d.ts +21 -0
  596. package/lib/utils/line.js +46 -0
  597. package/lib/utils/line.js.map +1 -0
  598. package/lib/utils/path.d.ts +35 -0
  599. package/lib/utils/path.js +150 -0
  600. package/lib/utils/path.js.map +1 -0
  601. package/lib/utils/point.d.ts +74 -20
  602. package/lib/utils/point.js +178 -48
  603. package/lib/utils/point.js.map +1 -1
  604. package/lib/utils/polygon.d.ts +17 -0
  605. package/lib/utils/polygon.js +66 -0
  606. package/lib/utils/polygon.js.map +1 -0
  607. package/lib/utils/position.d.ts +14 -1
  608. package/lib/utils/position.js +18 -1
  609. package/lib/utils/position.js.map +1 -1
  610. package/lib/utils/prefix.d.ts +1 -1
  611. package/lib/utils/prefix.js.map +1 -1
  612. package/lib/utils/shortcut.d.ts +11 -0
  613. package/lib/utils/shortcut.js +36 -4
  614. package/lib/utils/shortcut.js.map +1 -1
  615. package/lib/utils/style.js.map +1 -1
  616. package/lib/utils/vector.d.ts +3 -2
  617. package/lib/utils/vector.js +10 -3
  618. package/lib/utils/vector.js.map +1 -1
  619. package/package.json +6 -7
  620. package/src/behaviors/brush-select.ts +306 -0
  621. package/src/behaviors/click-element.ts +182 -0
  622. package/src/behaviors/collapse-expand.ts +13 -11
  623. package/src/behaviors/create-edge.ts +206 -0
  624. package/src/behaviors/drag-canvas.ts +22 -14
  625. package/src/behaviors/drag-element-force.ts +70 -0
  626. package/src/behaviors/drag-element.ts +32 -25
  627. package/src/behaviors/focus-element.ts +7 -6
  628. package/src/behaviors/hover-element.ts +16 -13
  629. package/src/behaviors/index.ts +10 -0
  630. package/src/behaviors/lasso-select.ts +103 -0
  631. package/src/behaviors/types.ts +2 -0
  632. package/src/behaviors/zoom-canvas.ts +14 -9
  633. package/src/constants/change.ts +1 -1
  634. package/src/constants/events/graph.ts +8 -16
  635. package/src/constants/index.ts +1 -0
  636. package/src/constants/registry.ts +22 -0
  637. package/src/elements/combos/base-combo.ts +83 -10
  638. package/src/elements/combos/circle.ts +8 -11
  639. package/src/elements/combos/rect.ts +5 -8
  640. package/src/elements/edges/base-edge.ts +95 -14
  641. package/src/elements/edges/cubic-horizontal.ts +2 -2
  642. package/src/elements/edges/cubic-vertical.ts +2 -2
  643. package/src/elements/edges/cubic.ts +2 -2
  644. package/src/elements/edges/polyline.ts +2 -2
  645. package/src/elements/edges/quadratic.ts +2 -2
  646. package/src/elements/nodes/base-node.ts +140 -20
  647. package/src/elements/nodes/circle.ts +5 -7
  648. package/src/elements/nodes/diamond.ts +4 -6
  649. package/src/elements/nodes/ellipse.ts +6 -8
  650. package/src/elements/nodes/hexagon.ts +7 -9
  651. package/src/elements/nodes/image.ts +12 -13
  652. package/src/elements/nodes/polygon.ts +17 -11
  653. package/src/elements/nodes/rect.ts +3 -4
  654. package/src/elements/nodes/star.ts +9 -11
  655. package/src/elements/nodes/triangle.ts +7 -9
  656. package/src/exports.ts +57 -12
  657. package/src/layouts/index.ts +1 -0
  658. package/src/layouts/types.ts +7 -5
  659. package/src/palettes/index.ts +13 -0
  660. package/src/plugins/camera-setting.ts +153 -0
  661. package/src/plugins/contextmenu.ts +10 -7
  662. package/src/plugins/history/events.ts +25 -0
  663. package/src/plugins/history/index.ts +222 -0
  664. package/src/plugins/history/utils.ts +98 -0
  665. package/src/plugins/hull/index.ts +149 -0
  666. package/src/plugins/hull/shape.ts +96 -0
  667. package/src/plugins/hull/util.ts +222 -0
  668. package/src/plugins/index.ts +8 -0
  669. package/src/plugins/legend.ts +321 -0
  670. package/src/plugins/tooltip.ts +16 -15
  671. package/src/preset.ts +2 -6
  672. package/src/registry/build-in.ts +33 -3
  673. package/src/registry/extension/index.ts +5 -5
  674. package/src/registry/index.ts +11 -4
  675. package/src/registry/types.ts +2 -7
  676. package/src/runtime/batch.ts +38 -0
  677. package/src/runtime/behavior.ts +4 -3
  678. package/src/runtime/canvas.ts +130 -52
  679. package/src/runtime/data.ts +31 -36
  680. package/src/runtime/element.ts +78 -185
  681. package/src/runtime/graph.ts +121 -15
  682. package/src/runtime/layout.ts +48 -79
  683. package/src/runtime/plugin.ts +5 -1
  684. package/src/runtime/transform.ts +27 -0
  685. package/src/runtime/types.ts +14 -0
  686. package/src/spec/index.ts +1 -0
  687. package/src/spec/spec.ts +7 -0
  688. package/src/spec/transform.ts +15 -0
  689. package/src/themes/base.ts +9 -1
  690. package/src/transforms/arrange-draw-order.ts +36 -0
  691. package/src/transforms/base-transform.ts +11 -0
  692. package/src/transforms/collapse-expand-combo.ts +87 -0
  693. package/src/transforms/index.ts +7 -0
  694. package/src/transforms/process-parallel-edges.ts +286 -0
  695. package/src/transforms/types.ts +23 -0
  696. package/src/transforms/update-related-edge.ts +28 -0
  697. package/src/types/canvas.ts +1 -1
  698. package/src/types/change.ts +28 -10
  699. package/src/types/element.ts +6 -147
  700. package/src/types/event.ts +62 -7
  701. package/src/types/index.ts +0 -1
  702. package/src/types/node.ts +3 -3
  703. package/src/types/point.ts +1 -0
  704. package/src/utils/animation.ts +6 -0
  705. package/src/utils/bbox.ts +1 -1
  706. package/src/utils/behaviors/brush.ts +29 -0
  707. package/src/utils/behaviors/lasso.ts +127 -0
  708. package/src/utils/behaviors/utils.ts +47 -0
  709. package/src/utils/change.ts +42 -1
  710. package/src/utils/combo.ts +6 -5
  711. package/src/utils/edge.ts +6 -1
  712. package/src/utils/element.ts +22 -11
  713. package/src/utils/event/events.ts +18 -18
  714. package/src/utils/extension.ts +1 -1
  715. package/src/utils/id.ts +11 -2
  716. package/src/utils/line.ts +50 -0
  717. package/src/utils/path.ts +153 -0
  718. package/src/utils/point.ts +190 -51
  719. package/src/utils/polygon.ts +72 -0
  720. package/src/utils/position.ts +18 -1
  721. package/src/utils/prefix.ts +1 -1
  722. package/src/utils/shortcut.ts +41 -5
  723. package/src/utils/style.ts +1 -1
  724. package/src/utils/vector.ts +10 -3
  725. package/dist/lib/types/behavior.d.ts +0 -5
  726. package/esm/elements/types.d.ts +0 -0
  727. package/esm/elements/types.js +0 -15
  728. package/esm/elements/types.js.map +0 -1
  729. package/esm/types/behavior.d.ts +0 -5
  730. package/esm/types/behavior.js +0 -2
  731. package/esm/types/behavior.js.map +0 -1
  732. package/lib/elements/types.d.ts +0 -0
  733. package/lib/elements/types.js +0 -15
  734. package/lib/elements/types.js.map +0 -1
  735. package/lib/types/behavior.d.ts +0 -5
  736. package/lib/types/behavior.js.map +0 -1
  737. package/src/elements/types.ts +0 -21
  738. package/src/types/behavior.ts +0 -6
@@ -0,0 +1,21 @@
1
+ import type { Point } from '../types';
2
+ export type LineSegment = [Point, Point];
3
+ /**
4
+ * <zh/> 判断两条线段是否平行
5
+ *
6
+ * <en/> Judge whether two line segments are parallel
7
+ * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
8
+ * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
9
+ * @returns <zh/> 是否平行 | <en/> whether parallel or not
10
+ */
11
+ export declare function isLinesParallel(l1: LineSegment, l2: LineSegment): boolean;
12
+ /**
13
+ * <zh/> 获取两条线段的交点
14
+ *
15
+ * <en/> Get the intersection of two line segments
16
+ * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
17
+ * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
18
+ * @param extended - <zh/> 是否包含延长线上的交点 | <en/> whether to include the intersection on the extension line
19
+ * @returns <zh/> 交点 | <en/> intersection
20
+ */
21
+ export declare function getLinesIntersection(l1: LineSegment, l2: LineSegment, extended?: boolean): Point | undefined;
@@ -0,0 +1,41 @@
1
+ import { isBetween } from './math';
2
+ import { cross, subtract } from './vector';
3
+ /**
4
+ * <zh/> 判断两条线段是否平行
5
+ *
6
+ * <en/> Judge whether two line segments are parallel
7
+ * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
8
+ * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
9
+ * @returns <zh/> 是否平行 | <en/> whether parallel or not
10
+ */
11
+ export function isLinesParallel(l1, l2) {
12
+ const [p1, p2] = l1;
13
+ const [p3, p4] = l2;
14
+ const v1 = subtract(p1, p2);
15
+ const v2 = subtract(p3, p4);
16
+ return cross(v1, v2).every((v) => v === 0);
17
+ }
18
+ /**
19
+ * <zh/> 获取两条线段的交点
20
+ *
21
+ * <en/> Get the intersection of two line segments
22
+ * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
23
+ * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
24
+ * @param extended - <zh/> 是否包含延长线上的交点 | <en/> whether to include the intersection on the extension line
25
+ * @returns <zh/> 交点 | <en/> intersection
26
+ */
27
+ export function getLinesIntersection(l1, l2, extended = false) {
28
+ if (isLinesParallel(l1, l2))
29
+ return undefined;
30
+ const [p1, p2] = l1;
31
+ const [p3, p4] = l2;
32
+ const t = ((p1[0] - p3[0]) * (p3[1] - p4[1]) - (p1[1] - p3[1]) * (p3[0] - p4[0])) /
33
+ ((p1[0] - p2[0]) * (p3[1] - p4[1]) - (p1[1] - p2[1]) * (p3[0] - p4[0]));
34
+ const u = p4[0] - p3[0]
35
+ ? (p1[0] - p3[0] + t * (p2[0] - p1[0])) / (p4[0] - p3[0])
36
+ : (p1[1] - p3[1] + t * (p2[1] - p1[1])) / (p4[1] - p3[1]);
37
+ if (!extended && (!isBetween(t, 0, 1) || !isBetween(u, 0, 1)))
38
+ return undefined;
39
+ return [p1[0] + t * (p2[0] - p1[0]), p1[1] + t * (p2[1] - p1[1])];
40
+ }
41
+ //# sourceMappingURL=line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line.js","sourceRoot":"src/","sources":["utils/line.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAI3C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,EAAe,EAAE,EAAe;IAC9D,MAAM,CAAC,EAAE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,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1E,MAAM,CAAC,GACL,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACX,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9D,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAEhF,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { PathArray } from '@antv/util';
2
+ import type { Point, Points } from '../types';
3
+ /**
4
+ * <zh/> points 转化为 path 路径
5
+ *
6
+ * <en/> points transfrom path.
7
+ * @param points Point[]
8
+ * @param isClose boolean
9
+ * @returns path string[][]
10
+ */
11
+ export declare function pointsToPath(points: Points, isClose?: boolean): PathArray;
12
+ /**
13
+ * <zh/> 将路径字符串转换为路径段数组
14
+ *
15
+ * <en/> Convert a path string to an array of path segments.
16
+ * @param path - <zh/> 路径字符串 | <en/> path string
17
+ * @returns <zh/> 路径段数组 | <en/> path segment array
18
+ */
19
+ export declare function parsePath(path: string): PathArray;
20
+ /**
21
+ * <zh/> 将路径转换为点数组
22
+ *
23
+ * <en/> Convert path to points array
24
+ * @param path - <zh/> 路径数组 <en/> path array
25
+ * @returns
26
+ */
27
+ export declare function pathToPoints(path: string | PathArray): Point[];
28
+ /**
29
+ * <zh/> 生成平滑闭合曲线
30
+ *
31
+ * <en/> Generate smooth closed curves
32
+ * @param points - <zh/> 点集 | <en/> points
33
+ * @returns <zh/> 平滑闭合曲线 | <en/> smooth closed curves
34
+ */
35
+ export declare const getClosedSpline: (points: Point[]) => PathArray;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * <zh/> points 转化为 path 路径
3
+ *
4
+ * <en/> points transfrom path.
5
+ * @param points Point[]
6
+ * @param isClose boolean
7
+ * @returns path string[][]
8
+ */
9
+ export function pointsToPath(points, isClose = true) {
10
+ const path = [];
11
+ points.forEach((point, index) => {
12
+ path.push([index === 0 ? 'M' : 'L', ...point]);
13
+ });
14
+ if (isClose) {
15
+ path.push(['Z']);
16
+ }
17
+ return path;
18
+ }
19
+ const PATH_COMMANDS = {
20
+ M: ['x', 'y'],
21
+ m: ['dx', 'dy'],
22
+ H: ['x'],
23
+ h: ['dx'],
24
+ V: ['y'],
25
+ v: ['dy'],
26
+ L: ['x', 'y'],
27
+ l: ['dx', 'dy'],
28
+ Z: [],
29
+ z: [],
30
+ C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],
31
+ c: ['dx1', 'dy1', 'dx2', 'dy2', 'dx', 'dy'],
32
+ S: ['x2', 'y2', 'x', 'y'],
33
+ s: ['dx2', 'dy2', 'dx', 'dy'],
34
+ Q: ['x1', 'y1', 'x', 'y'],
35
+ q: ['dx1', 'dy1', 'dx', 'dy'],
36
+ T: ['x', 'y'],
37
+ t: ['dx', 'dy'],
38
+ A: ['rx', 'ry', 'rotation', 'large-arc', 'sweep', 'x', 'y'],
39
+ a: ['rx', 'ry', 'rotation', 'large-arc', 'sweep', 'dx', 'dy'],
40
+ };
41
+ /**
42
+ * <zh/> 将路径字符串转换为路径段数组
43
+ *
44
+ * <en/> Convert a path string to an array of path segments.
45
+ * @param path - <zh/> 路径字符串 | <en/> path string
46
+ * @returns <zh/> 路径段数组 | <en/> path segment array
47
+ */
48
+ export function parsePath(path) {
49
+ const items = path
50
+ .replace(/[\n\r]/g, '')
51
+ .replace(/-/g, ' -')
52
+ .replace(/(\d*\.)(\d+)(?=\.)/g, '$1$2 ')
53
+ .trim()
54
+ .split(/\s*,|\s+/);
55
+ const segments = [];
56
+ let currentCommand = '';
57
+ let currentElement = {};
58
+ while (items.length > 0) {
59
+ let it = items.shift();
60
+ if (it in PATH_COMMANDS) {
61
+ currentCommand = it;
62
+ }
63
+ else {
64
+ items.unshift(it);
65
+ }
66
+ currentElement = { type: currentCommand };
67
+ PATH_COMMANDS[currentCommand].forEach((prop) => {
68
+ it = items.shift(); // TODO sanity check
69
+ currentElement[prop] = it;
70
+ });
71
+ if (currentCommand === 'M') {
72
+ currentCommand = 'L';
73
+ }
74
+ else if (currentCommand === 'm') {
75
+ currentCommand = 'l';
76
+ }
77
+ const [type, ...values] = Object.values(currentElement);
78
+ segments.push([type, ...values.map(Number)]);
79
+ }
80
+ return segments;
81
+ }
82
+ /**
83
+ * <zh/> 将路径转换为点数组
84
+ *
85
+ * <en/> Convert path to points array
86
+ * @param path - <zh/> 路径数组 <en/> path array
87
+ * @returns
88
+ */
89
+ export function pathToPoints(path) {
90
+ const points = [];
91
+ const segments = typeof path === 'string' ? parsePath(path) : path;
92
+ segments.forEach((seg) => {
93
+ const command = seg[0];
94
+ if (command === 'Z') {
95
+ points.push(points[0]);
96
+ return;
97
+ }
98
+ if (command !== 'A') {
99
+ for (let i = 1; i < seg.length; i = i + 2) {
100
+ points.push([seg[i], seg[i + 1], 0]);
101
+ }
102
+ }
103
+ else {
104
+ const length = seg.length;
105
+ points.push([seg[length - 2], seg[length - 1], 0]);
106
+ }
107
+ });
108
+ return points;
109
+ }
110
+ /**
111
+ * <zh/> 生成平滑闭合曲线
112
+ *
113
+ * <en/> Generate smooth closed curves
114
+ * @param points - <zh/> 点集 | <en/> points
115
+ * @returns <zh/> 平滑闭合曲线 | <en/> smooth closed curves
116
+ */
117
+ export const getClosedSpline = (points) => {
118
+ if (points.length < 2)
119
+ return [
120
+ ['M', 0, 0],
121
+ ['L', 0, 0],
122
+ ];
123
+ const first = points[0];
124
+ const second = points[1];
125
+ const last = points[points.length - 1];
126
+ const lastSecond = points[points.length - 2];
127
+ points.unshift(lastSecond, last);
128
+ points.push(first, second);
129
+ const closedPath = [['M', last[0], last[1]]];
130
+ for (let i = 1; i < points.length - 2; i += 1) {
131
+ const [x0, y0] = points[i - 1];
132
+ const [x1, y1] = points[i];
133
+ const [x2, y2] = points[i + 1];
134
+ const [x3, y3] = i !== points.length - 2 ? points[i + 2] : [x2, y2];
135
+ const cp1x = x1 + (x2 - x0) / 6;
136
+ const cp1y = y1 + (y2 - y0) / 6;
137
+ const cp2x = x2 - (x3 - x1) / 6;
138
+ const cp2y = y2 - (y3 - y1) / 6;
139
+ closedPath.push(['C', cp1x, cp1y, cp2x, cp2y, x2, y2]);
140
+ }
141
+ return closedPath;
142
+ };
143
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"src/","sources":["utils/path.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAO,GAAG,IAAI;IACzD,MAAM,IAAI,GAAG,EAAE,CAAC;IAEhB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,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C;QAC3B,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAEpE,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAChC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,UAAuB,CAAC;AACjC,CAAC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { AABB, PointLike } from '@antv/g';
2
2
  import type { Point } from '../types';
3
+ import type { LineSegment } from './line';
3
4
  /**
4
5
  * <zh/> 将对象坐标转换为数组坐标
5
6
  * <en/> Convert object coordinates to array coordinates
@@ -15,6 +16,21 @@ export declare function parsePoint(point: PointLike): Point;
15
16
  * @returns <zh/> 对象坐标 | <en/> object coordinates
16
17
  */
17
18
  export declare function toPointObject(point: Point): PointLike;
19
+ /**
20
+ * <zh/> 根据 X 轴坐标排序
21
+ * <en/> Sort by X-axis coordinates
22
+ * @param points - <zh/> 点集 | <en/> point set
23
+ * @returns <zh/> 排序后的点集 | <en/> sorted point set
24
+ */
25
+ export declare function sortByX(points: Point[]): Point[];
26
+ /**
27
+ * <zh/> 点集去重
28
+ *
29
+ * <en/> Deduplicate point set
30
+ * @param points - <zh/> 点集 | <en/> pointset
31
+ * @returns <zh/> 去重后的点集 | <en/> deduplicated pointset
32
+ */
33
+ export declare function deduplicate(points: Point[]): Point[];
18
34
  /**
19
35
  * <zh/> 对点格式化,精确到 `digits` 位的数字
20
36
  *
@@ -72,24 +88,6 @@ export declare function isOrthogonal(p1: Point, p2: Point): boolean;
72
88
  * @returns <zh/> 是否三点共线 | <en/> whether three points are collinear
73
89
  */
74
90
  export declare function isCollinear(p1: Point, p2: Point, p3: Point): boolean;
75
- /**
76
- * <zh/> 判断两条线段是否平行
77
- *
78
- * <en/> Judge whether two line segments are parallel
79
- * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
80
- * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
81
- * @returns <zh/> 是否平行 | <en/> whether parallel or not
82
- */
83
- export declare function isLinesParallel(l1: [Point, Point], l2: [Point, Point]): boolean;
84
- /**
85
- * <zh/> 获取两条线段的交点
86
- *
87
- * <en/> Get the intersection of two line segments
88
- * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
89
- * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
90
- * @returns <zh/> 交点 | <en/> intersection
91
- */
92
- export declare function getLinesIntersection(l1: [Point, Point], l2: [Point, Point]): Point | undefined;
93
91
  /**
94
92
  * <zh/> 获取从多边形中心到给定点的连线与多边形边缘的交点
95
93
  *
@@ -98,9 +96,21 @@ export declare function getLinesIntersection(l1: [Point, Point], l2: [Point, Poi
98
96
  * @param center - <zh/> 多边形中心 | <en/> the center of the polygon
99
97
  * @param points - <zh/> 多边形顶点 | <en/> the vertices of the polygon
100
98
  * @param isRelativePos - <zh/> 顶点坐标是否相对中心点 | <en/> whether the vertex coordinates are relative to the center point
101
- * @returns <zh/> 交点 | <en/> intersection
99
+ * @returns <zh/> 交点与相交线段 | <en/> intersection and intersecting line segment
100
+ */
101
+ export declare function getPolygonIntersectPoint(p: Point, center: Point, points: Point[], isRelativePos?: boolean): {
102
+ point: Point;
103
+ line?: LineSegment;
104
+ };
105
+ /**
106
+ * <zh/> 判断点是否在多边形内部(射线法)
107
+ *
108
+ * <en/> Whether point is inside the polygon (ray algo)
109
+ * @param point - <zh/> 点 | <en/> point
110
+ * @param points - <zh/> 多边形顶点 | <en/> polygon vertices
111
+ * @returns <zh/> 是否在多边形内部 | <en/> whether inside the polygon
102
112
  */
103
- export declare function getPolygonIntersectPoint(p: Point, center: Point, points: Point[], isRelativePos?: boolean): Point;
113
+ export declare function isPointInPolygon(point: Point, points: Point[]): boolean;
104
114
  /**
105
115
  * <zh/> 获取从矩形中心到给定点的连线与矩形边缘的交点
106
116
  *
@@ -127,3 +137,47 @@ export declare function getEllipseIntersectPoint(p: Point, bbox: AABB): Point;
127
137
  * @returns <zh/> 距离最近的两个点 | <en/> the nearest two points
128
138
  */
129
139
  export declare function findNearestPoints(group1: Point[], group2: Point[]): [Point, Point];
140
+ /**
141
+ * <zh/> 从一组线段中找到距离给定点最近的线段
142
+ *
143
+ * <en/> Find the line segment closest to the given point from a group of line segments
144
+ * @param point - <zh/> 给定点 | <en/> the given point
145
+ * @param lines - <zh/> 一组线段 | <en/> a group of line segments
146
+ * @returns <zh/> 距离最近的线段 | <en/> the nearest line segment
147
+ */
148
+ export declare function findNearestLine(point: Point, lines: LineSegment[]): [Point, Point];
149
+ /**
150
+ * <zh/> 获取点到线段的距离
151
+ *
152
+ * <en/> Get the distance from a point to a line segment
153
+ * @param point - <zh/> 点 | <en/> the point
154
+ * @param line - <zh/> 线段 | <en/> the line segment
155
+ * @returns <zh/> 点到线段的距离 | <en/> the distance from the point to the line segment
156
+ */
157
+ export declare function getDistanceToLine(point: Point, line: LineSegment): number;
158
+ /**
159
+ * <zh/> 获取线段上距离给定点最近的点
160
+ *
161
+ * <en/> Get the point on the line segment closest to the given point
162
+ * @param point - <zh/> 给定点 | <en/> the given point
163
+ * @param line - <zh/> 线段 | <en/> the line segment
164
+ * @returns <zh/> 线段上距离给定点最近的点 | <en/> the point on the line segment closest to the given point
165
+ */
166
+ export declare function findNearestPointOnLine(point: Point, line: LineSegment): Point;
167
+ /**
168
+ * <zh/> 获取点集的中心点
169
+ *
170
+ * <en/> Get the center point of a set of points
171
+ * @param points - <zh/> 点集 | <en/> point set
172
+ * @returns <zh/> 中心点 | <en/> center point
173
+ */
174
+ export declare function centerOf(points: Point[]): Point;
175
+ /**
176
+ * <zh/> 按顺时针或逆时针方向对点集排序
177
+ *
178
+ * <en/> Sort the point set in a clockwise or counterclockwise direction
179
+ * @param points - <zh/> 点集 | <en/> point set
180
+ * @param clockwise - <zh/> 是否顺时针 | <en/> whether clockwise
181
+ * @returns <zh/> 排序后的点集 | <en/> sorted point set
182
+ */
183
+ export declare function sortByClockwise(points: Point[], clockwise?: boolean): Point[];
@@ -1,7 +1,7 @@
1
1
  import { getBBoxHeight, getBBoxWidth } from './bbox';
2
- import { isBetween } from './math';
2
+ import { getLinesIntersection, isLinesParallel } from './line';
3
3
  import { getXYByPlacement } from './position';
4
- import { add, cross, distance, normalize, subtract, toVector2 } from './vector';
4
+ import { add, distance, divide, normalize, subtract, toVector2 } from './vector';
5
5
  /**
6
6
  * <zh/> 将对象坐标转换为数组坐标
7
7
  * <en/> Convert object coordinates to array coordinates
@@ -21,6 +21,32 @@ export function parsePoint(point) {
21
21
  export function toPointObject(point) {
22
22
  return { x: point[0], y: point[1] };
23
23
  }
24
+ /**
25
+ * <zh/> 根据 X 轴坐标排序
26
+ * <en/> Sort by X-axis coordinates
27
+ * @param points - <zh/> 点集 | <en/> point set
28
+ * @returns <zh/> 排序后的点集 | <en/> sorted point set
29
+ */
30
+ export function sortByX(points) {
31
+ return points.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
32
+ }
33
+ /**
34
+ * <zh/> 点集去重
35
+ *
36
+ * <en/> Deduplicate point set
37
+ * @param points - <zh/> 点集 | <en/> pointset
38
+ * @returns <zh/> 去重后的点集 | <en/> deduplicated pointset
39
+ */
40
+ export function deduplicate(points) {
41
+ const set = new Set();
42
+ return points.filter((p) => {
43
+ const key = p.join(',');
44
+ if (set.has(key))
45
+ return false;
46
+ set.add(key);
47
+ return true;
48
+ });
49
+ }
24
50
  /**
25
51
  * <zh/> 对点格式化,精确到 `digits` 位的数字
26
52
  *
@@ -93,43 +119,6 @@ export function isOrthogonal(p1, p2) {
93
119
  export function isCollinear(p1, p2, p3) {
94
120
  return isLinesParallel([p1, p2], [p2, p3]);
95
121
  }
96
- /**
97
- * <zh/> 判断两条线段是否平行
98
- *
99
- * <en/> Judge whether two line segments are parallel
100
- * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
101
- * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
102
- * @returns <zh/> 是否平行 | <en/> whether parallel or not
103
- */
104
- export function isLinesParallel(l1, l2) {
105
- const [p1, p2] = l1;
106
- const [p3, p4] = l2;
107
- const v1 = subtract(p1, p2);
108
- const v2 = subtract(p3, p4);
109
- return cross(v1, v2).every((v) => v === 0);
110
- }
111
- /**
112
- * <zh/> 获取两条线段的交点
113
- *
114
- * <en/> Get the intersection of two line segments
115
- * @param l1 - <zh/> 第一条线段 | <en/> the first line segment
116
- * @param l2 - <zh/> 第二条线段 | <en/> the second line segment
117
- * @returns <zh/> 交点 | <en/> intersection
118
- */
119
- export function getLinesIntersection(l1, l2) {
120
- if (isLinesParallel(l1, l2))
121
- return undefined;
122
- const [p1, p2] = l1;
123
- const [p3, p4] = l2;
124
- const t = ((p1[0] - p3[0]) * (p3[1] - p4[1]) - (p1[1] - p3[1]) * (p3[0] - p4[0])) /
125
- ((p1[0] - p2[0]) * (p3[1] - p4[1]) - (p1[1] - p2[1]) * (p3[0] - p4[0]));
126
- const u = p4[0] - p3[0]
127
- ? (p1[0] - p3[0] + t * (p2[0] - p1[0])) / (p4[0] - p3[0])
128
- : (p1[1] - p3[1] + t * (p2[1] - p1[1])) / (p4[1] - p3[1]);
129
- if (!isBetween(t, 0, 1) || !isBetween(u, 0, 1))
130
- return undefined;
131
- return [p1[0] + t * (p2[0] - p1[0]), p1[1] + t * (p2[1] - p1[1])];
132
- }
133
122
  /**
134
123
  * <zh/> 获取从多边形中心到给定点的连线与多边形边缘的交点
135
124
  *
@@ -138,7 +127,7 @@ export function getLinesIntersection(l1, l2) {
138
127
  * @param center - <zh/> 多边形中心 | <en/> the center of the polygon
139
128
  * @param points - <zh/> 多边形顶点 | <en/> the vertices of the polygon
140
129
  * @param isRelativePos - <zh/> 顶点坐标是否相对中心点 | <en/> whether the vertex coordinates are relative to the center point
141
- * @returns <zh/> 交点 | <en/> intersection
130
+ * @returns <zh/> 交点与相交线段 | <en/> intersection and intersecting line segment
142
131
  */
143
132
  export function getPolygonIntersectPoint(p, center, points, isRelativePos = true) {
144
133
  for (let i = 0; i < points.length; i++) {
@@ -149,10 +138,54 @@ export function getPolygonIntersectPoint(p, center, points, isRelativePos = true
149
138
  end = add(center, end);
150
139
  }
151
140
  const intersect = getLinesIntersection([center, p], [start, end]);
152
- if (intersect)
153
- return intersect;
141
+ if (intersect) {
142
+ return {
143
+ point: intersect,
144
+ line: [start, end],
145
+ };
146
+ }
154
147
  }
155
- return center;
148
+ return {
149
+ point: center,
150
+ line: undefined,
151
+ };
152
+ }
153
+ /**
154
+ * <zh/> 判断点是否在多边形内部(射线法)
155
+ *
156
+ * <en/> Whether point is inside the polygon (ray algo)
157
+ * @param point - <zh/> 点 | <en/> point
158
+ * @param points - <zh/> 多边形顶点 | <en/> polygon vertices
159
+ * @returns <zh/> 是否在多边形内部 | <en/> whether inside the polygon
160
+ */
161
+ export function isPointInPolygon(point, points) {
162
+ const [x, y] = point;
163
+ let isHit = false;
164
+ const n = points.length;
165
+ // 判断两个 double 在 eps 精度下的大小关系 | Determine the size relationship between two doubles within eps precision
166
+ const tolerance = 1e-6;
167
+ // svg 中点小于 3 个时,不显示,也无法被拾取 | When the number of points in the svg is less than 3, it is not displayed and cannot be picked up
168
+ if (n <= 2)
169
+ return false;
170
+ const dcmp = (xValue) => {
171
+ if (Math.abs(xValue) < tolerance) {
172
+ return 0;
173
+ }
174
+ return xValue < 0 ? -1 : 1;
175
+ };
176
+ for (let i = 0; i < n; i++) {
177
+ const p1 = points[i];
178
+ const p2 = points[(i + 1) % n];
179
+ // 点在多边形一条边上 | The point is on one side of the polygon
180
+ if (isCollinear(p1, p2, point))
181
+ return true;
182
+ // 前一个判断min(p1[1],p2[1])<P.y<=max(p1[1],p2[1]);后一个判断被测点 在 射线与边交点 的左边
183
+ if (dcmp(p1[1] - y) > 0 !== dcmp(p2[1] - y) > 0 &&
184
+ dcmp(x - ((y - p1[1]) * (p1[0] - p2[0])) / (p1[1] - p2[1]) - p1[0]) < 0) {
185
+ isHit = !isHit;
186
+ }
187
+ }
188
+ return isHit;
156
189
  }
157
190
  /**
158
191
  * <zh/> 获取从矩形中心到给定点的连线与矩形边缘的交点
@@ -170,7 +203,7 @@ export function getRectIntersectPoint(p, bbox) {
170
203
  getXYByPlacement(bbox, 'right-bottom'),
171
204
  getXYByPlacement(bbox, 'left-bottom'),
172
205
  ];
173
- return getPolygonIntersectPoint(p, center, corners, false);
206
+ return getPolygonIntersectPoint(p, center, corners, false).point;
174
207
  }
175
208
  /**
176
209
  * <zh/> 获取从椭圆中心到给定点的连线与椭圆边缘的交点
@@ -213,4 +246,95 @@ export function findNearestPoints(group1, group2) {
213
246
  });
214
247
  return nearestPoints;
215
248
  }
249
+ /**
250
+ * <zh/> 从一组线段中找到距离给定点最近的线段
251
+ *
252
+ * <en/> Find the line segment closest to the given point from a group of line segments
253
+ * @param point - <zh/> 给定点 | <en/> the given point
254
+ * @param lines - <zh/> 一组线段 | <en/> a group of line segments
255
+ * @returns <zh/> 距离最近的线段 | <en/> the nearest line segment
256
+ */
257
+ export function findNearestLine(point, lines) {
258
+ let minDistance = Infinity;
259
+ let nearestLine = [
260
+ [0, 0],
261
+ [0, 0],
262
+ ];
263
+ lines.forEach((line) => {
264
+ const distance = getDistanceToLine(point, line);
265
+ if (distance < minDistance) {
266
+ minDistance = distance;
267
+ nearestLine = line;
268
+ }
269
+ });
270
+ return nearestLine;
271
+ }
272
+ /**
273
+ * <zh/> 获取点到线段的距离
274
+ *
275
+ * <en/> Get the distance from a point to a line segment
276
+ * @param point - <zh/> 点 | <en/> the point
277
+ * @param line - <zh/> 线段 | <en/> the line segment
278
+ * @returns <zh/> 点到线段的距离 | <en/> the distance from the point to the line segment
279
+ */
280
+ export function getDistanceToLine(point, line) {
281
+ const nearestPoint = findNearestPointOnLine(point, line);
282
+ return distance(point, nearestPoint);
283
+ }
284
+ /**
285
+ * <zh/> 获取线段上距离给定点最近的点
286
+ *
287
+ * <en/> Get the point on the line segment closest to the given point
288
+ * @param point - <zh/> 给定点 | <en/> the given point
289
+ * @param line - <zh/> 线段 | <en/> the line segment
290
+ * @returns <zh/> 线段上距离给定点最近的点 | <en/> the point on the line segment closest to the given point
291
+ */
292
+ export function findNearestPointOnLine(point, line) {
293
+ const [x1, y1] = line[0];
294
+ const [x2, y2] = line[1];
295
+ const [x3, y3] = point;
296
+ const px = x2 - x1;
297
+ const py = y2 - y1;
298
+ // 若线段实际上是一个点 | If the line segment is actually a point
299
+ if (px === 0 && py === 0) {
300
+ return [x1, y1];
301
+ }
302
+ let u = ((x3 - x1) * px + (y3 - y1) * py) / (px * px + py * py);
303
+ if (u > 1) {
304
+ u = 1;
305
+ }
306
+ else if (u < 0) {
307
+ u = 0;
308
+ }
309
+ const x = x1 + u * px;
310
+ const y = y1 + u * py;
311
+ return [x, y];
312
+ }
313
+ /**
314
+ * <zh/> 获取点集的中心点
315
+ *
316
+ * <en/> Get the center point of a set of points
317
+ * @param points - <zh/> 点集 | <en/> point set
318
+ * @returns <zh/> 中心点 | <en/> center point
319
+ */
320
+ export function centerOf(points) {
321
+ const totalPosition = points.reduce((acc, p) => add(acc, p), [0, 0]);
322
+ return divide(totalPosition, points.length);
323
+ }
324
+ /**
325
+ * <zh/> 按顺时针或逆时针方向对点集排序
326
+ *
327
+ * <en/> Sort the point set in a clockwise or counterclockwise direction
328
+ * @param points - <zh/> 点集 | <en/> point set
329
+ * @param clockwise - <zh/> 是否顺时针 | <en/> whether clockwise
330
+ * @returns <zh/> 排序后的点集 | <en/> sorted point set
331
+ */
332
+ export function sortByClockwise(points, clockwise = true) {
333
+ const center = centerOf(points);
334
+ return points.sort(([x1, y1], [x2, y2]) => {
335
+ const angle1 = Math.atan2(y1 - center[1], x1 - center[0]);
336
+ const angle2 = Math.atan2(y2 - center[1], x2 - center[0]);
337
+ return clockwise ? angle2 - angle1 : angle1 - angle2;
338
+ });
339
+ }
216
340
  //# sourceMappingURL=point.js.map