@linkiez/dxf-renew 5.3.1

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 (447) hide show
  1. package/.eslintignore +17 -0
  2. package/.eslintrc.json +61 -0
  3. package/.gitattributes +4 -0
  4. package/.github/instructions/project-en_US.instructions.md +352 -0
  5. package/.github/workflows/release.yml +110 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +1 -0
  8. package/.prettierignore +1 -0
  9. package/.prettierrc.json +6 -0
  10. package/.releaserc.json +76 -0
  11. package/.travis.yml +6 -0
  12. package/.yarn/install-state.gz +0 -0
  13. package/.yarnrc.yml +1 -0
  14. package/CHANGELOG.md +134 -0
  15. package/CONTRIBUTING.md +271 -0
  16. package/LICENSE +21 -0
  17. package/PLAN.md +517 -0
  18. package/README.md +306 -0
  19. package/build.mjs +66 -0
  20. package/commitlint.config.js +25 -0
  21. package/dist/dxf.js +7234 -0
  22. package/docs/CODE_PATTERNS.md +182 -0
  23. package/docs/DIMENSION_SUMMARY.md +248 -0
  24. package/docs/DIMENSION_SUMMARY.pt-BR.md +248 -0
  25. package/docs/IMPLEMENTED-2D-ENTITIES.md +54 -0
  26. package/docs/IMPLEMENTED-2D-ENTITIES.pt-BR.md +54 -0
  27. package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.md +241 -0
  28. package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.pt-BR.md +169 -0
  29. package/docs/autocad_2012_pdf_dxf-reference_enu.md +8272 -0
  30. package/examples/dxf.html +36 -0
  31. package/examples/example.es5.js +30 -0
  32. package/examples/example.es6.js +30 -0
  33. package/examples/text-dimension-viewer.html +133 -0
  34. package/lib/Helper.cjs +89 -0
  35. package/lib/Helper.cjs.map +7 -0
  36. package/lib/Helper.js +59 -0
  37. package/lib/Helper.js.map +7 -0
  38. package/lib/applyTransforms.cjs +59 -0
  39. package/lib/applyTransforms.cjs.map +7 -0
  40. package/lib/applyTransforms.js +39 -0
  41. package/lib/applyTransforms.js.map +7 -0
  42. package/lib/cli.cjs +53 -0
  43. package/lib/cli.cjs.map +7 -0
  44. package/lib/cli.js +29 -0
  45. package/lib/cli.js.map +7 -0
  46. package/lib/config.cjs +30 -0
  47. package/lib/config.cjs.map +7 -0
  48. package/lib/config.js +10 -0
  49. package/lib/config.js.map +7 -0
  50. package/lib/constants.cjs +39 -0
  51. package/lib/constants.cjs.map +7 -0
  52. package/lib/constants.js +15 -0
  53. package/lib/constants.js.map +7 -0
  54. package/lib/denormalise.cjs +148 -0
  55. package/lib/denormalise.cjs.map +7 -0
  56. package/lib/denormalise.js +118 -0
  57. package/lib/denormalise.js.map +7 -0
  58. package/lib/dimensionToSVG.cjs +307 -0
  59. package/lib/dimensionToSVG.cjs.map +7 -0
  60. package/lib/dimensionToSVG.js +273 -0
  61. package/lib/dimensionToSVG.js.map +7 -0
  62. package/lib/entityToPolyline.cjs +248 -0
  63. package/lib/entityToPolyline.cjs.map +7 -0
  64. package/lib/entityToPolyline.js +213 -0
  65. package/lib/entityToPolyline.js.map +7 -0
  66. package/lib/getRGBForEntity.cjs +53 -0
  67. package/lib/getRGBForEntity.cjs.map +7 -0
  68. package/lib/getRGBForEntity.js +23 -0
  69. package/lib/getRGBForEntity.js.map +7 -0
  70. package/lib/groupEntitiesByLayer.cjs +34 -0
  71. package/lib/groupEntitiesByLayer.cjs.map +7 -0
  72. package/lib/groupEntitiesByLayer.js +14 -0
  73. package/lib/groupEntitiesByLayer.js.map +7 -0
  74. package/lib/handlers/blocks.cjs +93 -0
  75. package/lib/handlers/blocks.cjs.map +7 -0
  76. package/lib/handlers/blocks.js +63 -0
  77. package/lib/handlers/blocks.js.map +7 -0
  78. package/lib/handlers/entities.cjs +118 -0
  79. package/lib/handlers/entities.cjs.map +7 -0
  80. package/lib/handlers/entities.js +88 -0
  81. package/lib/handlers/entities.js.map +7 -0
  82. package/lib/handlers/entity/arc.cjs +82 -0
  83. package/lib/handlers/entity/arc.cjs.map +7 -0
  84. package/lib/handlers/entity/arc.js +47 -0
  85. package/lib/handlers/entity/arc.js.map +7 -0
  86. package/lib/handlers/entity/attdef.cjs +318 -0
  87. package/lib/handlers/entity/attdef.cjs.map +7 -0
  88. package/lib/handlers/entity/attdef.js +282 -0
  89. package/lib/handlers/entity/attdef.js.map +7 -0
  90. package/lib/handlers/entity/attrib.cjs +52 -0
  91. package/lib/handlers/entity/attrib.cjs.map +7 -0
  92. package/lib/handlers/entity/attrib.js +27 -0
  93. package/lib/handlers/entity/attrib.js.map +7 -0
  94. package/lib/handlers/entity/circle.cjs +73 -0
  95. package/lib/handlers/entity/circle.cjs.map +7 -0
  96. package/lib/handlers/entity/circle.js +38 -0
  97. package/lib/handlers/entity/circle.js.map +7 -0
  98. package/lib/handlers/entity/common.cjs +83 -0
  99. package/lib/handlers/entity/common.cjs.map +7 -0
  100. package/lib/handlers/entity/common.js +63 -0
  101. package/lib/handlers/entity/common.js.map +7 -0
  102. package/lib/handlers/entity/dimension.cjs +203 -0
  103. package/lib/handlers/entity/dimension.cjs.map +7 -0
  104. package/lib/handlers/entity/dimension.js +168 -0
  105. package/lib/handlers/entity/dimension.js.map +7 -0
  106. package/lib/handlers/entity/ellipse.cjs +88 -0
  107. package/lib/handlers/entity/ellipse.cjs.map +7 -0
  108. package/lib/handlers/entity/ellipse.js +53 -0
  109. package/lib/handlers/entity/ellipse.js.map +7 -0
  110. package/lib/handlers/entity/hatch.cjs +470 -0
  111. package/lib/handlers/entity/hatch.cjs.map +7 -0
  112. package/lib/handlers/entity/hatch.js +435 -0
  113. package/lib/handlers/entity/hatch.js.map +7 -0
  114. package/lib/handlers/entity/insert.cjs +106 -0
  115. package/lib/handlers/entity/insert.cjs.map +7 -0
  116. package/lib/handlers/entity/insert.js +71 -0
  117. package/lib/handlers/entity/insert.js.map +7 -0
  118. package/lib/handlers/entity/line.cjs +84 -0
  119. package/lib/handlers/entity/line.cjs.map +7 -0
  120. package/lib/handlers/entity/line.js +49 -0
  121. package/lib/handlers/entity/line.js.map +7 -0
  122. package/lib/handlers/entity/lwpolyline.cjs +82 -0
  123. package/lib/handlers/entity/lwpolyline.cjs.map +7 -0
  124. package/lib/handlers/entity/lwpolyline.js +47 -0
  125. package/lib/handlers/entity/lwpolyline.js.map +7 -0
  126. package/lib/handlers/entity/mtext.cjs +121 -0
  127. package/lib/handlers/entity/mtext.cjs.map +7 -0
  128. package/lib/handlers/entity/mtext.js +85 -0
  129. package/lib/handlers/entity/mtext.js.map +7 -0
  130. package/lib/handlers/entity/ole2Frame.cjs +98 -0
  131. package/lib/handlers/entity/ole2Frame.cjs.map +7 -0
  132. package/lib/handlers/entity/ole2Frame.js +63 -0
  133. package/lib/handlers/entity/ole2Frame.js.map +7 -0
  134. package/lib/handlers/entity/point.cjs +73 -0
  135. package/lib/handlers/entity/point.cjs.map +7 -0
  136. package/lib/handlers/entity/point.js +38 -0
  137. package/lib/handlers/entity/point.js.map +7 -0
  138. package/lib/handlers/entity/polyline.cjs +70 -0
  139. package/lib/handlers/entity/polyline.cjs.map +7 -0
  140. package/lib/handlers/entity/polyline.js +35 -0
  141. package/lib/handlers/entity/polyline.js.map +7 -0
  142. package/lib/handlers/entity/solid.cjs +101 -0
  143. package/lib/handlers/entity/solid.cjs.map +7 -0
  144. package/lib/handlers/entity/solid.js +66 -0
  145. package/lib/handlers/entity/solid.js.map +7 -0
  146. package/lib/handlers/entity/spline.cjs +109 -0
  147. package/lib/handlers/entity/spline.cjs.map +7 -0
  148. package/lib/handlers/entity/spline.js +74 -0
  149. package/lib/handlers/entity/spline.js.map +7 -0
  150. package/lib/handlers/entity/text.cjs +85 -0
  151. package/lib/handlers/entity/text.cjs.map +7 -0
  152. package/lib/handlers/entity/text.js +49 -0
  153. package/lib/handlers/entity/text.js.map +7 -0
  154. package/lib/handlers/entity/threeDFace.cjs +98 -0
  155. package/lib/handlers/entity/threeDFace.cjs.map +7 -0
  156. package/lib/handlers/entity/threeDFace.js +63 -0
  157. package/lib/handlers/entity/threeDFace.js.map +7 -0
  158. package/lib/handlers/entity/vertex.cjs +78 -0
  159. package/lib/handlers/entity/vertex.cjs.map +7 -0
  160. package/lib/handlers/entity/vertex.js +53 -0
  161. package/lib/handlers/entity/vertex.js.map +7 -0
  162. package/lib/handlers/entity/viewport.cjs +153 -0
  163. package/lib/handlers/entity/viewport.cjs.map +7 -0
  164. package/lib/handlers/entity/viewport.js +118 -0
  165. package/lib/handlers/entity/viewport.js.map +7 -0
  166. package/lib/handlers/header.cjs +92 -0
  167. package/lib/handlers/header.cjs.map +7 -0
  168. package/lib/handlers/header.js +72 -0
  169. package/lib/handlers/header.js.map +7 -0
  170. package/lib/handlers/objects.cjs +170 -0
  171. package/lib/handlers/objects.cjs.map +7 -0
  172. package/lib/handlers/objects.js +150 -0
  173. package/lib/handlers/objects.js.map +7 -0
  174. package/lib/handlers/tables.cjs +587 -0
  175. package/lib/handlers/tables.cjs.map +7 -0
  176. package/lib/handlers/tables.js +557 -0
  177. package/lib/handlers/tables.js.map +7 -0
  178. package/lib/index.cjs +60 -0
  179. package/lib/index.cjs.map +7 -0
  180. package/lib/index.js +19 -0
  181. package/lib/index.js.map +7 -0
  182. package/lib/parseString.cjs +118 -0
  183. package/lib/parseString.cjs.map +7 -0
  184. package/lib/parseString.js +88 -0
  185. package/lib/parseString.js.map +7 -0
  186. package/lib/toPolylines.cjs +69 -0
  187. package/lib/toPolylines.cjs.map +7 -0
  188. package/lib/toPolylines.js +39 -0
  189. package/lib/toPolylines.js.map +7 -0
  190. package/lib/toSVG.cjs +395 -0
  191. package/lib/toSVG.cjs.map +7 -0
  192. package/lib/toSVG.js +361 -0
  193. package/lib/toSVG.js.map +7 -0
  194. package/lib/types/arc-entity.cjs +17 -0
  195. package/lib/types/arc-entity.cjs.map +7 -0
  196. package/lib/types/arc-entity.js +1 -0
  197. package/lib/types/arc-entity.js.map +7 -0
  198. package/lib/types/base-entity.cjs +17 -0
  199. package/lib/types/base-entity.cjs.map +7 -0
  200. package/lib/types/base-entity.js +1 -0
  201. package/lib/types/base-entity.js.map +7 -0
  202. package/lib/types/circle-entity.cjs +17 -0
  203. package/lib/types/circle-entity.cjs.map +7 -0
  204. package/lib/types/circle-entity.js +1 -0
  205. package/lib/types/circle-entity.js.map +7 -0
  206. package/lib/types/common.cjs +17 -0
  207. package/lib/types/common.cjs.map +7 -0
  208. package/lib/types/common.js +1 -0
  209. package/lib/types/common.js.map +7 -0
  210. package/lib/types/dimension-entity.cjs +17 -0
  211. package/lib/types/dimension-entity.cjs.map +7 -0
  212. package/lib/types/dimension-entity.js +1 -0
  213. package/lib/types/dimension-entity.js.map +7 -0
  214. package/lib/types/dxf.cjs +17 -0
  215. package/lib/types/dxf.cjs.map +7 -0
  216. package/lib/types/dxf.js +1 -0
  217. package/lib/types/dxf.js.map +7 -0
  218. package/lib/types/ellipse-entity.cjs +17 -0
  219. package/lib/types/ellipse-entity.cjs.map +7 -0
  220. package/lib/types/ellipse-entity.js +1 -0
  221. package/lib/types/ellipse-entity.js.map +7 -0
  222. package/lib/types/entity.cjs +17 -0
  223. package/lib/types/entity.cjs.map +7 -0
  224. package/lib/types/entity.js +1 -0
  225. package/lib/types/entity.js.map +7 -0
  226. package/lib/types/handler-internal.cjs +17 -0
  227. package/lib/types/handler-internal.cjs.map +7 -0
  228. package/lib/types/handler-internal.js +1 -0
  229. package/lib/types/handler-internal.js.map +7 -0
  230. package/lib/types/handler.cjs +17 -0
  231. package/lib/types/handler.cjs.map +7 -0
  232. package/lib/types/handler.js +1 -0
  233. package/lib/types/handler.js.map +7 -0
  234. package/lib/types/hatch-entity.cjs +17 -0
  235. package/lib/types/hatch-entity.cjs.map +7 -0
  236. package/lib/types/hatch-entity.js +1 -0
  237. package/lib/types/hatch-entity.js.map +7 -0
  238. package/lib/types/helper.cjs +17 -0
  239. package/lib/types/helper.cjs.map +7 -0
  240. package/lib/types/helper.js +1 -0
  241. package/lib/types/helper.js.map +7 -0
  242. package/lib/types/index.cjs +77 -0
  243. package/lib/types/index.cjs.map +7 -0
  244. package/lib/types/index.js +29 -0
  245. package/lib/types/index.js.map +7 -0
  246. package/lib/types/insert-entity.cjs +17 -0
  247. package/lib/types/insert-entity.cjs.map +7 -0
  248. package/lib/types/insert-entity.js +1 -0
  249. package/lib/types/insert-entity.js.map +7 -0
  250. package/lib/types/layer-groups.cjs +17 -0
  251. package/lib/types/layer-groups.cjs.map +7 -0
  252. package/lib/types/layer-groups.js +1 -0
  253. package/lib/types/layer-groups.js.map +7 -0
  254. package/lib/types/line-entity.cjs +17 -0
  255. package/lib/types/line-entity.cjs.map +7 -0
  256. package/lib/types/line-entity.js +1 -0
  257. package/lib/types/line-entity.js.map +7 -0
  258. package/lib/types/mtext-entity.cjs +17 -0
  259. package/lib/types/mtext-entity.cjs.map +7 -0
  260. package/lib/types/mtext-entity.js +1 -0
  261. package/lib/types/mtext-entity.js.map +7 -0
  262. package/lib/types/ole2frame-entity.cjs +17 -0
  263. package/lib/types/ole2frame-entity.cjs.map +7 -0
  264. package/lib/types/ole2frame-entity.js +1 -0
  265. package/lib/types/ole2frame-entity.js.map +7 -0
  266. package/lib/types/options.cjs +17 -0
  267. package/lib/types/options.cjs.map +7 -0
  268. package/lib/types/options.js +1 -0
  269. package/lib/types/options.js.map +7 -0
  270. package/lib/types/point-entity.cjs +17 -0
  271. package/lib/types/point-entity.cjs.map +7 -0
  272. package/lib/types/point-entity.js +1 -0
  273. package/lib/types/point-entity.js.map +7 -0
  274. package/lib/types/polyline-entity.cjs +17 -0
  275. package/lib/types/polyline-entity.cjs.map +7 -0
  276. package/lib/types/polyline-entity.js +1 -0
  277. package/lib/types/polyline-entity.js.map +7 -0
  278. package/lib/types/polylines.cjs +17 -0
  279. package/lib/types/polylines.cjs.map +7 -0
  280. package/lib/types/polylines.js +1 -0
  281. package/lib/types/polylines.js.map +7 -0
  282. package/lib/types/solid-entity.cjs +17 -0
  283. package/lib/types/solid-entity.cjs.map +7 -0
  284. package/lib/types/solid-entity.js +1 -0
  285. package/lib/types/solid-entity.js.map +7 -0
  286. package/lib/types/spline-entity.cjs +17 -0
  287. package/lib/types/spline-entity.cjs.map +7 -0
  288. package/lib/types/spline-entity.js +1 -0
  289. package/lib/types/spline-entity.js.map +7 -0
  290. package/lib/types/svg.cjs +17 -0
  291. package/lib/types/svg.cjs.map +7 -0
  292. package/lib/types/svg.js +1 -0
  293. package/lib/types/svg.js.map +7 -0
  294. package/lib/types/tables.cjs +17 -0
  295. package/lib/types/tables.cjs.map +7 -0
  296. package/lib/types/tables.js +1 -0
  297. package/lib/types/tables.js.map +7 -0
  298. package/lib/types/text-entity.cjs +17 -0
  299. package/lib/types/text-entity.cjs.map +7 -0
  300. package/lib/types/text-entity.js +1 -0
  301. package/lib/types/text-entity.js.map +7 -0
  302. package/lib/types/util-types.cjs +17 -0
  303. package/lib/types/util-types.cjs.map +7 -0
  304. package/lib/types/util-types.js +1 -0
  305. package/lib/types/util-types.js.map +7 -0
  306. package/lib/types/vecks.d.cjs +2 -0
  307. package/lib/types/vecks.d.cjs.map +7 -0
  308. package/lib/types/vecks.d.js +1 -0
  309. package/lib/types/vecks.d.js.map +7 -0
  310. package/lib/types/viewport-entity.cjs +17 -0
  311. package/lib/types/viewport-entity.cjs.map +7 -0
  312. package/lib/types/viewport-entity.js +1 -0
  313. package/lib/types/viewport-entity.js.map +7 -0
  314. package/lib/types.cjs +23 -0
  315. package/lib/types.cjs.map +7 -0
  316. package/lib/types.js +2 -0
  317. package/lib/types.js.map +7 -0
  318. package/lib/util/bSpline.cjs +95 -0
  319. package/lib/util/bSpline.cjs.map +7 -0
  320. package/lib/util/bSpline.js +65 -0
  321. package/lib/util/bSpline.js.map +7 -0
  322. package/lib/util/colors.cjs +283 -0
  323. package/lib/util/colors.cjs.map +7 -0
  324. package/lib/util/colors.js +263 -0
  325. package/lib/util/colors.js.map +7 -0
  326. package/lib/util/createArcForLWPolyline.cjs +84 -0
  327. package/lib/util/createArcForLWPolyline.cjs.map +7 -0
  328. package/lib/util/createArcForLWPolyline.js +64 -0
  329. package/lib/util/createArcForLWPolyline.js.map +7 -0
  330. package/lib/util/dxfColorToRGB.cjs +115 -0
  331. package/lib/util/dxfColorToRGB.cjs.map +7 -0
  332. package/lib/util/dxfColorToRGB.js +90 -0
  333. package/lib/util/dxfColorToRGB.js.map +7 -0
  334. package/lib/util/insertKnot.cjs +77 -0
  335. package/lib/util/insertKnot.cjs.map +7 -0
  336. package/lib/util/insertKnot.js +57 -0
  337. package/lib/util/insertKnot.js.map +7 -0
  338. package/lib/util/logger.cjs +53 -0
  339. package/lib/util/logger.cjs.map +7 -0
  340. package/lib/util/logger.js +23 -0
  341. package/lib/util/logger.js.map +7 -0
  342. package/lib/util/rgbToColorAttribute.cjs +32 -0
  343. package/lib/util/rgbToColorAttribute.cjs.map +7 -0
  344. package/lib/util/rgbToColorAttribute.js +12 -0
  345. package/lib/util/rgbToColorAttribute.js.map +7 -0
  346. package/lib/util/rotate.cjs +30 -0
  347. package/lib/util/rotate.cjs.map +7 -0
  348. package/lib/util/rotate.js +10 -0
  349. package/lib/util/rotate.js.map +7 -0
  350. package/lib/util/round10.cjs +38 -0
  351. package/lib/util/round10.cjs.map +7 -0
  352. package/lib/util/round10.js +18 -0
  353. package/lib/util/round10.js.map +7 -0
  354. package/lib/util/toPiecewiseBezier.cjs +90 -0
  355. package/lib/util/toPiecewiseBezier.cjs.map +7 -0
  356. package/lib/util/toPiecewiseBezier.js +54 -0
  357. package/lib/util/toPiecewiseBezier.js.map +7 -0
  358. package/lib/util/transformBoundingBoxAndElement.cjs +80 -0
  359. package/lib/util/transformBoundingBoxAndElement.cjs.map +7 -0
  360. package/lib/util/transformBoundingBoxAndElement.js +60 -0
  361. package/lib/util/transformBoundingBoxAndElement.js.map +7 -0
  362. package/package.json +127 -0
  363. package/src/Helper.ts +71 -0
  364. package/src/applyTransforms.ts +54 -0
  365. package/src/cli.ts +41 -0
  366. package/src/config.ts +10 -0
  367. package/src/constants.ts +14 -0
  368. package/src/denormalise.ts +153 -0
  369. package/src/dimensionToSVG.ts +427 -0
  370. package/src/entityToPolyline.ts +338 -0
  371. package/src/getRGBForEntity.ts +28 -0
  372. package/src/groupEntitiesByLayer.ts +14 -0
  373. package/src/handlers/blocks.ts +65 -0
  374. package/src/handlers/entities.ts +111 -0
  375. package/src/handlers/entity/arc.ts +61 -0
  376. package/src/handlers/entity/attdef.ts +284 -0
  377. package/src/handlers/entity/attrib.ts +29 -0
  378. package/src/handlers/entity/circle.ts +47 -0
  379. package/src/handlers/entity/common.ts +79 -0
  380. package/src/handlers/entity/dimension.ts +217 -0
  381. package/src/handlers/entity/ellipse.ts +55 -0
  382. package/src/handlers/entity/hatch.ts +471 -0
  383. package/src/handlers/entity/insert.ts +73 -0
  384. package/src/handlers/entity/line.ts +56 -0
  385. package/src/handlers/entity/lwpolyline.ts +54 -0
  386. package/src/handlers/entity/mtext.ts +150 -0
  387. package/src/handlers/entity/ole2Frame.ts +64 -0
  388. package/src/handlers/entity/point.ts +47 -0
  389. package/src/handlers/entity/polyline.ts +49 -0
  390. package/src/handlers/entity/solid.ts +73 -0
  391. package/src/handlers/entity/spline.ts +103 -0
  392. package/src/handlers/entity/text.ts +83 -0
  393. package/src/handlers/entity/threeDFace.ts +69 -0
  394. package/src/handlers/entity/vertex.ts +55 -0
  395. package/src/handlers/entity/viewport.ts +119 -0
  396. package/src/handlers/header.ts +73 -0
  397. package/src/handlers/objects.ts +152 -0
  398. package/src/handlers/tables.ts +581 -0
  399. package/src/index.ts +19 -0
  400. package/src/parseString.ts +97 -0
  401. package/src/toPolylines.ts +47 -0
  402. package/src/toSVG.ts +518 -0
  403. package/src/types/README.md +91 -0
  404. package/src/types/arc-entity.ts +10 -0
  405. package/src/types/base-entity.ts +25 -0
  406. package/src/types/circle-entity.ts +8 -0
  407. package/src/types/common.ts +37 -0
  408. package/src/types/dimension-entity.ts +23 -0
  409. package/src/types/dxf.ts +64 -0
  410. package/src/types/ellipse-entity.ts +13 -0
  411. package/src/types/entity.ts +32 -0
  412. package/src/types/handler-internal.ts +51 -0
  413. package/src/types/handler.ts +10 -0
  414. package/src/types/hatch-entity.ts +127 -0
  415. package/src/types/helper.ts +12 -0
  416. package/src/types/index.ts +53 -0
  417. package/src/types/insert-entity.ts +19 -0
  418. package/src/types/layer-groups.ts +8 -0
  419. package/src/types/line-entity.ts +10 -0
  420. package/src/types/mtext-entity.ts +35 -0
  421. package/src/types/ole2frame-entity.ts +35 -0
  422. package/src/types/options.ts +17 -0
  423. package/src/types/point-entity.ts +7 -0
  424. package/src/types/polyline-entity.ts +20 -0
  425. package/src/types/polylines.ts +22 -0
  426. package/src/types/solid-entity.ts +9 -0
  427. package/src/types/spline-entity.ts +12 -0
  428. package/src/types/svg.ts +31 -0
  429. package/src/types/tables.ts +414 -0
  430. package/src/types/text-entity.ts +23 -0
  431. package/src/types/util-types.ts +27 -0
  432. package/src/types/vecks.d.ts +29 -0
  433. package/src/types/viewport-entity.ts +81 -0
  434. package/src/types.ts +5 -0
  435. package/src/util/bSpline.ts +97 -0
  436. package/src/util/colors.ts +266 -0
  437. package/src/util/createArcForLWPolyline.ts +93 -0
  438. package/src/util/diagram.png +0 -0
  439. package/src/util/dxfColorToRGB.ts +106 -0
  440. package/src/util/insertKnot.ts +69 -0
  441. package/src/util/logger.ts +23 -0
  442. package/src/util/rgbToColorAttribute.ts +14 -0
  443. package/src/util/rotate.ts +14 -0
  444. package/src/util/round10.ts +24 -0
  445. package/src/util/toPiecewiseBezier.ts +70 -0
  446. package/src/util/transformBoundingBoxAndElement.ts +74 -0
  447. package/tsconfig.json +34 -0
@@ -0,0 +1,266 @@
1
+ // DXF color table mapping color numbers to RGB values
2
+ import type { ColorRGB } from '../types/common'
3
+
4
+ // Re-export for backward compatibility
5
+ export type { ColorRGB } from '../types/common'
6
+
7
+ const colors: ColorRGB[] = [
8
+ [0, 0, 0],
9
+ [255, 0, 0],
10
+ [255, 255, 0],
11
+ [0, 255, 0],
12
+ [0, 255, 255],
13
+ [0, 0, 255],
14
+ [255, 0, 255],
15
+ [255, 255, 255],
16
+ [65, 65, 65],
17
+ [128, 128, 128],
18
+ [255, 0, 0],
19
+ [255, 170, 170],
20
+ [189, 0, 0],
21
+ [189, 126, 126],
22
+ [129, 0, 0],
23
+ [129, 86, 86],
24
+ [104, 0, 0],
25
+ [104, 69, 69],
26
+ [79, 0, 0],
27
+ [79, 53, 53],
28
+ [255, 63, 0],
29
+ [255, 191, 170],
30
+ [189, 46, 0],
31
+ [189, 141, 126],
32
+ [129, 31, 0],
33
+ [129, 96, 86],
34
+ [104, 25, 0],
35
+ [104, 78, 69],
36
+ [79, 19, 0],
37
+ [79, 59, 53],
38
+ [255, 127, 0],
39
+ [255, 212, 170],
40
+ [189, 94, 0],
41
+ [189, 157, 126],
42
+ [129, 64, 0],
43
+ [129, 107, 86],
44
+ [104, 52, 0],
45
+ [104, 86, 69],
46
+ [79, 39, 0],
47
+ [79, 66, 53],
48
+ [255, 191, 0],
49
+ [255, 234, 170],
50
+ [189, 141, 0],
51
+ [189, 173, 126],
52
+ [129, 96, 0],
53
+ [129, 118, 86],
54
+ [104, 78, 0],
55
+ [104, 95, 69],
56
+ [79, 59, 0],
57
+ [79, 73, 53],
58
+ [255, 255, 0],
59
+ [255, 255, 170],
60
+ [189, 189, 0],
61
+ [189, 189, 126],
62
+ [129, 129, 0],
63
+ [129, 129, 86],
64
+ [104, 104, 0],
65
+ [104, 104, 69],
66
+ [79, 79, 0],
67
+ [79, 79, 53],
68
+ [191, 255, 0],
69
+ [234, 255, 170],
70
+ [141, 189, 0],
71
+ [173, 189, 126],
72
+ [96, 129, 0],
73
+ [118, 129, 86],
74
+ [78, 104, 0],
75
+ [95, 104, 69],
76
+ [59, 79, 0],
77
+ [73, 79, 53],
78
+ [127, 255, 0],
79
+ [212, 255, 170],
80
+ [94, 189, 0],
81
+ [157, 189, 126],
82
+ [64, 129, 0],
83
+ [107, 129, 86],
84
+ [52, 104, 0],
85
+ [86, 104, 69],
86
+ [39, 79, 0],
87
+ [66, 79, 53],
88
+ [63, 255, 0],
89
+ [191, 255, 170],
90
+ [46, 189, 0],
91
+ [141, 189, 126],
92
+ [31, 129, 0],
93
+ [96, 129, 86],
94
+ [25, 104, 0],
95
+ [78, 104, 69],
96
+ [19, 79, 0],
97
+ [59, 79, 53],
98
+ [0, 255, 0],
99
+ [170, 255, 170],
100
+ [0, 189, 0],
101
+ [126, 189, 126],
102
+ [0, 129, 0],
103
+ [86, 129, 86],
104
+ [0, 104, 0],
105
+ [69, 104, 69],
106
+ [0, 79, 0],
107
+ [53, 79, 53],
108
+ [0, 255, 63],
109
+ [170, 255, 191],
110
+ [0, 189, 46],
111
+ [126, 189, 141],
112
+ [0, 129, 31],
113
+ [86, 129, 96],
114
+ [0, 104, 25],
115
+ [69, 104, 78],
116
+ [0, 79, 19],
117
+ [53, 79, 59],
118
+ [0, 255, 127],
119
+ [170, 255, 212],
120
+ [0, 189, 94],
121
+ [126, 189, 157],
122
+ [0, 129, 64],
123
+ [86, 129, 107],
124
+ [0, 104, 52],
125
+ [69, 104, 86],
126
+ [0, 79, 39],
127
+ [53, 79, 66],
128
+ [0, 255, 191],
129
+ [170, 255, 234],
130
+ [0, 189, 141],
131
+ [126, 189, 173],
132
+ [0, 129, 96],
133
+ [86, 129, 118],
134
+ [0, 104, 78],
135
+ [69, 104, 95],
136
+ [0, 79, 59],
137
+ [53, 79, 73],
138
+ [0, 255, 255],
139
+ [170, 255, 255],
140
+ [0, 189, 189],
141
+ [126, 189, 189],
142
+ [0, 129, 129],
143
+ [86, 129, 129],
144
+ [0, 104, 104],
145
+ [69, 104, 104],
146
+ [0, 79, 79],
147
+ [53, 79, 79],
148
+ [0, 191, 255],
149
+ [170, 234, 255],
150
+ [0, 141, 189],
151
+ [126, 173, 189],
152
+ [0, 96, 129],
153
+ [86, 118, 129],
154
+ [0, 78, 104],
155
+ [69, 95, 104],
156
+ [0, 59, 79],
157
+ [53, 73, 79],
158
+ [0, 127, 255],
159
+ [170, 212, 255],
160
+ [0, 94, 189],
161
+ [126, 157, 189],
162
+ [0, 64, 129],
163
+ [86, 107, 129],
164
+ [0, 52, 104],
165
+ [69, 86, 104],
166
+ [0, 39, 79],
167
+ [53, 66, 79],
168
+ [0, 63, 255],
169
+ [170, 191, 255],
170
+ [0, 46, 189],
171
+ [126, 141, 189],
172
+ [0, 31, 129],
173
+ [86, 96, 129],
174
+ [0, 25, 104],
175
+ [69, 78, 104],
176
+ [0, 19, 79],
177
+ [53, 59, 79],
178
+ [0, 0, 255],
179
+ [170, 170, 255],
180
+ [0, 0, 189],
181
+ [126, 126, 189],
182
+ [0, 0, 129],
183
+ [86, 86, 129],
184
+ [0, 0, 104],
185
+ [69, 69, 104],
186
+ [0, 0, 79],
187
+ [53, 53, 79],
188
+ [63, 0, 255],
189
+ [191, 170, 255],
190
+ [46, 0, 189],
191
+ [141, 126, 189],
192
+ [31, 0, 129],
193
+ [96, 86, 129],
194
+ [25, 0, 104],
195
+ [78, 69, 104],
196
+ [19, 0, 79],
197
+ [59, 53, 79],
198
+ [127, 0, 255],
199
+ [212, 170, 255],
200
+ [94, 0, 189],
201
+ [157, 126, 189],
202
+ [64, 0, 129],
203
+ [107, 86, 129],
204
+ [52, 0, 104],
205
+ [86, 69, 104],
206
+ [39, 0, 79],
207
+ [66, 53, 79],
208
+ [191, 0, 255],
209
+ [234, 170, 255],
210
+ [141, 0, 189],
211
+ [173, 126, 189],
212
+ [96, 0, 129],
213
+ [118, 86, 129],
214
+ [78, 0, 104],
215
+ [95, 69, 104],
216
+ [59, 0, 79],
217
+ [73, 53, 79],
218
+ [255, 0, 255],
219
+ [255, 170, 255],
220
+ [189, 0, 189],
221
+ [189, 126, 189],
222
+ [129, 0, 129],
223
+ [129, 86, 129],
224
+ [104, 0, 104],
225
+ [104, 69, 104],
226
+ [79, 0, 79],
227
+ [79, 53, 79],
228
+ [255, 0, 191],
229
+ [255, 170, 234],
230
+ [189, 0, 141],
231
+ [189, 126, 173],
232
+ [129, 0, 96],
233
+ [129, 86, 118],
234
+ [104, 0, 78],
235
+ [104, 69, 95],
236
+ [79, 0, 59],
237
+ [79, 53, 73],
238
+ [255, 0, 127],
239
+ [255, 170, 212],
240
+ [189, 0, 94],
241
+ [189, 126, 157],
242
+ [129, 0, 64],
243
+ [129, 86, 107],
244
+ [104, 0, 52],
245
+ [104, 69, 86],
246
+ [79, 0, 39],
247
+ [79, 53, 66],
248
+ [255, 0, 63],
249
+ [255, 170, 191],
250
+ [189, 0, 46],
251
+ [189, 126, 141],
252
+ [129, 0, 31],
253
+ [129, 86, 96],
254
+ [104, 0, 25],
255
+ [104, 69, 78],
256
+ [79, 0, 19],
257
+ [79, 53, 59],
258
+ [51, 51, 51],
259
+ [80, 80, 80],
260
+ [105, 105, 105],
261
+ [130, 130, 130],
262
+ [190, 190, 190],
263
+ [255, 255, 255],
264
+ ]
265
+
266
+ export default colors
@@ -0,0 +1,93 @@
1
+ import { V2 } from 'vecks'
2
+
3
+ type Point = [number, number]
4
+
5
+ /**
6
+ * Create the arcs point for a LWPOLYLINE. The start and end are excluded
7
+ *
8
+ * See diagram.png in this directory for description of points and angles used.
9
+ */
10
+ export default function createArcForLWPolyline(
11
+ from: Point,
12
+ to: Point,
13
+ bulge: number,
14
+ resolution?: number
15
+ ): Point[] {
16
+ // Resolution in degrees
17
+ if (!resolution) {
18
+ resolution = 5
19
+ }
20
+
21
+ // If the bulge is < 0, the arc goes clockwise. So we simply
22
+ // reverse a and b and invert sign
23
+ // Bulge = tan(theta/4)
24
+ let theta: number
25
+ let a: V2
26
+ let b: V2
27
+
28
+ if (bulge < 0) {
29
+ theta = Math.atan(-bulge) * 4
30
+ a = new V2(from[0], from[1])
31
+ b = new V2(to[0], to[1])
32
+ } else {
33
+ // Default is counter-clockwise
34
+ theta = Math.atan(bulge) * 4
35
+ a = new V2(to[0], to[1])
36
+ b = new V2(from[0], from[1])
37
+ }
38
+
39
+ const ab = b.sub(a)
40
+ const lengthAB = ab.length()
41
+ const c = a.add(ab.multiply(0.5))
42
+
43
+ // Distance from center of arc to line between form and to points
44
+ const lengthCD = Math.abs(lengthAB / 2 / Math.tan(theta / 2))
45
+ const normAB = ab.norm()
46
+
47
+ let d: V2
48
+ if (theta < Math.PI) {
49
+ const normDC = new V2(
50
+ normAB.x * Math.cos(Math.PI / 2) - normAB.y * Math.sin(Math.PI / 2),
51
+ normAB.y * Math.cos(Math.PI / 2) + normAB.x * Math.sin(Math.PI / 2),
52
+ )
53
+ // D is the center of the arc
54
+ d = c.add(normDC.multiply(-lengthCD))
55
+ } else {
56
+ const normCD = new V2(
57
+ normAB.x * Math.cos(Math.PI / 2) - normAB.y * Math.sin(Math.PI / 2),
58
+ normAB.y * Math.cos(Math.PI / 2) + normAB.x * Math.sin(Math.PI / 2),
59
+ )
60
+ // D is the center of the arc
61
+ d = c.add(normCD.multiply(lengthCD))
62
+ }
63
+
64
+ // Add points between start start and eng angle relative
65
+ // to the center point
66
+ const startAngle = (Math.atan2(b.y - d.y, b.x - d.x) / Math.PI) * 180
67
+ let endAngle = (Math.atan2(a.y - d.y, a.x - d.x) / Math.PI) * 180
68
+ if (endAngle < startAngle) {
69
+ endAngle += 360
70
+ }
71
+ const r = b.sub(d).length()
72
+
73
+ const startInter =
74
+ Math.floor(startAngle / resolution) * resolution + resolution
75
+ const endInter = Math.ceil(endAngle / resolution) * resolution - resolution
76
+
77
+ const points: V2[] = []
78
+ for (let i = startInter; i <= endInter; i += resolution) {
79
+ points.push(
80
+ d.add(
81
+ new V2(
82
+ Math.cos((i / 180) * Math.PI) * r,
83
+ Math.sin((i / 180) * Math.PI) * r,
84
+ ),
85
+ ),
86
+ )
87
+ }
88
+ // Maintain the right ordering to join the from and to points
89
+ if (bulge < 0) {
90
+ points.reverse()
91
+ }
92
+ return points.map((p): Point => [p.x, p.y])
93
+ }
Binary file
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Convert DXF ACI (AutoCAD Color Index) to RGB color
3
+ * Based on AutoCAD's standard 256 color palette
4
+ */
5
+ export default function dxfColorToRGB(colorNumber: number): { r: number; g: number; b: number } {
6
+ // Standard AutoCAD Color Index (ACI) colors
7
+ const aciColors: Array<[number, number, number]> = [
8
+ [0, 0, 0], // 0 - ByBlock
9
+ [255, 0, 0], // 1 - Red
10
+ [255, 255, 0], // 2 - Yellow
11
+ [0, 255, 0], // 3 - Green
12
+ [0, 255, 255], // 4 - Cyan
13
+ [0, 0, 255], // 5 - Blue
14
+ [255, 0, 255], // 6 - Magenta
15
+ [255, 255, 255], // 7 - White/Black (depends on background)
16
+ [128, 128, 128], // 8 - Gray
17
+ [192, 192, 192], // 9 - Light Gray
18
+ ]
19
+
20
+ // Handle special cases
21
+ if (colorNumber === 0 || colorNumber === 256) {
22
+ // ByBlock or ByLayer - return black as default
23
+ return { r: 0, g: 0, b: 0 }
24
+ }
25
+
26
+ if (colorNumber === 7) {
27
+ // White/Black - return black for light backgrounds
28
+ return { r: 0, g: 0, b: 0 }
29
+ }
30
+
31
+ // Colors 1-9 are standard
32
+ if (colorNumber >= 1 && colorNumber <= 9) {
33
+ const [r, g, b] = aciColors[colorNumber]
34
+ return { r, g, b }
35
+ }
36
+
37
+ // Colors 10-249 follow a pattern
38
+ // Simplified approximation for extended colors
39
+ if (colorNumber >= 10 && colorNumber <= 249) {
40
+ const base = colorNumber - 10
41
+ const hue = (base % 10) * 36
42
+ const lightness = Math.floor(base / 10) * 10 + 50
43
+
44
+ // Convert HSL to RGB (simplified)
45
+ const c = (1 - Math.abs(2 * lightness / 100 - 1)) * 100
46
+ const x = c * (1 - Math.abs(((hue / 60) % 2) - 1))
47
+ const m = lightness - c / 2
48
+
49
+ let r = 0
50
+ let g = 0
51
+ let b = 0
52
+
53
+ if (hue < 60) {
54
+ r = c
55
+ g = x
56
+ } else if (hue < 120) {
57
+ r = x
58
+ g = c
59
+ } else if (hue < 180) {
60
+ g = c
61
+ b = x
62
+ } else if (hue < 240) {
63
+ g = x
64
+ b = c
65
+ } else if (hue < 300) {
66
+ r = x
67
+ b = c
68
+ } else {
69
+ r = c
70
+ b = x
71
+ }
72
+
73
+ return {
74
+ r: Math.round((r + m) * 2.55),
75
+ g: Math.round((g + m) * 2.55),
76
+ b: Math.round((b + m) * 2.55),
77
+ }
78
+ }
79
+
80
+ // Grayscale colors 250-255
81
+ if (colorNumber >= 250 && colorNumber <= 255) {
82
+ const gray = Math.round(((colorNumber - 250) / 5) * 255)
83
+ return { r: gray, g: gray, b: gray }
84
+ }
85
+
86
+ // Default to black for unknown colors
87
+ return { r: 0, g: 0, b: 0 }
88
+ }
89
+
90
+ /**
91
+ * Convert RGB object to SVG color string
92
+ */
93
+ export function rgbToSVGColor(rgb: { r: number; g: number; b: number }): string {
94
+ return `rgb(${rgb.r},${rgb.g},${rgb.b})`
95
+ }
96
+
97
+ /**
98
+ * Convert DXF color number directly to SVG color string
99
+ */
100
+ export function dxfColorToSVG(colorNumber: number | undefined): string {
101
+ if (colorNumber === undefined) {
102
+ return 'currentColor'
103
+ }
104
+ const rgb = dxfColorToRGB(colorNumber)
105
+ return rgbToSVGColor(rgb)
106
+ }
@@ -0,0 +1,69 @@
1
+ import type { InsertKnotResult, UtilPoint } from '../types/util-types'
2
+
3
+ /**
4
+ * Knot insertion is known as "Boehm's algorithm"
5
+ *
6
+ * https://math.stackexchange.com/questions/417859/convert-a-b-spline-into-bezier-curves
7
+ * code adapted from http://preserve.mactech.com/articles/develop/issue_25/schneider.html
8
+ */
9
+ export default function insertKnot(
10
+ k: number,
11
+ controlPoints: UtilPoint[],
12
+ knots: number[],
13
+ newKnot: number
14
+ ): InsertKnotResult {
15
+ const x = knots
16
+ const b = controlPoints
17
+ const n = controlPoints.length
18
+ let i = 0
19
+ let foundIndex = false
20
+ for (let j = 0; j < n + k; j++) {
21
+ if (newKnot > x[j] && newKnot <= x[j + 1]) {
22
+ i = j
23
+ foundIndex = true
24
+ break
25
+ }
26
+ }
27
+ if (!foundIndex) {
28
+ throw new Error('invalid new knot')
29
+ }
30
+
31
+ const xHat: number[] = []
32
+ for (let j = 0; j < n + k + 1; j++) {
33
+ if (j <= i) {
34
+ xHat[j] = x[j]
35
+ } else if (j === i + 1) {
36
+ xHat[j] = newKnot
37
+ } else {
38
+ xHat[j] = x[j - 1]
39
+ }
40
+ }
41
+
42
+ let alpha: number
43
+ const bHat: UtilPoint[] = []
44
+ for (let j = 0; j < n + 1; j++) {
45
+ if (j <= i - k + 1) {
46
+ alpha = 1
47
+ } else if (i - k + 2 <= j && j <= i) {
48
+ if (x[j + k - 1] - x[j] === 0) {
49
+ alpha = 0
50
+ } else {
51
+ alpha = (newKnot - x[j]) / (x[j + k - 1] - x[j])
52
+ }
53
+ } else {
54
+ alpha = 0
55
+ }
56
+
57
+ if (alpha === 0) {
58
+ bHat[j] = b[j - 1]
59
+ } else if (alpha === 1) {
60
+ bHat[j] = b[j]
61
+ } else {
62
+ bHat[j] = {
63
+ x: (1 - alpha) * b[j - 1].x + alpha * b[j].x,
64
+ y: (1 - alpha) * b[j - 1].y + alpha * b[j].y,
65
+ }
66
+ }
67
+ }
68
+ return { controlPoints: bHat, knots: xHat }
69
+ }
@@ -0,0 +1,23 @@
1
+ import config from '../config'
2
+
3
+ function info(...args: any[]): void {
4
+ if (config.verbose) {
5
+ console.info(...args)
6
+ }
7
+ }
8
+
9
+ function warn(...args: any[]): void {
10
+ if (config.verbose) {
11
+ console.warn(...args)
12
+ }
13
+ }
14
+
15
+ function error(...args: any[]): void {
16
+ console.error(...args)
17
+ }
18
+
19
+ export default {
20
+ info,
21
+ warn,
22
+ error,
23
+ }
@@ -0,0 +1,14 @@
1
+ import type { ColorRGB } from './colors'
2
+
3
+ /**
4
+ * Convert a ColorRGB tuple to a CSS string definition.
5
+ * Converts white lines to black as the default.
6
+ */
7
+ export default function rgbToColorAttribute(rgb: ColorRGB): string {
8
+ const [r, g, b] = rgb
9
+ if (r === 255 && g === 255 && b === 255) {
10
+ return 'rgb(0, 0, 0)'
11
+ } else {
12
+ return `rgb(${r}, ${g}, ${b})`
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import { Point2D } from '../types'
2
+
3
+ /**
4
+ * Rotate a point by the given angle.
5
+ *
6
+ * @param p the point
7
+ * @param angle the rotation angle in radians
8
+ */
9
+ export default function rotate(p: Point2D, angle: number): Point2D {
10
+ return {
11
+ x: p.x * Math.cos(angle) - p.y * Math.sin(angle),
12
+ y: p.y * Math.cos(angle) + p.x * Math.sin(angle),
13
+ }
14
+ }
@@ -0,0 +1,24 @@
1
+ // This is based on the example code found from:
2
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
3
+ // Example code on MDN is public domain or CC0 (your preference) or MIT depending when the
4
+ // example code was added:
5
+ // https://developer.mozilla.org/en-US/docs/MDN/About
6
+
7
+ export default function round10(value: number, exp?: number): number {
8
+ // If the exp is undefined or zero...
9
+ if (exp === undefined || +exp === 0) {
10
+ return Math.round(value)
11
+ }
12
+ const numValue = +value
13
+ const numExp = +exp
14
+ // If the value is not a number or the exp is not an integer...
15
+ if (Number.isNaN(numValue) || !(typeof numExp === 'number' && numExp % 1 === 0)) {
16
+ return Number.NaN
17
+ }
18
+ // Shift
19
+ let valueStr = numValue.toString().split('e')
20
+ const roundedValue = Math.round(+(valueStr[0] + 'e' + (valueStr[1] ? +valueStr[1] - numExp : -numExp)))
21
+ // Shift back
22
+ valueStr = roundedValue.toString().split('e')
23
+ return +(valueStr[0] + 'e' + (valueStr[1] ? +valueStr[1] + numExp : numExp))
24
+ }
@@ -0,0 +1,70 @@
1
+ import type { BezierResult, UtilPoint } from '../types/util-types'
2
+ import insertKnot from './insertKnot'
3
+
4
+ /**
5
+ * For a pinned spline, the knots have to be repeated k times
6
+ * (where k is the order), at both the beginning and the end
7
+ */
8
+ export const checkPinned = (k: number, knots: number[]): void => {
9
+ // Pinned at the start
10
+ for (let i = 1; i < k; ++i) {
11
+ if (knots[i] !== knots[0]) {
12
+ throw new Error(`not pinned. order: ${k} knots: ${knots}`)
13
+ }
14
+ }
15
+ // Pinned at the end
16
+ for (let i = knots.length - 2; i > knots.length - k - 1; --i) {
17
+ if (knots[i] !== knots[knots.length - 1]) {
18
+ throw new Error(`not pinned. order: ${k} knots: ${knots}`)
19
+ }
20
+ }
21
+ }
22
+
23
+ export const multiplicity = (knots: number[], index: number): number => {
24
+ let m = 1
25
+ for (let i = index + 1; i < knots.length; ++i) {
26
+ if (knots[i] === knots[index]) {
27
+ ++m
28
+ } else {
29
+ break
30
+ }
31
+ }
32
+ return m
33
+ }
34
+
35
+ /**
36
+ * https://saccade.com/writing/graphics/KnotVectors.pdf
37
+ * A quadratic piecewise Bézier knot vector with seven control points
38
+ * will look like this [0 0 0 1 1 2 2 3 3 3]. In general, in a
39
+ * piecewise Bézier knot vector the first k knots are the same,
40
+ * then each subsequent group of k-1 knots is the same,
41
+ * until you get to the end.
42
+ */
43
+ export const computeInsertions = (k: number, knots: number[]): number[] => {
44
+ const inserts: number[] = []
45
+ let i = k
46
+ while (i < knots.length - k) {
47
+ const knot = knots[i]
48
+ const m = multiplicity(knots, i)
49
+ for (let j = 0; j < k - m - 1; ++j) {
50
+ inserts.push(knot)
51
+ }
52
+ i = i + m
53
+ }
54
+ return inserts
55
+ }
56
+
57
+ export default function toPiecewiseBezier(
58
+ k: number,
59
+ controlPoints: UtilPoint[],
60
+ knots: number[]
61
+ ): BezierResult {
62
+ checkPinned(k, knots)
63
+ const insertions = computeInsertions(k, knots)
64
+ return insertions.reduce(
65
+ (acc, tNew) => {
66
+ return insertKnot(k, acc.controlPoints, acc.knots, tNew)
67
+ },
68
+ { controlPoints, knots },
69
+ )
70
+ }