@antv/util 3.0.2 → 3.1.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.
Files changed (489) hide show
  1. package/README.md +167 -4
  2. package/dist/util.min.js +1 -1
  3. package/esm/color/arr2rgb.js +3 -3
  4. package/esm/color/arr2rgb.js.map +1 -1
  5. package/esm/color/gradient.js +9 -9
  6. package/esm/color/gradient.js.map +1 -1
  7. package/esm/color/tocssgradient.js +18 -18
  8. package/esm/color/tocssgradient.js.map +1 -1
  9. package/esm/color/torgb.js +6 -6
  10. package/esm/color/torgb.js.map +1 -1
  11. package/esm/helper/to-radian.js +1 -1
  12. package/esm/helper/to-radian.js.map +1 -1
  13. package/esm/matrix/index.js +8 -8
  14. package/esm/matrix/index.js.map +1 -1
  15. package/esm/path/convert/path-2-absolute.d.ts +2 -0
  16. package/esm/path/convert/path-2-absolute.js +83 -0
  17. package/esm/path/convert/path-2-absolute.js.map +1 -0
  18. package/esm/path/convert/path-2-curve.d.ts +2 -0
  19. package/esm/path/convert/path-2-curve.js +56 -0
  20. package/esm/path/convert/path-2-curve.js.map +1 -0
  21. package/esm/path/convert/path-2-string.d.ts +6 -0
  22. package/esm/path/convert/path-2-string.js +11 -0
  23. package/esm/path/convert/path-2-string.js.map +1 -0
  24. package/esm/path/index.d.ts +17 -16
  25. package/esm/path/index.js +17 -16
  26. package/esm/path/index.js.map +1 -1
  27. package/esm/path/parser/finalize-segment.d.ts +5 -0
  28. package/esm/path/parser/finalize-segment.js +27 -0
  29. package/esm/path/parser/finalize-segment.js.map +1 -0
  30. package/esm/path/parser/is-arc-command.d.ts +4 -0
  31. package/esm/path/parser/is-arc-command.js +7 -0
  32. package/esm/path/parser/is-arc-command.js.map +1 -0
  33. package/esm/path/parser/is-digit-start.d.ts +6 -0
  34. package/esm/path/parser/is-digit-start.js +11 -0
  35. package/esm/path/parser/is-digit-start.js.map +1 -0
  36. package/esm/path/parser/is-path-command.d.ts +4 -0
  37. package/esm/path/parser/is-path-command.js +23 -0
  38. package/esm/path/parser/is-path-command.js.map +1 -0
  39. package/esm/path/parser/is-space.d.ts +4 -0
  40. package/esm/path/parser/is-space.js +22 -0
  41. package/esm/path/parser/is-space.js.map +1 -0
  42. package/esm/path/parser/params-count.d.ts +13 -0
  43. package/esm/path/parser/params-count.js +14 -0
  44. package/esm/path/parser/params-count.js.map +1 -0
  45. package/esm/path/parser/params-parser.d.ts +10 -0
  46. package/esm/path/parser/params-parser.js +11 -0
  47. package/esm/path/parser/params-parser.js.map +1 -0
  48. package/esm/path/parser/parse-path-string.d.ts +6 -0
  49. package/esm/path/parser/parse-path-string.js +21 -0
  50. package/esm/path/parser/parse-path-string.js.map +1 -0
  51. package/esm/path/parser/path-parser.d.ts +16 -0
  52. package/esm/path/parser/path-parser.js +18 -0
  53. package/esm/path/parser/path-parser.js.map +1 -0
  54. package/esm/path/parser/scan-flag.d.ts +6 -0
  55. package/esm/path/parser/scan-flag.js +20 -0
  56. package/esm/path/parser/scan-flag.js.map +1 -0
  57. package/esm/path/parser/scan-param.d.ts +6 -0
  58. package/esm/path/parser/scan-param.js +83 -0
  59. package/esm/path/parser/scan-param.js.map +1 -0
  60. package/esm/path/parser/scan-segment.d.ts +6 -0
  61. package/esm/path/parser/scan-segment.js +57 -0
  62. package/esm/path/parser/scan-segment.js.map +1 -0
  63. package/esm/path/parser/skip-spaces.d.ts +7 -0
  64. package/esm/path/parser/skip-spaces.js +13 -0
  65. package/esm/path/parser/skip-spaces.js.map +1 -0
  66. package/esm/path/process/arc-2-cubic.d.ts +7 -1
  67. package/esm/path/process/arc-2-cubic.js +276 -133
  68. package/esm/path/process/arc-2-cubic.js.map +1 -1
  69. package/esm/path/process/clone-path.d.ts +2 -0
  70. package/esm/path/process/clone-path.js +4 -0
  71. package/esm/path/process/clone-path.js.map +1 -0
  72. package/esm/path/process/fix-arc.d.ts +2 -0
  73. package/esm/path/process/fix-arc.js +16 -0
  74. package/esm/path/process/fix-arc.js.map +1 -0
  75. package/esm/path/process/line-2-cubic.js +17 -32
  76. package/esm/path/process/line-2-cubic.js.map +1 -1
  77. package/esm/path/process/normalize-path.d.ts +8 -0
  78. package/esm/path/process/normalize-path.js +35 -0
  79. package/esm/path/process/normalize-path.js.map +1 -0
  80. package/esm/path/process/normalize-segment.d.ts +6 -0
  81. package/esm/path/process/normalize-segment.js +42 -0
  82. package/esm/path/process/normalize-segment.js.map +1 -0
  83. package/esm/path/process/quad-2-cubic.js +2 -2
  84. package/esm/path/process/quad-2-cubic.js.map +1 -1
  85. package/esm/path/process/reverse-curve.d.ts +2 -0
  86. package/esm/path/process/reverse-curve.js +13 -0
  87. package/esm/path/process/reverse-curve.js.map +1 -0
  88. package/esm/path/process/round-path.d.ts +6 -0
  89. package/esm/path/process/round-path.js +20 -0
  90. package/esm/path/process/round-path.js.map +1 -0
  91. package/esm/path/process/segment-2-cubic.d.ts +2 -2
  92. package/esm/path/process/segment-2-cubic.js +23 -19
  93. package/esm/path/process/segment-2-cubic.js.map +1 -1
  94. package/esm/path/types.d.ts +114 -17
  95. package/esm/path/util/distance-square-root.d.ts +1 -0
  96. package/esm/path/util/distance-square-root.js +4 -0
  97. package/esm/path/util/distance-square-root.js.map +1 -0
  98. package/esm/path/util/equalize-segments.d.ts +2 -0
  99. package/esm/path/util/equalize-segments.js +68 -0
  100. package/esm/path/util/equalize-segments.js.map +1 -0
  101. package/esm/path/util/get-draw-direction.d.ts +2 -0
  102. package/esm/path/util/get-draw-direction.js +5 -0
  103. package/esm/path/util/get-draw-direction.js.map +1 -0
  104. package/esm/path/util/get-path-area.d.ts +8 -0
  105. package/esm/path/util/get-path-area.js +68 -0
  106. package/esm/path/util/get-path-area.js.map +1 -0
  107. package/esm/path/util/get-path-bbox-total-length.d.ts +5 -0
  108. package/esm/path/util/get-path-bbox-total-length.js +37 -0
  109. package/esm/path/util/get-path-bbox-total-length.js.map +1 -0
  110. package/esm/path/util/get-path-bbox.d.ts +5 -0
  111. package/esm/path/util/get-path-bbox.js +35 -0
  112. package/esm/path/util/get-path-bbox.js.map +1 -0
  113. package/esm/path/util/get-point-at-length.d.ts +5 -0
  114. package/esm/path/util/get-point-at-length.js +8 -0
  115. package/esm/path/util/get-point-at-length.js.map +1 -0
  116. package/esm/path/util/get-properties-at-length.d.ts +6 -0
  117. package/esm/path/util/get-properties-at-length.js +58 -0
  118. package/esm/path/util/get-properties-at-length.js.map +1 -0
  119. package/esm/path/util/get-properties-at-point.d.ts +7 -0
  120. package/esm/path/util/get-properties-at-point.js +69 -0
  121. package/esm/path/util/get-properties-at-point.js.map +1 -0
  122. package/esm/path/util/get-rotated-curve.d.ts +2 -0
  123. package/esm/path/util/get-rotated-curve.js +34 -0
  124. package/esm/path/util/get-rotated-curve.js.map +1 -0
  125. package/esm/path/util/get-total-length.d.ts +8 -0
  126. package/esm/path/util/get-total-length.js +11 -0
  127. package/esm/path/util/get-total-length.js.map +1 -0
  128. package/esm/path/util/is-absolute-array.d.ts +6 -0
  129. package/esm/path/util/is-absolute-array.js +11 -0
  130. package/esm/path/util/is-absolute-array.js.map +1 -0
  131. package/esm/path/util/is-curve-array.d.ts +9 -0
  132. package/esm/path/util/is-curve-array.js +12 -0
  133. package/esm/path/util/is-curve-array.js.map +1 -0
  134. package/esm/path/util/is-normalized-array.d.ts +7 -0
  135. package/esm/path/util/is-normalized-array.js +10 -0
  136. package/esm/path/util/is-normalized-array.js.map +1 -0
  137. package/esm/path/util/is-path-array.d.ts +5 -0
  138. package/esm/path/util/is-path-array.js +12 -0
  139. package/esm/path/util/is-path-array.js.map +1 -0
  140. package/esm/path/util/is-point-in-stroke.d.ts +5 -0
  141. package/esm/path/util/is-point-in-stroke.js +9 -0
  142. package/esm/path/util/is-point-in-stroke.js.map +1 -0
  143. package/esm/path/util/mid-point.d.ts +1 -0
  144. package/esm/path/util/mid-point.js +8 -0
  145. package/esm/path/util/mid-point.js.map +1 -0
  146. package/esm/path/util/path-length-factory.d.ts +7 -0
  147. package/esm/path/util/path-length-factory.js +94 -0
  148. package/esm/path/util/path-length-factory.js.map +1 -0
  149. package/esm/path/util/rotate-vector.d.ts +4 -0
  150. package/esm/path/util/rotate-vector.js +6 -0
  151. package/esm/path/util/rotate-vector.js.map +1 -0
  152. package/esm/path/util/segment-arc-factory.d.ts +6 -0
  153. package/esm/path/util/segment-arc-factory.js +135 -0
  154. package/esm/path/util/segment-arc-factory.js.map +1 -0
  155. package/esm/path/util/segment-cubic-factory.d.ts +6 -0
  156. package/esm/path/util/segment-cubic-factory.js +63 -0
  157. package/esm/path/util/segment-cubic-factory.js.map +1 -0
  158. package/esm/path/util/segment-line-factory.d.ts +6 -0
  159. package/esm/path/util/segment-line-factory.js +36 -0
  160. package/esm/path/util/segment-line-factory.js.map +1 -0
  161. package/esm/path/util/segment-quad-factory.d.ts +6 -0
  162. package/esm/path/util/segment-quad-factory.js +65 -0
  163. package/esm/path/util/segment-quad-factory.js.map +1 -0
  164. package/lib/color/arr2rgb.js +3 -3
  165. package/lib/color/arr2rgb.js.map +1 -1
  166. package/lib/color/gradient.js +12 -12
  167. package/lib/color/gradient.js.map +1 -1
  168. package/lib/color/tocssgradient.js +18 -18
  169. package/lib/color/tocssgradient.js.map +1 -1
  170. package/lib/color/torgb.js +7 -7
  171. package/lib/color/torgb.js.map +1 -1
  172. package/lib/helper/to-radian.js +1 -1
  173. package/lib/helper/to-radian.js.map +1 -1
  174. package/lib/matrix/index.js +9 -9
  175. package/lib/matrix/index.js.map +1 -1
  176. package/lib/path/convert/path-2-absolute.d.ts +2 -0
  177. package/lib/path/convert/path-2-absolute.js +87 -0
  178. package/lib/path/convert/path-2-absolute.js.map +1 -0
  179. package/lib/path/convert/path-2-curve.d.ts +2 -0
  180. package/lib/path/convert/path-2-curve.js +60 -0
  181. package/lib/path/convert/path-2-curve.js.map +1 -0
  182. package/lib/path/convert/path-2-string.d.ts +6 -0
  183. package/lib/path/convert/path-2-string.js +15 -0
  184. package/lib/path/convert/path-2-string.js.map +1 -0
  185. package/lib/path/index.d.ts +17 -16
  186. package/lib/path/index.js +42 -31
  187. package/lib/path/index.js.map +1 -1
  188. package/lib/path/parser/finalize-segment.d.ts +5 -0
  189. package/lib/path/parser/finalize-segment.js +31 -0
  190. package/lib/path/parser/finalize-segment.js.map +1 -0
  191. package/lib/path/parser/is-arc-command.d.ts +4 -0
  192. package/lib/path/parser/is-arc-command.js +11 -0
  193. package/lib/path/parser/is-arc-command.js.map +1 -0
  194. package/lib/path/parser/is-digit-start.d.ts +6 -0
  195. package/lib/path/parser/is-digit-start.js +16 -0
  196. package/lib/path/parser/is-digit-start.js.map +1 -0
  197. package/lib/path/parser/is-path-command.d.ts +4 -0
  198. package/lib/path/parser/is-path-command.js +27 -0
  199. package/lib/path/parser/is-path-command.js.map +1 -0
  200. package/lib/path/parser/is-space.d.ts +4 -0
  201. package/lib/path/parser/is-space.js +26 -0
  202. package/lib/path/parser/is-space.js.map +1 -0
  203. package/lib/path/parser/params-count.d.ts +13 -0
  204. package/lib/path/parser/params-count.js +17 -0
  205. package/lib/path/parser/params-count.js.map +1 -0
  206. package/lib/path/parser/params-parser.d.ts +10 -0
  207. package/lib/path/parser/params-parser.js +14 -0
  208. package/lib/path/parser/params-parser.js.map +1 -0
  209. package/lib/path/parser/parse-path-string.d.ts +6 -0
  210. package/lib/path/parser/parse-path-string.js +25 -0
  211. package/lib/path/parser/parse-path-string.js.map +1 -0
  212. package/lib/path/parser/path-parser.d.ts +16 -0
  213. package/lib/path/parser/path-parser.js +22 -0
  214. package/lib/path/parser/path-parser.js.map +1 -0
  215. package/lib/path/parser/scan-flag.d.ts +6 -0
  216. package/lib/path/parser/scan-flag.js +24 -0
  217. package/lib/path/parser/scan-flag.js.map +1 -0
  218. package/lib/path/parser/scan-param.d.ts +6 -0
  219. package/lib/path/parser/scan-param.js +87 -0
  220. package/lib/path/parser/scan-param.js.map +1 -0
  221. package/lib/path/parser/scan-segment.d.ts +6 -0
  222. package/lib/path/parser/scan-segment.js +61 -0
  223. package/lib/path/parser/scan-segment.js.map +1 -0
  224. package/lib/path/parser/skip-spaces.d.ts +7 -0
  225. package/lib/path/parser/skip-spaces.js +17 -0
  226. package/lib/path/parser/skip-spaces.js.map +1 -0
  227. package/lib/path/process/arc-2-cubic.d.ts +7 -1
  228. package/lib/path/process/arc-2-cubic.js +276 -133
  229. package/lib/path/process/arc-2-cubic.js.map +1 -1
  230. package/lib/path/process/clone-path.d.ts +2 -0
  231. package/lib/path/process/clone-path.js +8 -0
  232. package/lib/path/process/clone-path.js.map +1 -0
  233. package/lib/path/process/fix-arc.d.ts +2 -0
  234. package/lib/path/process/fix-arc.js +20 -0
  235. package/lib/path/process/fix-arc.js.map +1 -0
  236. package/lib/path/process/line-2-cubic.js +17 -32
  237. package/lib/path/process/line-2-cubic.js.map +1 -1
  238. package/lib/path/process/normalize-path.d.ts +8 -0
  239. package/lib/path/process/normalize-path.js +39 -0
  240. package/lib/path/process/normalize-path.js.map +1 -0
  241. package/lib/path/process/normalize-segment.d.ts +6 -0
  242. package/lib/path/process/normalize-segment.js +46 -0
  243. package/lib/path/process/normalize-segment.js.map +1 -0
  244. package/lib/path/process/quad-2-cubic.js +2 -2
  245. package/lib/path/process/quad-2-cubic.js.map +1 -1
  246. package/lib/path/process/reverse-curve.d.ts +2 -0
  247. package/lib/path/process/reverse-curve.js +17 -0
  248. package/lib/path/process/reverse-curve.js.map +1 -0
  249. package/lib/path/process/round-path.d.ts +6 -0
  250. package/lib/path/process/round-path.js +24 -0
  251. package/lib/path/process/round-path.js.map +1 -0
  252. package/lib/path/process/segment-2-cubic.d.ts +2 -2
  253. package/lib/path/process/segment-2-cubic.js +26 -22
  254. package/lib/path/process/segment-2-cubic.js.map +1 -1
  255. package/lib/path/types.d.ts +114 -17
  256. package/lib/path/util/distance-square-root.d.ts +1 -0
  257. package/lib/path/util/distance-square-root.js +8 -0
  258. package/lib/path/util/distance-square-root.js.map +1 -0
  259. package/lib/path/util/equalize-segments.d.ts +2 -0
  260. package/lib/path/util/equalize-segments.js +72 -0
  261. package/lib/path/util/equalize-segments.js.map +1 -0
  262. package/lib/path/util/get-draw-direction.d.ts +2 -0
  263. package/lib/path/util/get-draw-direction.js +9 -0
  264. package/lib/path/util/get-draw-direction.js.map +1 -0
  265. package/lib/path/util/get-path-area.d.ts +8 -0
  266. package/lib/path/util/get-path-area.js +72 -0
  267. package/lib/path/util/get-path-area.js.map +1 -0
  268. package/lib/path/util/get-path-bbox-total-length.d.ts +5 -0
  269. package/lib/path/util/get-path-bbox-total-length.js +41 -0
  270. package/lib/path/util/get-path-bbox-total-length.js.map +1 -0
  271. package/lib/path/util/get-path-bbox.d.ts +5 -0
  272. package/lib/path/util/get-path-bbox.js +39 -0
  273. package/lib/path/util/get-path-bbox.js.map +1 -0
  274. package/lib/path/util/get-point-at-length.d.ts +5 -0
  275. package/lib/path/util/get-point-at-length.js +12 -0
  276. package/lib/path/util/get-point-at-length.js.map +1 -0
  277. package/lib/path/util/get-properties-at-length.d.ts +6 -0
  278. package/lib/path/util/get-properties-at-length.js +62 -0
  279. package/lib/path/util/get-properties-at-length.js.map +1 -0
  280. package/lib/path/util/get-properties-at-point.d.ts +7 -0
  281. package/lib/path/util/get-properties-at-point.js +73 -0
  282. package/lib/path/util/get-properties-at-point.js.map +1 -0
  283. package/lib/path/util/get-rotated-curve.d.ts +2 -0
  284. package/lib/path/util/get-rotated-curve.js +38 -0
  285. package/lib/path/util/get-rotated-curve.js.map +1 -0
  286. package/lib/path/util/get-total-length.d.ts +8 -0
  287. package/lib/path/util/get-total-length.js +15 -0
  288. package/lib/path/util/get-total-length.js.map +1 -0
  289. package/lib/path/util/is-absolute-array.d.ts +6 -0
  290. package/lib/path/util/is-absolute-array.js +15 -0
  291. package/lib/path/util/is-absolute-array.js.map +1 -0
  292. package/lib/path/util/is-curve-array.d.ts +9 -0
  293. package/lib/path/util/is-curve-array.js +16 -0
  294. package/lib/path/util/is-curve-array.js.map +1 -0
  295. package/lib/path/util/is-normalized-array.d.ts +7 -0
  296. package/lib/path/util/is-normalized-array.js +14 -0
  297. package/lib/path/util/is-normalized-array.js.map +1 -0
  298. package/lib/path/util/is-path-array.d.ts +5 -0
  299. package/lib/path/util/is-path-array.js +16 -0
  300. package/lib/path/util/is-path-array.js.map +1 -0
  301. package/lib/path/util/is-point-in-stroke.d.ts +5 -0
  302. package/lib/path/util/is-point-in-stroke.js +13 -0
  303. package/lib/path/util/is-point-in-stroke.js.map +1 -0
  304. package/lib/path/util/mid-point.d.ts +1 -0
  305. package/lib/path/util/mid-point.js +12 -0
  306. package/lib/path/util/mid-point.js.map +1 -0
  307. package/lib/path/util/path-length-factory.d.ts +7 -0
  308. package/lib/path/util/path-length-factory.js +98 -0
  309. package/lib/path/util/path-length-factory.js.map +1 -0
  310. package/lib/path/util/rotate-vector.d.ts +4 -0
  311. package/lib/path/util/rotate-vector.js +10 -0
  312. package/lib/path/util/rotate-vector.js.map +1 -0
  313. package/lib/path/util/segment-arc-factory.d.ts +6 -0
  314. package/lib/path/util/segment-arc-factory.js +139 -0
  315. package/lib/path/util/segment-arc-factory.js.map +1 -0
  316. package/lib/path/util/segment-cubic-factory.d.ts +6 -0
  317. package/lib/path/util/segment-cubic-factory.js +67 -0
  318. package/lib/path/util/segment-cubic-factory.js.map +1 -0
  319. package/lib/path/util/segment-line-factory.d.ts +6 -0
  320. package/lib/path/util/segment-line-factory.js +40 -0
  321. package/lib/path/util/segment-line-factory.js.map +1 -0
  322. package/lib/path/util/segment-quad-factory.d.ts +6 -0
  323. package/lib/path/util/segment-quad-factory.js +69 -0
  324. package/lib/path/util/segment-quad-factory.js.map +1 -0
  325. package/package.json +1 -1
  326. package/src/.DS_Store +0 -0
  327. package/src/path/.DS_Store +0 -0
  328. package/src/path/convert/path-2-absolute.ts +90 -0
  329. package/src/path/convert/path-2-curve.ts +68 -0
  330. package/src/path/convert/path-2-string.ts +12 -0
  331. package/src/path/index.ts +18 -16
  332. package/src/path/parser/finalize-segment.ts +30 -0
  333. package/src/path/parser/is-arc-command.ts +6 -0
  334. package/src/path/parser/is-digit-start.ts +13 -0
  335. package/src/path/parser/is-path-command.ts +22 -0
  336. package/src/path/parser/is-space.ts +23 -0
  337. package/src/path/parser/params-count.ts +13 -0
  338. package/src/path/parser/params-parser.ts +10 -0
  339. package/src/path/parser/parse-path-string.ts +26 -0
  340. package/src/path/parser/path-parser.ts +35 -0
  341. package/src/path/parser/scan-flag.ts +24 -0
  342. package/src/path/parser/scan-param.ts +98 -0
  343. package/src/path/parser/scan-segment.ts +68 -0
  344. package/src/path/parser/skip-spaces.ts +14 -0
  345. package/src/path/process/arc-2-cubic.ts +332 -215
  346. package/src/path/process/clone-path.ts +5 -0
  347. package/src/path/process/fix-arc.ts +17 -0
  348. package/src/path/process/line-2-cubic.ts +17 -33
  349. package/src/path/process/normalize-path.ts +42 -0
  350. package/src/path/process/normalize-segment.ts +42 -0
  351. package/src/path/process/reverse-curve.ts +18 -0
  352. package/src/path/process/round-path.ts +22 -0
  353. package/src/path/process/segment-2-cubic.ts +28 -27
  354. package/src/path/types.ts +190 -17
  355. package/src/path/util/distance-square-root.ts +3 -0
  356. package/src/path/util/equalize-segments.ts +79 -0
  357. package/src/path/util/get-draw-direction.ts +6 -0
  358. package/src/path/util/get-path-area.ts +83 -0
  359. package/src/path/util/get-path-bbox-total-length.ts +45 -0
  360. package/src/path/util/get-path-bbox.ts +42 -0
  361. package/src/path/util/get-point-at-length.ts +9 -0
  362. package/src/path/util/get-properties-at-length.ts +65 -0
  363. package/src/path/util/get-properties-at-point.ts +73 -0
  364. package/src/path/util/get-rotated-curve.ts +42 -0
  365. package/src/path/util/get-total-length.ts +12 -0
  366. package/src/path/util/is-absolute-array.ts +14 -0
  367. package/src/path/util/is-curve-array.ts +13 -0
  368. package/src/path/util/is-normalized-array.ts +11 -0
  369. package/src/path/util/is-path-array.ts +15 -0
  370. package/src/path/util/is-point-in-stroke.ts +10 -0
  371. package/src/path/util/mid-point.ts +7 -0
  372. package/src/path/util/path-length-factory.ts +98 -0
  373. package/src/path/util/rotate-vector.ts +5 -0
  374. package/src/path/util/segment-arc-factory.ts +186 -0
  375. package/src/path/util/segment-cubic-factory.ts +92 -0
  376. package/src/path/util/segment-line-factory.ts +37 -0
  377. package/src/path/util/segment-quad-factory.ts +90 -0
  378. package/esm/path/catmull-rom-2-bezier.d.ts +0 -10
  379. package/esm/path/catmull-rom-2-bezier.js +0 -115
  380. package/esm/path/catmull-rom-2-bezier.js.map +0 -1
  381. package/esm/path/fill-path-by-diff.d.ts +0 -5
  382. package/esm/path/fill-path-by-diff.js +0 -110
  383. package/esm/path/fill-path-by-diff.js.map +0 -1
  384. package/esm/path/fill-path.d.ts +0 -1
  385. package/esm/path/fill-path.js +0 -129
  386. package/esm/path/fill-path.js.map +0 -1
  387. package/esm/path/format-path.d.ts +0 -1
  388. package/esm/path/format-path.js +0 -139
  389. package/esm/path/format-path.js.map +0 -1
  390. package/esm/path/get-arc-params.d.ts +0 -17
  391. package/esm/path/get-arc-params.js +0 -90
  392. package/esm/path/get-arc-params.js.map +0 -1
  393. package/esm/path/get-line-intersect.d.ts +0 -14
  394. package/esm/path/get-line-intersect.js +0 -33
  395. package/esm/path/get-line-intersect.js.map +0 -1
  396. package/esm/path/is-polygons-intersect.d.ts +0 -1
  397. package/esm/path/is-polygons-intersect.js +0 -81
  398. package/esm/path/is-polygons-intersect.js.map +0 -1
  399. package/esm/path/parse-path-array.d.ts +0 -1
  400. package/esm/path/parse-path-array.js +0 -5
  401. package/esm/path/parse-path-array.js.map +0 -1
  402. package/esm/path/parse-path-string.d.ts +0 -1
  403. package/esm/path/parse-path-string.js +0 -61
  404. package/esm/path/parse-path-string.js.map +0 -1
  405. package/esm/path/parse-path.d.ts +0 -1
  406. package/esm/path/parse-path.js +0 -33
  407. package/esm/path/parse-path.js.map +0 -1
  408. package/esm/path/path-2-absolute.d.ts +0 -1
  409. package/esm/path/path-2-absolute.js +0 -124
  410. package/esm/path/path-2-absolute.js.map +0 -1
  411. package/esm/path/path-2-curve.d.ts +0 -2
  412. package/esm/path/path-2-curve.js +0 -63
  413. package/esm/path/path-2-curve.js.map +0 -1
  414. package/esm/path/path-2-segments.d.ts +0 -1
  415. package/esm/path/path-2-segments.js +0 -138
  416. package/esm/path/path-2-segments.js.map +0 -1
  417. package/esm/path/path-intersection.d.ts +0 -9
  418. package/esm/path/path-intersection.js +0 -366
  419. package/esm/path/path-intersection.js.map +0 -1
  420. package/esm/path/point-in-polygon.d.ts +0 -5
  421. package/esm/path/point-in-polygon.js +0 -49
  422. package/esm/path/point-in-polygon.js.map +0 -1
  423. package/esm/path/rect-path.d.ts +0 -4
  424. package/esm/path/rect-path.js +0 -19
  425. package/esm/path/rect-path.js.map +0 -1
  426. package/lib/path/catmull-rom-2-bezier.d.ts +0 -10
  427. package/lib/path/catmull-rom-2-bezier.js +0 -119
  428. package/lib/path/catmull-rom-2-bezier.js.map +0 -1
  429. package/lib/path/fill-path-by-diff.d.ts +0 -5
  430. package/lib/path/fill-path-by-diff.js +0 -117
  431. package/lib/path/fill-path-by-diff.js.map +0 -1
  432. package/lib/path/fill-path.d.ts +0 -1
  433. package/lib/path/fill-path.js +0 -133
  434. package/lib/path/fill-path.js.map +0 -1
  435. package/lib/path/format-path.d.ts +0 -1
  436. package/lib/path/format-path.js +0 -143
  437. package/lib/path/format-path.js.map +0 -1
  438. package/lib/path/get-arc-params.d.ts +0 -17
  439. package/lib/path/get-arc-params.js +0 -95
  440. package/lib/path/get-arc-params.js.map +0 -1
  441. package/lib/path/get-line-intersect.d.ts +0 -14
  442. package/lib/path/get-line-intersect.js +0 -37
  443. package/lib/path/get-line-intersect.js.map +0 -1
  444. package/lib/path/is-polygons-intersect.d.ts +0 -1
  445. package/lib/path/is-polygons-intersect.js +0 -85
  446. package/lib/path/is-polygons-intersect.js.map +0 -1
  447. package/lib/path/parse-path-array.d.ts +0 -1
  448. package/lib/path/parse-path-array.js +0 -9
  449. package/lib/path/parse-path-array.js.map +0 -1
  450. package/lib/path/parse-path-string.d.ts +0 -1
  451. package/lib/path/parse-path-string.js +0 -65
  452. package/lib/path/parse-path-string.js.map +0 -1
  453. package/lib/path/parse-path.d.ts +0 -1
  454. package/lib/path/parse-path.js +0 -37
  455. package/lib/path/parse-path.js.map +0 -1
  456. package/lib/path/path-2-absolute.d.ts +0 -1
  457. package/lib/path/path-2-absolute.js +0 -128
  458. package/lib/path/path-2-absolute.js.map +0 -1
  459. package/lib/path/path-2-curve.d.ts +0 -2
  460. package/lib/path/path-2-curve.js +0 -67
  461. package/lib/path/path-2-curve.js.map +0 -1
  462. package/lib/path/path-2-segments.d.ts +0 -1
  463. package/lib/path/path-2-segments.js +0 -142
  464. package/lib/path/path-2-segments.js.map +0 -1
  465. package/lib/path/path-intersection.d.ts +0 -9
  466. package/lib/path/path-intersection.js +0 -370
  467. package/lib/path/path-intersection.js.map +0 -1
  468. package/lib/path/point-in-polygon.d.ts +0 -5
  469. package/lib/path/point-in-polygon.js +0 -53
  470. package/lib/path/point-in-polygon.js.map +0 -1
  471. package/lib/path/rect-path.d.ts +0 -4
  472. package/lib/path/rect-path.js +0 -23
  473. package/lib/path/rect-path.js.map +0 -1
  474. package/src/path/catmull-rom-2-bezier.ts +0 -141
  475. package/src/path/fill-path-by-diff.ts +0 -116
  476. package/src/path/fill-path.ts +0 -129
  477. package/src/path/format-path.ts +0 -142
  478. package/src/path/get-arc-params.ts +0 -102
  479. package/src/path/get-line-intersect.ts +0 -46
  480. package/src/path/is-polygons-intersect.ts +0 -95
  481. package/src/path/parse-path-array.ts +0 -5
  482. package/src/path/parse-path-string.ts +0 -62
  483. package/src/path/parse-path.ts +0 -34
  484. package/src/path/path-2-absolute.ts +0 -132
  485. package/src/path/path-2-curve.ts +0 -69
  486. package/src/path/path-2-segments.ts +0 -142
  487. package/src/path/path-intersection.ts +0 -419
  488. package/src/path/point-in-polygon.ts +0 -56
  489. package/src/path/rect-path.ts +0 -22
@@ -1,95 +0,0 @@
1
- import { isPointInPolygon } from './point-in-polygon';
2
- import { getLineIntersect } from './get-line-intersect';
3
-
4
- function parseToLines(points) {
5
- const lines = [];
6
- const count = points.length;
7
- for (let i = 0; i < count - 1; i++) {
8
- const point = points[i];
9
- const next = points[i + 1];
10
- lines.push({
11
- from: {
12
- x: point[0],
13
- y: point[1],
14
- },
15
- to: {
16
- x: next[0],
17
- y: next[1],
18
- },
19
- });
20
- }
21
- if (lines.length > 1) {
22
- const first = points[0];
23
- const last = points[count - 1];
24
- lines.push({
25
- from: {
26
- x: last[0],
27
- y: last[1],
28
- },
29
- to: {
30
- x: first[0],
31
- y: first[1],
32
- },
33
- });
34
- }
35
- return lines;
36
- }
37
-
38
- function lineIntersectPolygon(lines, line) {
39
- for (let i = 0; i < lines.length; i++) {
40
- const l = lines[i];
41
- if (getLineIntersect(l.from, l.to, line.from, line.to)) {
42
- return true;
43
- }
44
- }
45
- return false;
46
- }
47
-
48
- type BBox = {
49
- minX: number;
50
- minY: number;
51
- maxX: number;
52
- maxY: number;
53
- };
54
-
55
- function getBBox(points): BBox {
56
- const xArr = points.map((p) => p[0]);
57
- const yArr = points.map((p) => p[1]);
58
- return {
59
- minX: Math.min.apply(null, xArr),
60
- maxX: Math.max.apply(null, xArr),
61
- minY: Math.min.apply(null, yArr),
62
- maxY: Math.max.apply(null, yArr),
63
- };
64
- }
65
-
66
- function intersectBBox(box1: BBox, box2: BBox) {
67
- return !(box2.minX > box1.maxX || box2.maxX < box1.minX || box2.minY > box1.maxY || box2.maxY < box1.minY);
68
- }
69
-
70
- export function isPolygonsIntersect(points1, points2) {
71
- // 空数组,或者一个点返回 false
72
- if (points1.length < 2 || points2.length < 2) {
73
- return false;
74
- }
75
-
76
- const bbox1 = getBBox(points1);
77
- const bbox2 = getBBox(points2);
78
- // 判定包围盒是否相交,比判定点是否在多边形内要快的多,可以筛选掉大多数情况
79
- if (!intersectBBox(bbox1, bbox2)) {
80
- return false;
81
- }
82
-
83
- // 判定点是否在多边形内部,一旦有一个点在另一个多边形内,则返回
84
- let hasOneIn = points2.some((point) => isPointInPolygon(points1, point[0], point[1]));
85
- if (hasOneIn) return true;
86
-
87
- // 两个多边形都需要判定
88
- hasOneIn = points1.some((point) => isPointInPolygon(points2, point[0], point[1]));
89
- if (hasOneIn) return true;
90
-
91
- const lines1 = parseToLines(points1);
92
- const lines2 = parseToLines(points2);
93
-
94
- return lines2.some((line) => lineIntersectPolygon(lines1, line));
95
- }
@@ -1,5 +0,0 @@
1
- const p2s = /,?([a-z]),?/gi;
2
-
3
- export function parsePathArray(path: any[]): string {
4
- return path.join(',').replace(p2s, '$1');
5
- }
@@ -1,62 +0,0 @@
1
- const SPACES = '\\s';
2
- const PATH_COMMAND = new RegExp(
3
- '([a-z])[' + SPACES + ',]*((-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?[' + SPACES + ']*,?[' + SPACES + ']*)+)',
4
- 'ig',
5
- );
6
- const PATH_VALUES = new RegExp('(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)[' + SPACES + ']*,?[' + SPACES + ']*', 'ig');
7
-
8
- // Parses given path string into an array of arrays of path segments
9
- export function parsePathString(pathString: string | any[]) {
10
- if (typeof pathString === 'string') {
11
- if (pathString) {
12
- const paramCounts = {
13
- a: 7,
14
- c: 6,
15
- o: 2,
16
- h: 1,
17
- l: 2,
18
- m: 2,
19
- r: 4,
20
- q: 4,
21
- s: 4,
22
- t: 2,
23
- v: 1,
24
- u: 3,
25
- z: 0,
26
- };
27
- const data = [];
28
-
29
- pathString.replace(PATH_COMMAND, function (a, b, c) {
30
- const params = [];
31
- let name = b.toLowerCase();
32
- c.replace(PATH_VALUES, function (a, b) {
33
- b && params.push(+b);
34
- });
35
- if (name === 'm' && params.length > 2) {
36
- data.push([b].concat(params.splice(0, 2)));
37
- name = 'l';
38
- b = b === 'm' ? 'l' : 'L';
39
- }
40
- if (name === 'o' && params.length === 1) {
41
- data.push([b, params[0]]);
42
- }
43
- if (name === 'r') {
44
- data.push([b].concat(params));
45
- } else {
46
- while (params.length >= paramCounts[name]) {
47
- data.push([b].concat(params.splice(0, paramCounts[name])));
48
- if (!paramCounts[name]) {
49
- break;
50
- }
51
- }
52
- }
53
- return '';
54
- });
55
- return data;
56
- } else {
57
- return null;
58
- }
59
- } else if (Array.isArray(pathString)) {
60
- return pathString;
61
- }
62
- }
@@ -1,34 +0,0 @@
1
- const regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/gi;
2
- const regexDot = /[^\s,]+/gi;
3
-
4
- export function parsePath(p: string): string[] {
5
- let path = p || ([] as string | string[]);
6
- if (Array.isArray(path)) {
7
- return path;
8
- }
9
-
10
- if (typeof path === 'string') {
11
- path = path.match(regexTags);
12
- path.forEach((item, index) => {
13
- // @ts-ignore
14
- item = item.match(regexDot);
15
- if (item[0].length > 1) {
16
- const tag = item[0].charAt(0);
17
- // @ts-ignore
18
- item.splice(1, 0, item[0].substr(1));
19
- // @ts-ignore
20
- item[0] = tag;
21
- }
22
- // @ts-ignore
23
- item.forEach(function (sub, i) {
24
- if (!isNaN(sub)) {
25
- // @ts-ignore
26
- item[i] = +sub;
27
- }
28
- });
29
- // @ts-ignore
30
- path[index] = item;
31
- });
32
- return path;
33
- }
34
- }
@@ -1,132 +0,0 @@
1
- import { parsePathString } from './parse-path-string';
2
-
3
- const REGEX_MD = /[a-z]/;
4
-
5
- function toSymmetry(p, c) {
6
- // 点对称
7
- return [c[0] + (c[0] - p[0]), c[1] + (c[1] - p[1])];
8
- }
9
-
10
- export function path2Absolute(pathString: string) {
11
- const pathArray = parsePathString(pathString);
12
-
13
- if (!pathArray || !pathArray.length) {
14
- return [['M', 0, 0]];
15
- }
16
- let needProcess = false; // 如果存在小写的命令或者 V,H,T,S 则需要处理
17
- for (let i = 0; i < pathArray.length; i++) {
18
- const cmd = pathArray[i][0];
19
- // 如果存在相对位置的命令,则中断返回
20
- if (REGEX_MD.test(cmd) || ['V', 'H', 'T', 'S'].indexOf(cmd) >= 0) {
21
- needProcess = true;
22
- break;
23
- }
24
- }
25
- // 如果不存在相对命令,则直接返回
26
- // 如果在业务上都写绝对路径,这种方式最快,仅做了一次检测
27
- if (!needProcess) {
28
- return pathArray;
29
- }
30
-
31
- const res = [];
32
- let x = 0;
33
- let y = 0;
34
- let mx = 0;
35
- let my = 0;
36
- let start = 0;
37
- const first = pathArray[0];
38
- if (first[0] === 'M' || first[0] === 'm') {
39
- x = +first[1];
40
- y = +first[2];
41
- mx = x;
42
- my = y;
43
- start++;
44
- res[0] = ['M', x, y];
45
- }
46
-
47
- for (let i = start, ii = pathArray.length; i < ii; i++) {
48
- const pa = pathArray[i];
49
- const preParams = res[i - 1]; // 取前一个已经处理后的节点,否则会出现问题
50
- let r = [];
51
- const cmd = pa[0];
52
- const upCmd = cmd.toUpperCase();
53
- if (cmd !== upCmd) {
54
- r[0] = upCmd;
55
- switch (upCmd) {
56
- case 'A':
57
- r[1] = pa[1];
58
- r[2] = pa[2];
59
- r[3] = pa[3];
60
- r[4] = pa[4];
61
- r[5] = pa[5];
62
- r[6] = +pa[6] + x;
63
- r[7] = +pa[7] + y;
64
- break;
65
- case 'V':
66
- r[1] = +pa[1] + y;
67
- break;
68
- case 'H':
69
- r[1] = +pa[1] + x;
70
- break;
71
- case 'M':
72
- mx = +pa[1] + x;
73
- my = +pa[2] + y;
74
- r[1] = mx;
75
- r[2] = my;
76
- break; // for lint
77
- default:
78
- for (let j = 1, jj = pa.length; j < jj; j++) {
79
- r[j] = +pa[j] + (j % 2 ? x : y);
80
- }
81
- }
82
- } else {
83
- // 如果本来已经大写,则不处理
84
- r = pathArray[i];
85
- }
86
- // 需要在外面统一做,同时处理 V,H,S,T 等特殊指令
87
- switch (upCmd) {
88
- case 'Z':
89
- x = +mx;
90
- y = +my;
91
- break;
92
- case 'H':
93
- x = r[1];
94
- r = ['L', x, y];
95
- break;
96
- case 'V':
97
- y = r[1];
98
- r = ['L', x, y];
99
- break;
100
- case 'T':
101
- x = r[1];
102
- y = r[2];
103
- // 以 x, y 为中心的,上一个控制点的对称点
104
- // 需要假设上一个节点的命令为 Q
105
- const symetricT = toSymmetry([preParams[1], preParams[2]], [preParams[3], preParams[4]]);
106
- r = ['Q', symetricT[0], symetricT[1], x, y];
107
- break;
108
- case 'S':
109
- x = r[r.length - 2];
110
- y = r[r.length - 1];
111
- // 以 x,y 为中心,取上一个控制点,
112
- // 需要假设上一个线段为 C 或者 S
113
- const length = preParams.length;
114
- const symetricS = toSymmetry(
115
- [preParams[length - 4], preParams[length - 3]],
116
- [preParams[length - 2], preParams[length - 1]],
117
- );
118
- r = ['C', symetricS[0], symetricS[1], r[1], r[2], x, y];
119
- break;
120
- case 'M':
121
- mx = r[r.length - 2];
122
- my = r[r.length - 1];
123
- break; // for lint
124
- default:
125
- x = r[r.length - 2];
126
- y = r[r.length - 1];
127
- }
128
- res.push(r);
129
- }
130
-
131
- return res;
132
- }
@@ -1,69 +0,0 @@
1
- import { path2Absolute } from './path-2-absolute';
2
- import { segmentToCubic } from './process/segment-2-cubic';
3
- import type { PathCommand, ProcessParams } from './types';
4
-
5
- export function path2Curve(path: PathCommand[] | string, needZCommandIndexes = false) {
6
- const pathArray = path2Absolute(path as string) as PathCommand[];
7
-
8
- const params: ProcessParams = {
9
- x1: 0,
10
- y1: 0,
11
- x2: 0,
12
- y2: 0,
13
- x: 0,
14
- y: 0,
15
- qx: null,
16
- qy: null,
17
- };
18
- const allPathCommands = [];
19
- let pathCommand = '';
20
- let ii = pathArray.length;
21
- let segment: PathCommand;
22
- let seglen: number;
23
- const zCommandIndexes: number[] = [];
24
-
25
- for (let i = 0; i < ii; i += 1) {
26
- if (pathArray[i]) [pathCommand] = pathArray[i];
27
-
28
- allPathCommands[i] = pathCommand;
29
- pathArray[i] = segmentToCubic(pathArray[i], params);
30
-
31
- fixArc(pathArray, allPathCommands, i);
32
- ii = pathArray.length; // solves curveArrays ending in Z
33
-
34
- // keep Z command account for lineJoin
35
- // @see https://github.com/antvis/util/issues/68
36
- if (pathCommand === 'Z') {
37
- zCommandIndexes.push(i);
38
- }
39
-
40
- segment = pathArray[i];
41
- seglen = segment.length;
42
-
43
- params.x1 = +segment[seglen - 2];
44
- params.y1 = +segment[seglen - 1];
45
- params.x2 = +segment[seglen - 4] || params.x1;
46
- params.y2 = +segment[seglen - 3] || params.y1;
47
- }
48
- if (needZCommandIndexes) {
49
- return [pathArray, zCommandIndexes];
50
- } else {
51
- return pathArray;
52
- }
53
- }
54
-
55
- function fixArc(pathArray: PathCommand[], allPathCommands: string[], i: number) {
56
- if (pathArray[i].length > 7) {
57
- pathArray[i].shift();
58
- const pi = pathArray[i];
59
- // const ni = i + 1;
60
- let ni = i;
61
- while (pi.length) {
62
- // if created multiple C:s, their original seg is saved
63
- allPathCommands[i] = 'A';
64
- // @ts-ignore
65
- pathArray.splice((ni += 1), 0, ['C'].concat(pi.splice(0, 6)));
66
- }
67
- pathArray.splice(i, 1);
68
- }
69
- }
@@ -1,142 +0,0 @@
1
- import { getArcParams, isSamePoint } from './get-arc-params';
2
- import { parsePath } from './parse-path';
3
-
4
- // 点对称
5
- function toSymmetry(point, center) {
6
- return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
7
- }
8
-
9
- export function path2Segments(path) {
10
- path = parsePath(path);
11
- const segments = [];
12
- let currentPoint = null; // 当前图形
13
- let nextParams = null; // 下一节点的 path 参数
14
- let startMovePoint = null; // 开始 M 的点,可能会有多个
15
- let lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
16
- const count = path.length;
17
- for (let i = 0; i < count; i++) {
18
- const params = path[i];
19
- nextParams = path[i + 1];
20
- const command = params[0];
21
- // 数学定义上的参数,便于后面的计算
22
- const segment = {
23
- command,
24
- prePoint: currentPoint,
25
- params,
26
- startTangent: null,
27
- endTangent: null,
28
- };
29
- switch (command) {
30
- case 'M':
31
- startMovePoint = [params[1], params[2]];
32
- lastStartMovePointIndex = i;
33
- break;
34
- case 'A':
35
- const arcParams = getArcParams(currentPoint, params);
36
- segment['arcParams'] = arcParams;
37
- break;
38
- default:
39
- break;
40
- }
41
- if (command === 'Z') {
42
- // 有了 Z 后,当前节点从开始 M 的点开始
43
- currentPoint = startMovePoint;
44
- // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
45
- nextParams = path[lastStartMovePointIndex + 1];
46
- } else {
47
- const len = params.length;
48
- currentPoint = [params[len - 2], params[len - 1]];
49
- }
50
- if (nextParams && nextParams[0] === 'Z') {
51
- // 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
52
- nextParams = path[lastStartMovePointIndex];
53
- if (segments[lastStartMovePointIndex]) {
54
- // 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
55
- segments[lastStartMovePointIndex].prePoint = currentPoint;
56
- }
57
- }
58
- segment['currentPoint'] = currentPoint;
59
- // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
60
- if (
61
- segments[lastStartMovePointIndex] &&
62
- isSamePoint(currentPoint, segments[lastStartMovePointIndex].currentPoint)
63
- ) {
64
- segments[lastStartMovePointIndex].prePoint = segment.prePoint;
65
- }
66
- const nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
67
- segment['nextPoint'] = nextPoint;
68
- // Add startTangent and endTangent
69
- const { prePoint } = segment;
70
- if (['L', 'H', 'V'].includes(command)) {
71
- segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
72
- segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
73
- } else if (command === 'Q') {
74
- // 二次贝塞尔曲线只有一个控制点
75
- const cp = [params[1], params[2]];
76
- // 二次贝塞尔曲线的终点为 currentPoint
77
- segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
78
- segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
79
- } else if (command === 'T') {
80
- const preSegment = segments[i - 1];
81
- const cp = toSymmetry(preSegment.currentPoint, prePoint);
82
- if (preSegment.command === 'Q') {
83
- segment.command = 'Q';
84
- segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
85
- segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
86
- } else {
87
- segment.command = 'TL';
88
- segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
89
- segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
90
- }
91
- } else if (command === 'C') {
92
- // 三次贝塞尔曲线有两个控制点
93
- const cp1 = [params[1], params[2]];
94
- const cp2 = [params[3], params[4]];
95
- segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
96
- segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
97
-
98
- // horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
99
- if (segment.startTangent[0] === 0 && segment.startTangent[1] === 0) {
100
- segment.startTangent = [cp1[0] - cp2[0], cp1[1] - cp2[1]];
101
- }
102
- if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
103
- segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
104
- }
105
- } else if (command === 'S') {
106
- const preSegment = segments[i - 1];
107
- const cp1 = toSymmetry(preSegment.currentPoint, prePoint);
108
- const cp2 = [params[1], params[2]];
109
- if (preSegment.command === 'C') {
110
- segment.command = 'C'; // 将 S 命令变换为 C 命令
111
- segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
112
- segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
113
- } else {
114
- segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
115
- segment.startTangent = [prePoint[0] - cp2[0], prePoint[1] - cp2[1]];
116
- segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
117
- }
118
- } else if (command === 'A') {
119
- let d = 0.001;
120
- const {
121
- cx = 0,
122
- cy = 0,
123
- rx = 0,
124
- ry = 0,
125
- sweepFlag = 0,
126
- startAngle = 0,
127
- endAngle = 0,
128
- } = segment['arcParams'] || {};
129
- if (sweepFlag === 0) {
130
- d *= -1;
131
- }
132
- const dx1 = rx * Math.cos(startAngle - d) + cx;
133
- const dy1 = ry * Math.sin(startAngle - d) + cy;
134
- segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
135
- const dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
136
- const dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
137
- segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
138
- }
139
- segments.push(segment);
140
- }
141
- return segments;
142
- }