meerk40t 0.9.3001__py2.py3-none-any.whl → 0.9.7010__py2.py3-none-any.whl

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 (445) hide show
  1. meerk40t/__init__.py +1 -1
  2. meerk40t/balormk/balor_params.py +167 -167
  3. meerk40t/balormk/clone_loader.py +457 -457
  4. meerk40t/balormk/controller.py +1566 -1512
  5. meerk40t/balormk/cylindermod.py +64 -0
  6. meerk40t/balormk/device.py +966 -1959
  7. meerk40t/balormk/driver.py +778 -591
  8. meerk40t/balormk/galvo_commands.py +1195 -0
  9. meerk40t/balormk/gui/balorconfig.py +237 -111
  10. meerk40t/balormk/gui/balorcontroller.py +191 -184
  11. meerk40t/balormk/gui/baloroperationproperties.py +116 -115
  12. meerk40t/balormk/gui/corscene.py +845 -0
  13. meerk40t/balormk/gui/gui.py +179 -147
  14. meerk40t/balormk/livelightjob.py +466 -382
  15. meerk40t/balormk/mock_connection.py +131 -109
  16. meerk40t/balormk/plugin.py +133 -135
  17. meerk40t/balormk/usb_connection.py +306 -301
  18. meerk40t/camera/__init__.py +1 -1
  19. meerk40t/camera/camera.py +514 -397
  20. meerk40t/camera/gui/camerapanel.py +1241 -1095
  21. meerk40t/camera/gui/gui.py +58 -58
  22. meerk40t/camera/plugin.py +441 -399
  23. meerk40t/ch341/__init__.py +27 -27
  24. meerk40t/ch341/ch341device.py +628 -628
  25. meerk40t/ch341/libusb.py +595 -589
  26. meerk40t/ch341/mock.py +171 -171
  27. meerk40t/ch341/windriver.py +157 -157
  28. meerk40t/constants.py +13 -0
  29. meerk40t/core/__init__.py +1 -1
  30. meerk40t/core/bindalias.py +550 -539
  31. meerk40t/core/core.py +47 -47
  32. meerk40t/core/cutcode/cubiccut.py +73 -73
  33. meerk40t/core/cutcode/cutcode.py +315 -312
  34. meerk40t/core/cutcode/cutgroup.py +141 -137
  35. meerk40t/core/cutcode/cutobject.py +192 -185
  36. meerk40t/core/cutcode/dwellcut.py +37 -37
  37. meerk40t/core/cutcode/gotocut.py +29 -29
  38. meerk40t/core/cutcode/homecut.py +29 -29
  39. meerk40t/core/cutcode/inputcut.py +34 -34
  40. meerk40t/core/cutcode/linecut.py +33 -33
  41. meerk40t/core/cutcode/outputcut.py +34 -34
  42. meerk40t/core/cutcode/plotcut.py +335 -335
  43. meerk40t/core/cutcode/quadcut.py +61 -61
  44. meerk40t/core/cutcode/rastercut.py +168 -148
  45. meerk40t/core/cutcode/waitcut.py +34 -34
  46. meerk40t/core/cutplan.py +1843 -1316
  47. meerk40t/core/drivers.py +330 -329
  48. meerk40t/core/elements/align.py +801 -669
  49. meerk40t/core/elements/branches.py +1844 -1507
  50. meerk40t/core/elements/clipboard.py +229 -219
  51. meerk40t/core/elements/element_treeops.py +4561 -2837
  52. meerk40t/core/elements/element_types.py +125 -105
  53. meerk40t/core/elements/elements.py +4329 -3617
  54. meerk40t/core/elements/files.py +117 -64
  55. meerk40t/core/elements/geometry.py +473 -224
  56. meerk40t/core/elements/grid.py +467 -316
  57. meerk40t/core/elements/materials.py +158 -94
  58. meerk40t/core/elements/notes.py +50 -38
  59. meerk40t/core/elements/offset_clpr.py +933 -912
  60. meerk40t/core/elements/offset_mk.py +963 -955
  61. meerk40t/core/elements/penbox.py +339 -267
  62. meerk40t/core/elements/placements.py +300 -83
  63. meerk40t/core/elements/render.py +785 -687
  64. meerk40t/core/elements/shapes.py +2618 -2092
  65. meerk40t/core/elements/trace.py +651 -563
  66. meerk40t/core/elements/tree_commands.py +415 -409
  67. meerk40t/core/elements/undo_redo.py +116 -58
  68. meerk40t/core/elements/wordlist.py +319 -200
  69. meerk40t/core/exceptions.py +9 -9
  70. meerk40t/core/laserjob.py +220 -220
  71. meerk40t/core/logging.py +63 -63
  72. meerk40t/core/node/blobnode.py +83 -86
  73. meerk40t/core/node/bootstrap.py +105 -103
  74. meerk40t/core/node/branch_elems.py +40 -31
  75. meerk40t/core/node/branch_ops.py +45 -38
  76. meerk40t/core/node/branch_regmark.py +48 -41
  77. meerk40t/core/node/cutnode.py +29 -32
  78. meerk40t/core/node/effect_hatch.py +375 -257
  79. meerk40t/core/node/effect_warp.py +398 -0
  80. meerk40t/core/node/effect_wobble.py +441 -309
  81. meerk40t/core/node/elem_ellipse.py +404 -309
  82. meerk40t/core/node/elem_image.py +1082 -801
  83. meerk40t/core/node/elem_line.py +358 -292
  84. meerk40t/core/node/elem_path.py +259 -201
  85. meerk40t/core/node/elem_point.py +129 -102
  86. meerk40t/core/node/elem_polyline.py +310 -246
  87. meerk40t/core/node/elem_rect.py +376 -286
  88. meerk40t/core/node/elem_text.py +445 -418
  89. meerk40t/core/node/filenode.py +59 -40
  90. meerk40t/core/node/groupnode.py +138 -74
  91. meerk40t/core/node/image_processed.py +777 -766
  92. meerk40t/core/node/image_raster.py +156 -113
  93. meerk40t/core/node/layernode.py +31 -31
  94. meerk40t/core/node/mixins.py +135 -107
  95. meerk40t/core/node/node.py +1427 -1304
  96. meerk40t/core/node/nutils.py +117 -114
  97. meerk40t/core/node/op_cut.py +462 -335
  98. meerk40t/core/node/op_dots.py +296 -251
  99. meerk40t/core/node/op_engrave.py +414 -311
  100. meerk40t/core/node/op_image.py +755 -369
  101. meerk40t/core/node/op_raster.py +787 -522
  102. meerk40t/core/node/place_current.py +37 -40
  103. meerk40t/core/node/place_point.py +329 -126
  104. meerk40t/core/node/refnode.py +58 -47
  105. meerk40t/core/node/rootnode.py +225 -219
  106. meerk40t/core/node/util_console.py +48 -48
  107. meerk40t/core/node/util_goto.py +84 -65
  108. meerk40t/core/node/util_home.py +61 -61
  109. meerk40t/core/node/util_input.py +102 -102
  110. meerk40t/core/node/util_output.py +102 -102
  111. meerk40t/core/node/util_wait.py +65 -65
  112. meerk40t/core/parameters.py +709 -707
  113. meerk40t/core/planner.py +875 -785
  114. meerk40t/core/plotplanner.py +656 -652
  115. meerk40t/core/space.py +120 -113
  116. meerk40t/core/spoolers.py +706 -705
  117. meerk40t/core/svg_io.py +1836 -1549
  118. meerk40t/core/treeop.py +534 -445
  119. meerk40t/core/undos.py +278 -124
  120. meerk40t/core/units.py +784 -680
  121. meerk40t/core/view.py +393 -322
  122. meerk40t/core/webhelp.py +62 -62
  123. meerk40t/core/wordlist.py +513 -504
  124. meerk40t/cylinder/cylinder.py +247 -0
  125. meerk40t/cylinder/gui/cylindersettings.py +41 -0
  126. meerk40t/cylinder/gui/gui.py +24 -0
  127. meerk40t/device/__init__.py +1 -1
  128. meerk40t/device/basedevice.py +322 -123
  129. meerk40t/device/devicechoices.py +50 -0
  130. meerk40t/device/dummydevice.py +163 -128
  131. meerk40t/device/gui/defaultactions.py +618 -602
  132. meerk40t/device/gui/effectspanel.py +114 -0
  133. meerk40t/device/gui/formatterpanel.py +253 -290
  134. meerk40t/device/gui/warningpanel.py +337 -260
  135. meerk40t/device/mixins.py +13 -13
  136. meerk40t/dxf/__init__.py +1 -1
  137. meerk40t/dxf/dxf_io.py +766 -554
  138. meerk40t/dxf/plugin.py +47 -35
  139. meerk40t/external_plugins.py +79 -79
  140. meerk40t/external_plugins_build.py +28 -28
  141. meerk40t/extra/cag.py +112 -116
  142. meerk40t/extra/coolant.py +403 -0
  143. meerk40t/extra/encode_detect.py +198 -0
  144. meerk40t/extra/ezd.py +1165 -1165
  145. meerk40t/extra/hershey.py +835 -340
  146. meerk40t/extra/imageactions.py +322 -316
  147. meerk40t/extra/inkscape.py +630 -622
  148. meerk40t/extra/lbrn.py +424 -424
  149. meerk40t/extra/outerworld.py +284 -0
  150. meerk40t/extra/param_functions.py +1542 -1556
  151. meerk40t/extra/potrace.py +257 -253
  152. meerk40t/extra/serial_exchange.py +118 -0
  153. meerk40t/extra/updater.py +602 -453
  154. meerk40t/extra/vectrace.py +147 -146
  155. meerk40t/extra/winsleep.py +83 -83
  156. meerk40t/extra/xcs_reader.py +597 -0
  157. meerk40t/fill/fills.py +781 -335
  158. meerk40t/fill/patternfill.py +1061 -1061
  159. meerk40t/fill/patterns.py +614 -567
  160. meerk40t/grbl/control.py +87 -87
  161. meerk40t/grbl/controller.py +990 -903
  162. meerk40t/grbl/device.py +1081 -768
  163. meerk40t/grbl/driver.py +989 -771
  164. meerk40t/grbl/emulator.py +532 -497
  165. meerk40t/grbl/gcodejob.py +783 -767
  166. meerk40t/grbl/gui/grblconfiguration.py +373 -298
  167. meerk40t/grbl/gui/grblcontroller.py +485 -271
  168. meerk40t/grbl/gui/grblhardwareconfig.py +269 -153
  169. meerk40t/grbl/gui/grbloperationconfig.py +105 -0
  170. meerk40t/grbl/gui/gui.py +147 -116
  171. meerk40t/grbl/interpreter.py +44 -44
  172. meerk40t/grbl/loader.py +22 -22
  173. meerk40t/grbl/mock_connection.py +56 -56
  174. meerk40t/grbl/plugin.py +294 -264
  175. meerk40t/grbl/serial_connection.py +93 -88
  176. meerk40t/grbl/tcp_connection.py +81 -79
  177. meerk40t/grbl/ws_connection.py +112 -0
  178. meerk40t/gui/__init__.py +1 -1
  179. meerk40t/gui/about.py +2042 -296
  180. meerk40t/gui/alignment.py +1644 -1608
  181. meerk40t/gui/autoexec.py +199 -0
  182. meerk40t/gui/basicops.py +791 -670
  183. meerk40t/gui/bufferview.py +77 -71
  184. meerk40t/gui/busy.py +170 -133
  185. meerk40t/gui/choicepropertypanel.py +1673 -1469
  186. meerk40t/gui/consolepanel.py +706 -542
  187. meerk40t/gui/devicepanel.py +687 -581
  188. meerk40t/gui/dialogoptions.py +110 -107
  189. meerk40t/gui/executejob.py +316 -306
  190. meerk40t/gui/fonts.py +90 -90
  191. meerk40t/gui/functionwrapper.py +252 -0
  192. meerk40t/gui/gui_mixins.py +729 -0
  193. meerk40t/gui/guicolors.py +205 -182
  194. meerk40t/gui/help_assets/help_assets.py +218 -201
  195. meerk40t/gui/helper.py +154 -0
  196. meerk40t/gui/hersheymanager.py +1430 -846
  197. meerk40t/gui/icons.py +3422 -2747
  198. meerk40t/gui/imagesplitter.py +555 -508
  199. meerk40t/gui/keymap.py +354 -344
  200. meerk40t/gui/laserpanel.py +892 -806
  201. meerk40t/gui/laserrender.py +1470 -1232
  202. meerk40t/gui/lasertoolpanel.py +805 -793
  203. meerk40t/gui/magnetoptions.py +436 -0
  204. meerk40t/gui/materialmanager.py +2917 -0
  205. meerk40t/gui/materialtest.py +1722 -1694
  206. meerk40t/gui/mkdebug.py +646 -359
  207. meerk40t/gui/mwindow.py +163 -140
  208. meerk40t/gui/navigationpanels.py +2605 -2467
  209. meerk40t/gui/notes.py +143 -142
  210. meerk40t/gui/opassignment.py +414 -410
  211. meerk40t/gui/operation_info.py +310 -299
  212. meerk40t/gui/plugin.py +494 -328
  213. meerk40t/gui/position.py +714 -669
  214. meerk40t/gui/preferences.py +901 -650
  215. meerk40t/gui/propertypanels/attributes.py +1461 -1131
  216. meerk40t/gui/propertypanels/blobproperty.py +117 -114
  217. meerk40t/gui/propertypanels/consoleproperty.py +83 -80
  218. meerk40t/gui/propertypanels/gotoproperty.py +77 -0
  219. meerk40t/gui/propertypanels/groupproperties.py +223 -217
  220. meerk40t/gui/propertypanels/hatchproperty.py +489 -469
  221. meerk40t/gui/propertypanels/imageproperty.py +2244 -1384
  222. meerk40t/gui/propertypanels/inputproperty.py +59 -58
  223. meerk40t/gui/propertypanels/opbranchproperties.py +82 -80
  224. meerk40t/gui/propertypanels/operationpropertymain.py +1890 -1638
  225. meerk40t/gui/propertypanels/outputproperty.py +59 -58
  226. meerk40t/gui/propertypanels/pathproperty.py +389 -380
  227. meerk40t/gui/propertypanels/placementproperty.py +1214 -383
  228. meerk40t/gui/propertypanels/pointproperty.py +140 -136
  229. meerk40t/gui/propertypanels/propertywindow.py +313 -181
  230. meerk40t/gui/propertypanels/rasterwizardpanels.py +996 -912
  231. meerk40t/gui/propertypanels/regbranchproperties.py +76 -0
  232. meerk40t/gui/propertypanels/textproperty.py +770 -755
  233. meerk40t/gui/propertypanels/waitproperty.py +56 -55
  234. meerk40t/gui/propertypanels/warpproperty.py +121 -0
  235. meerk40t/gui/propertypanels/wobbleproperty.py +255 -204
  236. meerk40t/gui/ribbon.py +2468 -2210
  237. meerk40t/gui/scene/scene.py +1100 -1051
  238. meerk40t/gui/scene/sceneconst.py +22 -22
  239. meerk40t/gui/scene/scenepanel.py +439 -349
  240. meerk40t/gui/scene/scenespacewidget.py +365 -365
  241. meerk40t/gui/scene/widget.py +518 -505
  242. meerk40t/gui/scenewidgets/affinemover.py +215 -215
  243. meerk40t/gui/scenewidgets/attractionwidget.py +315 -309
  244. meerk40t/gui/scenewidgets/bedwidget.py +120 -97
  245. meerk40t/gui/scenewidgets/elementswidget.py +137 -107
  246. meerk40t/gui/scenewidgets/gridwidget.py +785 -745
  247. meerk40t/gui/scenewidgets/guidewidget.py +765 -765
  248. meerk40t/gui/scenewidgets/laserpathwidget.py +66 -66
  249. meerk40t/gui/scenewidgets/machineoriginwidget.py +86 -86
  250. meerk40t/gui/scenewidgets/nodeselector.py +28 -28
  251. meerk40t/gui/scenewidgets/rectselectwidget.py +589 -346
  252. meerk40t/gui/scenewidgets/relocatewidget.py +33 -33
  253. meerk40t/gui/scenewidgets/reticlewidget.py +83 -83
  254. meerk40t/gui/scenewidgets/selectionwidget.py +2952 -2756
  255. meerk40t/gui/simpleui.py +357 -333
  256. meerk40t/gui/simulation.py +2431 -2094
  257. meerk40t/gui/snapoptions.py +208 -203
  258. meerk40t/gui/spoolerpanel.py +1227 -1180
  259. meerk40t/gui/statusbarwidgets/defaultoperations.py +480 -353
  260. meerk40t/gui/statusbarwidgets/infowidget.py +520 -483
  261. meerk40t/gui/statusbarwidgets/opassignwidget.py +356 -355
  262. meerk40t/gui/statusbarwidgets/selectionwidget.py +172 -171
  263. meerk40t/gui/statusbarwidgets/shapepropwidget.py +754 -236
  264. meerk40t/gui/statusbarwidgets/statusbar.py +272 -260
  265. meerk40t/gui/statusbarwidgets/statusbarwidget.py +268 -270
  266. meerk40t/gui/statusbarwidgets/strokewidget.py +267 -251
  267. meerk40t/gui/themes.py +200 -78
  268. meerk40t/gui/tips.py +591 -0
  269. meerk40t/gui/toolwidgets/circlebrush.py +35 -35
  270. meerk40t/gui/toolwidgets/toolcircle.py +248 -242
  271. meerk40t/gui/toolwidgets/toolcontainer.py +82 -77
  272. meerk40t/gui/toolwidgets/tooldraw.py +97 -90
  273. meerk40t/gui/toolwidgets/toolellipse.py +219 -212
  274. meerk40t/gui/toolwidgets/toolimagecut.py +25 -132
  275. meerk40t/gui/toolwidgets/toolline.py +39 -144
  276. meerk40t/gui/toolwidgets/toollinetext.py +79 -236
  277. meerk40t/gui/toolwidgets/toollinetext_inline.py +296 -0
  278. meerk40t/gui/toolwidgets/toolmeasure.py +160 -216
  279. meerk40t/gui/toolwidgets/toolnodeedit.py +2088 -2074
  280. meerk40t/gui/toolwidgets/toolnodemove.py +92 -94
  281. meerk40t/gui/toolwidgets/toolparameter.py +754 -668
  282. meerk40t/gui/toolwidgets/toolplacement.py +108 -108
  283. meerk40t/gui/toolwidgets/toolpoint.py +68 -59
  284. meerk40t/gui/toolwidgets/toolpointlistbuilder.py +294 -0
  285. meerk40t/gui/toolwidgets/toolpointmove.py +183 -0
  286. meerk40t/gui/toolwidgets/toolpolygon.py +288 -403
  287. meerk40t/gui/toolwidgets/toolpolyline.py +38 -196
  288. meerk40t/gui/toolwidgets/toolrect.py +211 -207
  289. meerk40t/gui/toolwidgets/toolrelocate.py +72 -72
  290. meerk40t/gui/toolwidgets/toolribbon.py +598 -113
  291. meerk40t/gui/toolwidgets/tooltabedit.py +546 -0
  292. meerk40t/gui/toolwidgets/tooltext.py +98 -89
  293. meerk40t/gui/toolwidgets/toolvector.py +213 -204
  294. meerk40t/gui/toolwidgets/toolwidget.py +39 -39
  295. meerk40t/gui/usbconnect.py +98 -91
  296. meerk40t/gui/utilitywidgets/buttonwidget.py +18 -18
  297. meerk40t/gui/utilitywidgets/checkboxwidget.py +90 -90
  298. meerk40t/gui/utilitywidgets/controlwidget.py +14 -14
  299. meerk40t/gui/utilitywidgets/cyclocycloidwidget.py +343 -340
  300. meerk40t/gui/utilitywidgets/debugwidgets.py +148 -0
  301. meerk40t/gui/utilitywidgets/handlewidget.py +27 -27
  302. meerk40t/gui/utilitywidgets/harmonograph.py +450 -447
  303. meerk40t/gui/utilitywidgets/openclosewidget.py +40 -40
  304. meerk40t/gui/utilitywidgets/rotationwidget.py +54 -54
  305. meerk40t/gui/utilitywidgets/scalewidget.py +75 -75
  306. meerk40t/gui/utilitywidgets/seekbarwidget.py +183 -183
  307. meerk40t/gui/utilitywidgets/togglewidget.py +142 -142
  308. meerk40t/gui/utilitywidgets/toolbarwidget.py +8 -8
  309. meerk40t/gui/wordlisteditor.py +985 -931
  310. meerk40t/gui/wxmeerk40t.py +1444 -1169
  311. meerk40t/gui/wxmmain.py +5578 -4112
  312. meerk40t/gui/wxmribbon.py +1591 -1076
  313. meerk40t/gui/wxmscene.py +1635 -1453
  314. meerk40t/gui/wxmtree.py +2410 -2089
  315. meerk40t/gui/wxutils.py +1769 -1099
  316. meerk40t/gui/zmatrix.py +102 -102
  317. meerk40t/image/__init__.py +1 -1
  318. meerk40t/image/dither.py +429 -0
  319. meerk40t/image/imagetools.py +2778 -2269
  320. meerk40t/internal_plugins.py +150 -130
  321. meerk40t/kernel/__init__.py +63 -12
  322. meerk40t/kernel/channel.py +259 -212
  323. meerk40t/kernel/context.py +538 -538
  324. meerk40t/kernel/exceptions.py +41 -41
  325. meerk40t/kernel/functions.py +463 -414
  326. meerk40t/kernel/jobs.py +100 -100
  327. meerk40t/kernel/kernel.py +3809 -3571
  328. meerk40t/kernel/lifecycles.py +71 -71
  329. meerk40t/kernel/module.py +49 -49
  330. meerk40t/kernel/service.py +147 -147
  331. meerk40t/kernel/settings.py +383 -343
  332. meerk40t/lihuiyu/controller.py +883 -876
  333. meerk40t/lihuiyu/device.py +1181 -1069
  334. meerk40t/lihuiyu/driver.py +1466 -1372
  335. meerk40t/lihuiyu/gui/gui.py +127 -106
  336. meerk40t/lihuiyu/gui/lhyaccelgui.py +377 -363
  337. meerk40t/lihuiyu/gui/lhycontrollergui.py +741 -651
  338. meerk40t/lihuiyu/gui/lhydrivergui.py +470 -446
  339. meerk40t/lihuiyu/gui/lhyoperationproperties.py +238 -237
  340. meerk40t/lihuiyu/gui/tcpcontroller.py +226 -190
  341. meerk40t/lihuiyu/interpreter.py +53 -53
  342. meerk40t/lihuiyu/laserspeed.py +450 -450
  343. meerk40t/lihuiyu/loader.py +90 -90
  344. meerk40t/lihuiyu/parser.py +404 -404
  345. meerk40t/lihuiyu/plugin.py +101 -102
  346. meerk40t/lihuiyu/tcp_connection.py +111 -109
  347. meerk40t/main.py +231 -165
  348. meerk40t/moshi/builder.py +788 -781
  349. meerk40t/moshi/controller.py +505 -499
  350. meerk40t/moshi/device.py +495 -442
  351. meerk40t/moshi/driver.py +862 -696
  352. meerk40t/moshi/gui/gui.py +78 -76
  353. meerk40t/moshi/gui/moshicontrollergui.py +538 -522
  354. meerk40t/moshi/gui/moshidrivergui.py +87 -75
  355. meerk40t/moshi/plugin.py +43 -43
  356. meerk40t/network/console_server.py +102 -57
  357. meerk40t/network/kernelserver.py +10 -9
  358. meerk40t/network/tcp_server.py +142 -140
  359. meerk40t/network/udp_server.py +103 -77
  360. meerk40t/network/web_server.py +390 -0
  361. meerk40t/newly/controller.py +1158 -1144
  362. meerk40t/newly/device.py +874 -732
  363. meerk40t/newly/driver.py +540 -412
  364. meerk40t/newly/gui/gui.py +219 -188
  365. meerk40t/newly/gui/newlyconfig.py +116 -101
  366. meerk40t/newly/gui/newlycontroller.py +193 -186
  367. meerk40t/newly/gui/operationproperties.py +51 -51
  368. meerk40t/newly/mock_connection.py +82 -82
  369. meerk40t/newly/newly_params.py +56 -56
  370. meerk40t/newly/plugin.py +1214 -1246
  371. meerk40t/newly/usb_connection.py +322 -322
  372. meerk40t/rotary/gui/gui.py +52 -46
  373. meerk40t/rotary/gui/rotarysettings.py +240 -232
  374. meerk40t/rotary/rotary.py +202 -98
  375. meerk40t/ruida/control.py +291 -91
  376. meerk40t/ruida/controller.py +138 -1088
  377. meerk40t/ruida/device.py +672 -231
  378. meerk40t/ruida/driver.py +534 -472
  379. meerk40t/ruida/emulator.py +1494 -1491
  380. meerk40t/ruida/exceptions.py +4 -4
  381. meerk40t/ruida/gui/gui.py +71 -76
  382. meerk40t/ruida/gui/ruidaconfig.py +239 -72
  383. meerk40t/ruida/gui/ruidacontroller.py +187 -184
  384. meerk40t/ruida/gui/ruidaoperationproperties.py +48 -47
  385. meerk40t/ruida/loader.py +54 -52
  386. meerk40t/ruida/mock_connection.py +57 -109
  387. meerk40t/ruida/plugin.py +124 -87
  388. meerk40t/ruida/rdjob.py +2084 -945
  389. meerk40t/ruida/serial_connection.py +116 -0
  390. meerk40t/ruida/tcp_connection.py +146 -0
  391. meerk40t/ruida/udp_connection.py +73 -0
  392. meerk40t/svgelements.py +9671 -9669
  393. meerk40t/tools/driver_to_path.py +584 -579
  394. meerk40t/tools/geomstr.py +5583 -4680
  395. meerk40t/tools/jhfparser.py +357 -292
  396. meerk40t/tools/kerftest.py +904 -890
  397. meerk40t/tools/livinghinges.py +1168 -1033
  398. meerk40t/tools/pathtools.py +987 -949
  399. meerk40t/tools/pmatrix.py +234 -0
  400. meerk40t/tools/pointfinder.py +942 -942
  401. meerk40t/tools/polybool.py +940 -940
  402. meerk40t/tools/rasterplotter.py +1660 -547
  403. meerk40t/tools/shxparser.py +989 -901
  404. meerk40t/tools/ttfparser.py +726 -446
  405. meerk40t/tools/zinglplotter.py +595 -593
  406. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/LICENSE +21 -21
  407. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/METADATA +150 -139
  408. meerk40t-0.9.7010.dist-info/RECORD +445 -0
  409. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/WHEEL +1 -1
  410. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/top_level.txt +0 -1
  411. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/zip-safe +1 -1
  412. meerk40t/balormk/elementlightjob.py +0 -159
  413. meerk40t-0.9.3001.dist-info/RECORD +0 -437
  414. test/bootstrap.py +0 -63
  415. test/test_cli.py +0 -12
  416. test/test_core_cutcode.py +0 -418
  417. test/test_core_elements.py +0 -144
  418. test/test_core_plotplanner.py +0 -397
  419. test/test_core_viewports.py +0 -312
  420. test/test_drivers_grbl.py +0 -108
  421. test/test_drivers_lihuiyu.py +0 -443
  422. test/test_drivers_newly.py +0 -113
  423. test/test_element_degenerate_points.py +0 -43
  424. test/test_elements_classify.py +0 -97
  425. test/test_elements_penbox.py +0 -22
  426. test/test_file_svg.py +0 -176
  427. test/test_fill.py +0 -155
  428. test/test_geomstr.py +0 -1523
  429. test/test_geomstr_nodes.py +0 -18
  430. test/test_imagetools_actualize.py +0 -306
  431. test/test_imagetools_wizard.py +0 -258
  432. test/test_kernel.py +0 -200
  433. test/test_laser_speeds.py +0 -3303
  434. test/test_length.py +0 -57
  435. test/test_lifecycle.py +0 -66
  436. test/test_operations.py +0 -251
  437. test/test_operations_hatch.py +0 -57
  438. test/test_ruida.py +0 -19
  439. test/test_spooler.py +0 -22
  440. test/test_tools_rasterplotter.py +0 -29
  441. test/test_wobble.py +0 -133
  442. test/test_zingl.py +0 -124
  443. {test → meerk40t/cylinder}/__init__.py +0 -0
  444. /meerk40t/{core/element_commands.py → cylinder/gui/__init__.py} +0 -0
  445. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7010.dist-info}/entry_points.txt +0 -0
meerk40t/core/units.py CHANGED
@@ -1,680 +1,784 @@
1
- """
2
- Device Specific Unit Conversion Objects
3
-
4
- This defines a Viewport which all .device services are expected to implement. This provides the core functionality for
5
- establishing the scene and mapping points from scene locations to device locations. This also provides functionality
6
- for converting different length or angle units into other length or angle units.
7
-
8
- The fundamental unit used for all the elements objects is that 1 inch is equal to 65535 native units called a Tat for
9
- Tiger and Tatarize. This is basically a solid middle ground for providing significant rendering detail while not
10
- overflowing the buffer in linux which starts react poorly for values greater than 16,777,216 (2^24). This should provide
11
- enough detail for even the smallest lensed galvo laser while also allowing us to define objects as large as a football
12
- stadium.
13
- """
14
-
15
-
16
- import re
17
- from copy import copy
18
- from math import tau
19
-
20
- from meerk40t.svgelements import Matrix
21
-
22
- PATTERN_FLOAT = r"[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?"
23
- REGEX_LENGTH = re.compile(r"(%s)\.?([A-Za-z%%]*)" % PATTERN_FLOAT)
24
- ERROR = 1e-11
25
- DEFAULT_PPI = 96.0
26
- NATIVE_UNIT_PER_INCH = 65535
27
-
28
- NM_PER_INCH = 25400000
29
- NM_PER_MIL = 25400
30
- NM_PER_NM = 1
31
- NM_PER_uM = 1000
32
- NM_PER_MM = 1000000
33
- NM_PER_CM = 10000000
34
- NM_PER_PIXEL = NM_PER_INCH / DEFAULT_PPI
35
-
36
- MIL_PER_INCH = 1000
37
- NM_PER_INCH = 2.54e7
38
- uM_PER_INCH = 25400
39
- MM_PER_INCH = 25.4
40
- CM_PER_INCH = 2.54
41
-
42
- PX_PER_INCH = DEFAULT_PPI
43
- PX_PER_MIL = DEFAULT_PPI / MIL_PER_INCH
44
- PX_PER_NM = DEFAULT_PPI / NM_PER_INCH
45
- PX_PER_uM = DEFAULT_PPI / uM_PER_INCH
46
- PX_PER_MM = DEFAULT_PPI / MM_PER_INCH
47
- PX_PER_CM = DEFAULT_PPI / CM_PER_INCH
48
- PX_PER_PIXEL = 1
49
-
50
-
51
- UNITS_PER_TAT = 1
52
- UNITS_PER_INCH = NATIVE_UNIT_PER_INCH
53
- UNITS_PER_MIL = NATIVE_UNIT_PER_INCH / MIL_PER_INCH
54
- UNITS_PER_uM = NATIVE_UNIT_PER_INCH / uM_PER_INCH
55
- UNITS_PER_MM = NATIVE_UNIT_PER_INCH / MM_PER_INCH
56
- UNITS_PER_CM = NATIVE_UNIT_PER_INCH / CM_PER_INCH
57
- UNITS_PER_NM = NATIVE_UNIT_PER_INCH / NM_PER_INCH
58
- UNITS_PER_PIXEL = NATIVE_UNIT_PER_INCH / DEFAULT_PPI
59
- UNITS_PER_POINT = UNITS_PER_PIXEL * 4.0 / 3.0
60
- PX_PER_UNIT = 1.0 / UNITS_PER_PIXEL
61
-
62
- UNITS_NANOMETER = 0
63
- UNITS_MM = 1
64
- UNITS_CM = 2
65
- UNITS_MILS = 3
66
- UNITS_INCH = 4
67
- UNITS_PERCENT = 100
68
-
69
-
70
- ACCEPTED_UNITS = (
71
- "",
72
- "cm",
73
- "mm",
74
- "in",
75
- "inch",
76
- "inches",
77
- "mil",
78
- "pt",
79
- "pc",
80
- "px",
81
- "%",
82
- "tat",
83
- )
84
-
85
-
86
- class Length:
87
- """
88
- Amounts are converted to UNITS.
89
- Initial unit is saved as preferred units.
90
- """
91
-
92
- units_per_spx = 50
93
-
94
- def __init__(
95
- self,
96
- *args,
97
- amount=None,
98
- relative_length=None,
99
- unitless=1.0,
100
- preferred_units=None,
101
- digits=None,
102
- ):
103
- self._digits = digits
104
- self._amount = amount
105
- if self._amount is None:
106
- if len(args) == 2:
107
- value = str(args[0]) + str(args[1])
108
- elif len(args) == 1:
109
- value = args[0]
110
- else:
111
- raise ValueError("Arguments not acceptable")
112
- s = str(value)
113
- match = REGEX_LENGTH.match(s)
114
- if not match:
115
- raise ValueError("Length was not parsable.")
116
- amount = float(match.group(1))
117
- units = match.group(2)
118
- if units == "inch" or units == "inches":
119
- units = "in"
120
- scale = 1.0
121
- if units == "":
122
- if unitless:
123
- scale = unitless
124
- elif units == "tat":
125
- scale = UNITS_PER_TAT
126
- elif units == "mm":
127
- scale = UNITS_PER_MM
128
- elif units == "cm":
129
- scale = UNITS_PER_CM
130
- elif units == "um":
131
- scale = UNITS_PER_uM
132
- elif units == "nm":
133
- scale = UNITS_PER_NM
134
- elif units == "in":
135
- scale = UNITS_PER_INCH
136
- elif units == "mil":
137
- scale = UNITS_PER_MIL
138
- elif units == "px":
139
- scale = UNITS_PER_PIXEL
140
- elif units == "pt":
141
- scale = UNITS_PER_POINT
142
- elif units == "spx":
143
- scale = self.units_per_spx
144
- elif units == "pc":
145
- scale = UNITS_PER_PIXEL * 16.0
146
- elif units == "%":
147
- if relative_length is not None:
148
- fraction = amount / 100.0
149
- if isinstance(relative_length, (str, Length)):
150
- relative_length = Length(
151
- relative_length, unitless=unitless
152
- ).units
153
- amount = relative_length
154
- scale = fraction
155
- units = ""
156
- else:
157
- raise ValueError("Percent without relative length is meaningless.")
158
- else:
159
- raise ValueError("Units was not recognized")
160
- self._amount = scale * amount
161
- if preferred_units is None:
162
- preferred_units = units
163
- else:
164
- # amount is only ever a number.
165
- if not isinstance(amount, (float, int)):
166
- raise ValueError("Amount must be an number.")
167
- if preferred_units is None:
168
- preferred_units = ""
169
- if preferred_units == "inch" or preferred_units == "inches":
170
- preferred_units = "in"
171
- self._preferred_units = preferred_units
172
-
173
- def __float__(self):
174
- return self._amount
175
-
176
- def __imul__(self, other):
177
- if isinstance(other, (int, float)):
178
- self._amount *= other
179
- return self
180
- if self._amount == 0.0:
181
- return 0.0
182
- raise ValueError
183
-
184
- def __iadd__(self, other):
185
- if not isinstance(other, Length):
186
- other = Length(other)
187
- self._amount += other._amount
188
- return self
189
-
190
- def __abs__(self):
191
- c = self.__copy__()
192
- c._amount = abs(c._amount)
193
- return c
194
-
195
- def __truediv__(self, other):
196
- if not isinstance(other, Length):
197
- other = Length(other)
198
- return self._amount / other._amount
199
-
200
- __floordiv__ = __truediv__
201
- __div__ = __truediv__
202
-
203
- def __lt__(self, other):
204
- return (self - other)._amount - ERROR < 0
205
-
206
- def __gt__(self, other):
207
- return (self - other)._amount + ERROR > 0
208
-
209
- def __le__(self, other):
210
- return (self - other)._amount - ERROR <= 0
211
-
212
- def __ge__(self, other):
213
- return (self - other)._amount + ERROR >= 0
214
-
215
- def __ne__(self, other):
216
- return not self.__eq__(other)
217
-
218
- def __add__(self, other):
219
- if isinstance(other, (str, float, int)):
220
- other = Length(other)
221
- c = self.__copy__()
222
- c += other
223
- return c
224
-
225
- __radd__ = __add__
226
-
227
- def __mul__(self, other):
228
- c = copy(self)
229
- c *= other
230
- return c
231
-
232
- def __rdiv__(self, other):
233
- c = copy(self)
234
- c *= 1.0 / other._amount
235
- return c
236
-
237
- def __neg__(self):
238
- s = self.__copy__()
239
- s._amount = -s._amount
240
- return s
241
-
242
- def __isub__(self, other):
243
- if not isinstance(other, Length):
244
- other = Length(other)
245
- self += -other
246
- return self
247
-
248
- def __sub__(self, other):
249
- s = self.__copy__()
250
- s -= other
251
- return s
252
-
253
- def __round__(self, ndigits=0):
254
- return round(self._amount, ndigits=ndigits)
255
-
256
- def __rsub__(self, other):
257
- if not isinstance(other, Length):
258
- other = Length(other)
259
- return (-self) + other
260
-
261
- def __copy__(self):
262
- return Length(
263
- None,
264
- amount=self._amount,
265
- preferred_units=self._preferred_units,
266
- digits=self._digits,
267
- )
268
-
269
- __rmul__ = __mul__
270
-
271
- def __repr__(self):
272
- c = self.__copy__()
273
- c._digits = None
274
- return c.preferred_length
275
-
276
- def __str__(self):
277
- return self.preferred_length
278
-
279
- def __eq__(self, other):
280
- if other is None:
281
- return False
282
- if isinstance(other, (int, float)):
283
- return self._amount == other
284
- if not isinstance(other, Length):
285
- try:
286
- other = Length(other)
287
- except ValueError:
288
- # Not a length, we do not equal this.
289
- return False
290
- return abs(self._amount - other._amount) <= ERROR
291
-
292
- @property
293
- def preferred(self):
294
- if self._preferred_units == "px":
295
- return self.pixels
296
- elif self._preferred_units == "in":
297
- return self.inches
298
- elif self._preferred_units == "cm":
299
- return self.cm
300
- elif self._preferred_units == "mm":
301
- return self.mm
302
- elif self._preferred_units == "nm":
303
- return self.nm
304
- elif self._preferred_units == "mil":
305
- return self.mil
306
- elif self._preferred_units == "um":
307
- return self.um
308
- elif self._preferred_units == "pt":
309
- return self.pt
310
- elif self._preferred_units == "spx":
311
- return self.spx
312
- else:
313
- return self.units
314
-
315
- @property
316
- def preferred_length(self):
317
- if self._preferred_units == "px":
318
- return self.length_pixels
319
- elif self._preferred_units == "in":
320
- return self.length_inches
321
- elif self._preferred_units == "cm":
322
- return self.length_cm
323
- elif self._preferred_units == "mm":
324
- return self.length_mm
325
- elif self._preferred_units == "nm":
326
- return self.length_nm
327
- elif self._preferred_units == "mil":
328
- return self.length_mil
329
- elif self._preferred_units == "um":
330
- return self.length_um
331
- elif self._preferred_units == "pt":
332
- return self.length_pt
333
- else:
334
- return self.length_units
335
-
336
- @property
337
- def pixels(self):
338
- amount = self._amount / UNITS_PER_PIXEL
339
- if self._digits:
340
- amount = round(amount, self._digits)
341
- return amount
342
-
343
- @property
344
- def inches(self):
345
- amount = self._amount / UNITS_PER_INCH
346
- if self._digits:
347
- amount = round(amount, self._digits)
348
- return amount
349
-
350
- @property
351
- def cm(self):
352
- amount = self._amount / UNITS_PER_CM
353
- if self._digits:
354
- amount = round(amount, self._digits)
355
- return amount
356
-
357
- @property
358
- def mm(self):
359
- amount = self._amount / UNITS_PER_MM
360
- if self._digits:
361
- amount = round(amount, self._digits)
362
- return amount
363
-
364
- @property
365
- def nm(self):
366
- amount = self._amount / UNITS_PER_NM
367
- if self._digits:
368
- amount = round(amount, self._digits)
369
- return amount
370
-
371
- @property
372
- def mil(self):
373
- amount = self._amount / UNITS_PER_MIL
374
- if self._digits:
375
- amount = round(amount, self._digits)
376
- return amount
377
-
378
- @property
379
- def um(self):
380
- amount = self._amount / UNITS_PER_uM
381
- if self._digits:
382
- amount = round(amount, self._digits)
383
- return amount
384
-
385
- @property
386
- def pt(self):
387
- amount = self._amount / UNITS_PER_POINT
388
- if self._digits:
389
- amount = round(amount, self._digits)
390
- return amount
391
-
392
- @property
393
- def spx(self):
394
- amount = self._amount / self.units_per_spx
395
- if self._digits:
396
- amount = round(amount, self._digits)
397
- return amount
398
-
399
- @property
400
- def units(self):
401
- amount = self._amount
402
- if self._digits:
403
- amount = round(amount, self._digits)
404
- return amount
405
-
406
- @property
407
- def length_pixels(self):
408
- amount = self.pixels
409
- return f"{round(amount, 8)}px"
410
-
411
- @property
412
- def length_inches(self):
413
- amount = self.inches
414
- return f"{round(amount, 8)}in"
415
-
416
- @property
417
- def length_cm(self):
418
- amount = self.cm
419
- return f"{round(amount, 8)}cm"
420
-
421
- @property
422
- def length_mm(self):
423
- amount = self.mm
424
- return f"{round(amount, 8)}mm"
425
-
426
- @property
427
- def length_nm(self):
428
- amount = self.nm
429
- return f"{round(amount, 8)}nm"
430
-
431
- @property
432
- def length_mil(self):
433
- amount = self.mil
434
- return f"{round(amount, 8)}mil"
435
-
436
- @property
437
- def length_um(self):
438
- amount = self.um
439
- return f"{round(amount, 8)}um"
440
-
441
- @property
442
- def length_pt(self):
443
- amount = self.pt
444
- return f"{round(amount, 8)}pt"
445
-
446
- @property
447
- def length_spx(self):
448
- amount = self.spx
449
- return f"{round(amount, 8)}spx"
450
-
451
- @property
452
- def length_units(self):
453
- return f"{self.units}"
454
-
455
- def as_percent(self, relative_length):
456
- return 100.00 * self._amount / Length(relative_length).units
457
-
458
-
459
- class Angle:
460
- """
461
- Angle conversion and math, stores angle as a float in radians and
462
- converts to other forms of angle. Failures to parse raise ValueError.
463
- """
464
-
465
- def __init__(self, angle, digits=None, preferred_units="rad"):
466
- if isinstance(angle, Angle):
467
- self._digits = angle._digits
468
- self.angle = angle.angle
469
- self.preferred_units = angle.preferred_units
470
- return
471
- self._digits = digits
472
- if not isinstance(angle, str):
473
- self.angle = float(angle)
474
- self.preferred_units = preferred_units
475
- return
476
- angle = angle.lower()
477
- if angle.endswith("deg"):
478
- self.angle = float(angle[:-3]) * tau / 360.0
479
- self.preferred_units = "deg"
480
- elif angle.endswith("grad"):
481
- self.angle = float(angle[:-4]) * tau / 400.0
482
- self.preferred_units = "grad"
483
- elif angle.endswith("rad"):
484
- # Must be after 'grad' since 'grad' ends with 'rad' too.
485
- self.angle = float(angle[:-3])
486
- self.preferred_units = "rad"
487
- elif angle.endswith("turn"):
488
- self.angle = float(angle[:-4]) * tau
489
- self.preferred_units = "turn"
490
- elif angle.endswith("%"):
491
- self.angle = float(angle[:-1]) * tau / 100.0
492
- self.preferred_units = "%"
493
- else:
494
- self.angle = float(angle)
495
- self.preferred_units = preferred_units
496
-
497
- def __str__(self):
498
- return self.angle_preferred
499
-
500
- def __copy__(self):
501
- return Angle(
502
- self.angle, preferred_units=self.preferred_units, digits=self._digits
503
- )
504
-
505
- def __eq__(self, other):
506
- if hasattr(other, "angle"):
507
- other = other.angle
508
- c1 = abs((self.angle % tau) - (other % tau)) <= 1e-11
509
- return c1
510
-
511
- def __float__(self):
512
- return self.radians
513
-
514
- def __neg__(self):
515
- return Angle(
516
- -self.angle, preferred_units=self.preferred_units, digits=self._digits
517
- )
518
-
519
- def normalize(self):
520
- self.angle /= tau
521
-
522
- @property
523
- def angle_preferred(self):
524
- if self.preferred_units == "rad":
525
- return self.angle_radians
526
- elif self.preferred_units == "grad":
527
- return self.angle_gradians
528
- elif self.preferred_units == "deg":
529
- return self.angle_degrees
530
- elif self.preferred_units == "turn":
531
- return self.angle_turns
532
-
533
- @property
534
- def radians(self):
535
- amount = self.angle
536
- if self._digits:
537
- amount = round(amount, self._digits)
538
- return amount
539
-
540
- @property
541
- def degrees(self):
542
- amount = self.angle * 360.0 / tau
543
- if self._digits:
544
- amount = round(amount, self._digits)
545
- return amount
546
-
547
- @property
548
- def gradians(self):
549
- amount = self.angle * 400.0 / tau
550
- if self._digits:
551
- amount = round(amount, self._digits)
552
- return amount
553
-
554
- @property
555
- def turns(self):
556
- amount = self.angle / tau
557
- if self._digits:
558
- amount = round(amount, self._digits)
559
- return amount
560
-
561
- @property
562
- def angle_radians(self):
563
- return f"{self.radians}rad"
564
-
565
- @property
566
- def angle_degrees(self):
567
- return f"{self.degrees}deg"
568
-
569
- @property
570
- def angle_gradians(self):
571
- return f"{self.gradians}grad"
572
-
573
- @property
574
- def angle_turns(self):
575
- return f"{self.turns}turn"
576
-
577
- def is_orthogonal(self):
578
- return (self.angle % (tau / 4.0)) == 0
579
-
580
-
581
- def viewbox_transform(
582
- e_x, e_y, e_width, e_height, vb_x, vb_y, vb_width, vb_height, aspect
583
- ):
584
- """
585
- SVG 1.1 7.2, SVG 2.0 8.2 equivalent transform of an SVG viewport.
586
- With regards to https://github.com/w3c/svgwg/issues/215 use 8.2 version.
587
-
588
- It creates transform commands equal to that viewport expected.
589
-
590
- Let e-x, e-y, e-width, e-height be the position and size of the element respectively.
591
- Let vb-x, vb-y, vb-width, vb-height be the min-x, min-y, width and height values of the viewBox attribute
592
- respectively.
593
-
594
- Let align be align value of preserveAspectRatio, or 'xMidYMid' if preserveAspectRatio is not defined.
595
- Let meetOrSlice be the meetOrSlice value of preserveAspectRatio, or 'meet' if preserveAspectRatio is not defined
596
- or if meetOrSlice is missing from this value.
597
-
598
- @param e_x: element_x value
599
- @param e_y: element_y value
600
- @param e_width: element_width value
601
- @param e_height: element_height value
602
- @param vb_x: viewbox_x value
603
- @param vb_y: viewbox_y value
604
- @param vb_width: viewbox_width value
605
- @param vb_height: viewbox_height value
606
- @param aspect: preserve aspect ratio value
607
- @return: string of the SVG transform commands to account for the viewbox.
608
- """
609
- if (
610
- e_x is None
611
- or e_y is None
612
- or e_width is None
613
- or e_height is None
614
- or vb_x is None
615
- or vb_y is None
616
- or vb_width is None
617
- or vb_height is None
618
- ):
619
- return ""
620
- if aspect is not None:
621
- aspect_slice = aspect.split(" ")
622
- try:
623
- align = aspect_slice[0]
624
- except IndexError:
625
- align = "xMidyMid"
626
- try:
627
- meet_or_slice = aspect_slice[1]
628
- except IndexError:
629
- meet_or_slice = "meet"
630
- else:
631
- align = "xMidyMid"
632
- meet_or_slice = "meet"
633
- # Initialize scale-x to e-width/vb-width.
634
- scale_x = e_width / vb_width
635
- # Initialize scale-y to e-height/vb-height.
636
- scale_y = e_height / vb_height
637
-
638
- # If align is not 'none' and meetOrSlice is 'meet', set the larger of scale-x and scale-y to the smaller.
639
- if align != "none" and meet_or_slice == "meet":
640
- scale_x = scale_y = min(scale_x, scale_y)
641
- # Otherwise, if align is not 'none' and meetOrSlice is 'slice', set the smaller of scale-x and scale-y to the larger
642
- elif align != "none" and meet_or_slice == "slice":
643
- scale_x = scale_y = max(scale_x, scale_y)
644
- # Initialize translate-x to e-x - (vb-x * scale-x).
645
- translate_x = e_x - (vb_x * scale_x)
646
- # Initialize translate-y to e-y - (vb-y * scale-y)
647
- translate_y = e_y - (vb_y * scale_y)
648
- # If align contains 'xMid', add (e-width - vb-width * scale-x) / 2 to translate-x.
649
- align = align.lower()
650
- if "xmid" in align:
651
- translate_x += (e_width - vb_width * scale_x) / 2.0
652
- # If align contains 'xMax', add (e-width - vb-width * scale-x) to translate-x.
653
- if "xmax" in align:
654
- translate_x += e_width - vb_width * scale_x
655
- # If align contains 'yMid', add (e-height - vb-height * scale-y) / 2 to translate-y.
656
- if "ymid" in align:
657
- translate_y += (e_height - vb_height * scale_y) / 2.0
658
- # If align contains 'yMax', add (e-height - vb-height * scale-y) to translate-y.
659
- if "ymax" in align:
660
- translate_y += e_height - vb_height * scale_y
661
- # The transform applied to content contained by the element is given by:
662
- # translate(translate-x, translate-y) scale(scale-x, scale-y)
663
- if isinstance(scale_x, Length) or isinstance(scale_y, Length):
664
- raise ValueError
665
- if translate_x == 0 and translate_y == 0:
666
- if scale_x == 1 and scale_y == 1:
667
- return "" # Nothing happens.
668
- else:
669
- return f"scale({scale_x:.12f}, {scale_y:.12f})"
670
- else:
671
- if scale_x == 1 and scale_y == 1:
672
- return f"translate({translate_x:.12f}, {translate_y:.12f})"
673
- else:
674
- return (
675
- f"translate({translate_x:.12f}, {translate_y:.12f}) "
676
- f"scale({scale_x:.12f}, {scale_y:.12f})"
677
- )
678
-
679
-
680
- # TODO: Add in speed for units. mm/s in/s mm/minute.
1
+ """
2
+ Device Specific Unit Conversion Objects
3
+
4
+ This defines a Viewport which all .device services are expected to implement. This provides the core functionality for
5
+ establishing the scene and mapping points from scene locations to device locations. This also provides functionality
6
+ for converting different length or angle units into other length or angle units.
7
+
8
+ The fundamental unit used for all the elements objects is that 1 inch is equal to 65535 native units called a Tat for
9
+ Tiger and Tatarize. This is basically a solid middle ground for providing significant rendering detail while not
10
+ overflowing the buffer in linux which starts react poorly for values greater than 16,777,216 (2^24). This should provide
11
+ enough detail for even the smallest lensed galvo laser while also allowing us to define objects as large as a football
12
+ stadium.
13
+ """
14
+
15
+
16
+ import re
17
+ from copy import copy
18
+ from math import tau
19
+
20
+ PATTERN_FLOAT = r"[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?"
21
+ REGEX_LENGTH = re.compile(r"(%s)\.?([A-Za-z%%]*)" % PATTERN_FLOAT)
22
+ ERROR = 1e-11
23
+ DEFAULT_PPI = 96.0
24
+ NATIVE_UNIT_PER_INCH = 65535
25
+
26
+ NM_PER_INCH = 25400000
27
+ NM_PER_MIL = 25400
28
+ NM_PER_NM = 1
29
+ NM_PER_uM = 1000
30
+ NM_PER_MM = 1000000
31
+ NM_PER_CM = 10000000
32
+ NM_PER_PIXEL = NM_PER_INCH / DEFAULT_PPI
33
+
34
+ MIL_PER_INCH = 1000
35
+ NM_PER_INCH = 2.54e7
36
+ uM_PER_INCH = 25400
37
+ MM_PER_INCH = 25.4
38
+ CM_PER_INCH = 2.54
39
+
40
+ PX_PER_INCH = DEFAULT_PPI
41
+ PX_PER_MIL = DEFAULT_PPI / MIL_PER_INCH
42
+ PX_PER_NM = DEFAULT_PPI / NM_PER_INCH
43
+ PX_PER_uM = DEFAULT_PPI / uM_PER_INCH
44
+ PX_PER_MM = DEFAULT_PPI / MM_PER_INCH
45
+ PX_PER_CM = DEFAULT_PPI / CM_PER_INCH
46
+ PX_PER_PIXEL = 1
47
+
48
+
49
+ UNITS_PER_TAT = 1
50
+ UNITS_PER_INCH = NATIVE_UNIT_PER_INCH
51
+ UNITS_PER_MIL = NATIVE_UNIT_PER_INCH / MIL_PER_INCH
52
+ UNITS_PER_uM = NATIVE_UNIT_PER_INCH / uM_PER_INCH
53
+ UNITS_PER_MM = NATIVE_UNIT_PER_INCH / MM_PER_INCH
54
+ UNITS_PER_CM = NATIVE_UNIT_PER_INCH / CM_PER_INCH
55
+ UNITS_PER_NM = NATIVE_UNIT_PER_INCH / NM_PER_INCH
56
+ UNITS_PER_PIXEL = NATIVE_UNIT_PER_INCH / DEFAULT_PPI
57
+ UNITS_PER_POINT = UNITS_PER_PIXEL * 4.0 / 3.0
58
+ PX_PER_UNIT = 1.0 / UNITS_PER_PIXEL
59
+
60
+ UNITS_NANOMETER = 0
61
+ UNITS_MM = 1
62
+ UNITS_CM = 2
63
+ UNITS_MILS = 3
64
+ UNITS_INCH = 4
65
+ UNITS_PERCENT = 100
66
+
67
+
68
+ ACCEPTED_UNITS = (
69
+ "",
70
+ "cm",
71
+ "mm",
72
+ "in",
73
+ "inch",
74
+ "inches",
75
+ "mil",
76
+ "pt",
77
+ "pc",
78
+ "px",
79
+ "%",
80
+ "tat",
81
+ )
82
+
83
+ ACCEPTED_ANGLE_UNITS = (
84
+ "",
85
+ "deg",
86
+ "grad",
87
+ "rad",
88
+ "turn",
89
+ "%",
90
+ )
91
+
92
+
93
+ class Length:
94
+ """
95
+ Amounts are converted to UNITS.
96
+ Initial unit is saved as preferred units.
97
+ """
98
+
99
+ units_per_spx = 50
100
+
101
+ def __init__(
102
+ self,
103
+ *args,
104
+ amount=None,
105
+ relative_length=None,
106
+ unitless=1.0,
107
+ preferred_units=None,
108
+ digits=None,
109
+ ):
110
+ self._digits = digits
111
+ self._amount = amount
112
+ if relative_length:
113
+ self._relative = Length(relative_length, unitless=unitless).units
114
+ else:
115
+ self._relative = None
116
+ if self._amount is None:
117
+ if len(args) == 2:
118
+ value = str(args[0]) + str(args[1])
119
+ elif len(args) == 1:
120
+ value = args[0]
121
+ else:
122
+ raise ValueError("Arguments not acceptable")
123
+ s = str(value)
124
+ match = REGEX_LENGTH.match(s)
125
+ if not match:
126
+ raise ValueError(f"Length was not parsable: '{s}'.")
127
+ amount = float(match.group(1))
128
+ units = match.group(2)
129
+ if units == "inch" or units == "inches":
130
+ units = "in"
131
+ scale = 1.0
132
+ if units == "":
133
+ if unitless:
134
+ scale = unitless
135
+ elif units == "tat":
136
+ scale = UNITS_PER_TAT
137
+ elif units == "mm":
138
+ scale = UNITS_PER_MM
139
+ elif units == "cm":
140
+ scale = UNITS_PER_CM
141
+ elif units == "um":
142
+ scale = UNITS_PER_uM
143
+ elif units == "nm":
144
+ scale = UNITS_PER_NM
145
+ elif units == "in":
146
+ scale = UNITS_PER_INCH
147
+ elif units == "mil":
148
+ scale = UNITS_PER_MIL
149
+ elif units == "px":
150
+ scale = UNITS_PER_PIXEL
151
+ elif units == "pt":
152
+ scale = UNITS_PER_POINT
153
+ elif units == "spx":
154
+ scale = self.units_per_spx
155
+ elif units == "pc":
156
+ scale = UNITS_PER_PIXEL * 16.0
157
+ elif units == "%":
158
+ if relative_length is not None:
159
+ fraction = amount / 100.0
160
+ if isinstance(relative_length, (str, Length)):
161
+ relative_length = Length(
162
+ relative_length, unitless=unitless
163
+ ).units
164
+ amount = relative_length
165
+ scale = fraction
166
+ units = ""
167
+ else:
168
+ raise ValueError("Percent without relative length is meaningless.")
169
+ else:
170
+ raise ValueError(f"Units '{units}' was not recognized for '{s}'")
171
+ self._amount = scale * amount
172
+ if preferred_units is None:
173
+ preferred_units = units
174
+ else:
175
+ # amount is only ever a number.
176
+ if not isinstance(amount, (float, int)):
177
+ raise ValueError("Amount must be an number.")
178
+ if preferred_units is None:
179
+ preferred_units = ""
180
+ if preferred_units == "inch" or preferred_units == "inches":
181
+ preferred_units = "in"
182
+ self._preferred_units = preferred_units
183
+
184
+ def __float__(self):
185
+ return self._amount
186
+
187
+ def __imul__(self, other):
188
+ if isinstance(other, (int, float)):
189
+ self._amount *= other
190
+ return self
191
+ if self._amount == 0.0:
192
+ return 0.0
193
+ raise ValueError
194
+
195
+ def __iadd__(self, other):
196
+ if not isinstance(other, Length):
197
+ other = Length(other)
198
+ self._amount += other._amount
199
+ return self
200
+
201
+ def __abs__(self):
202
+ c = self.__copy__()
203
+ c._amount = abs(c._amount)
204
+ return c
205
+
206
+ def __truediv__(self, other):
207
+ if not isinstance(other, Length):
208
+ other = Length(other)
209
+ return self._amount / other._amount
210
+
211
+ __floordiv__ = __truediv__
212
+ __div__ = __truediv__
213
+
214
+ def __lt__(self, other):
215
+ return (self - other)._amount - ERROR < 0
216
+
217
+ def __gt__(self, other):
218
+ return (self - other)._amount + ERROR > 0
219
+
220
+ def __le__(self, other):
221
+ return (self - other)._amount - ERROR <= 0
222
+
223
+ def __ge__(self, other):
224
+ return (self - other)._amount + ERROR >= 0
225
+
226
+ def __ne__(self, other):
227
+ return not self.__eq__(other)
228
+
229
+ def __add__(self, other):
230
+ if isinstance(other, (str, float, int)):
231
+ other = Length(other)
232
+ c = self.__copy__()
233
+ c += other
234
+ return c
235
+
236
+ __radd__ = __add__
237
+
238
+ def __mul__(self, other):
239
+ c = copy(self)
240
+ c *= other
241
+ return c
242
+
243
+ def __rdiv__(self, other):
244
+ c = copy(self)
245
+ c *= 1.0 / other._amount
246
+ return c
247
+
248
+ def __neg__(self):
249
+ s = self.__copy__()
250
+ s._amount = -s._amount
251
+ return s
252
+
253
+ def __isub__(self, other):
254
+ if not isinstance(other, Length):
255
+ other = Length(other)
256
+ self += -other
257
+ return self
258
+
259
+ def __sub__(self, other):
260
+ s = self.__copy__()
261
+ s -= other
262
+ return s
263
+
264
+ def __round__(self, ndigits=0):
265
+ return round(self._amount, ndigits=ndigits)
266
+
267
+ def __rsub__(self, other):
268
+ if not isinstance(other, Length):
269
+ other = Length(other)
270
+ return (-self) + other
271
+
272
+ def __copy__(self):
273
+ return Length(
274
+ None,
275
+ amount=self._amount,
276
+ preferred_units=self._preferred_units,
277
+ digits=self._digits,
278
+ )
279
+
280
+ __rmul__ = __mul__
281
+
282
+ def __repr__(self):
283
+ c = self.__copy__()
284
+ c._digits = None
285
+ return c.preferred_length
286
+
287
+ def __str__(self):
288
+ return self.preferred_length
289
+
290
+ def __eq__(self, other):
291
+ if other is None:
292
+ return False
293
+ if isinstance(other, (int, float)):
294
+ return self._amount == other
295
+ if not isinstance(other, Length):
296
+ try:
297
+ other = Length(other)
298
+ except ValueError:
299
+ # Not a length, we do not equal this.
300
+ return False
301
+ return abs(self._amount - other._amount) <= ERROR
302
+
303
+ @property
304
+ def preferred(self):
305
+ if self._preferred_units == "px":
306
+ return self.pixels
307
+ elif self._preferred_units == "in":
308
+ return self.inches
309
+ elif self._preferred_units == "cm":
310
+ return self.cm
311
+ elif self._preferred_units == "mm":
312
+ return self.mm
313
+ elif self._preferred_units == "nm":
314
+ return self.nm
315
+ elif self._preferred_units == "mil":
316
+ return self.mil
317
+ elif self._preferred_units == "um":
318
+ return self.um
319
+ elif self._preferred_units == "pt":
320
+ return self.pt
321
+ elif self._preferred_units == "spx":
322
+ return self.spx
323
+ elif self._preferred_units == "%":
324
+ return self.percent
325
+ else:
326
+ return self.units
327
+
328
+ @property
329
+ def preferred_length(self):
330
+ if self._preferred_units == "px":
331
+ return self.length_pixels
332
+ elif self._preferred_units == "in":
333
+ return self.length_inches
334
+ elif self._preferred_units == "cm":
335
+ return self.length_cm
336
+ elif self._preferred_units == "mm":
337
+ return self.length_mm
338
+ elif self._preferred_units == "nm":
339
+ return self.length_nm
340
+ elif self._preferred_units == "mil":
341
+ return self.length_mil
342
+ elif self._preferred_units == "um":
343
+ return self.length_um
344
+ elif self._preferred_units == "pt":
345
+ return self.length_pt
346
+ elif self._preferred_units == "%":
347
+ return self.length_percent
348
+ else:
349
+ return self.length_units
350
+
351
+ @property
352
+ def pixels(self):
353
+ amount = self._amount / UNITS_PER_PIXEL
354
+ if self._digits:
355
+ amount = round(amount, self._digits)
356
+ return amount
357
+
358
+ @property
359
+ def inches(self):
360
+ amount = self._amount / UNITS_PER_INCH
361
+ if self._digits:
362
+ amount = round(amount, self._digits)
363
+ return amount
364
+
365
+ @property
366
+ def cm(self):
367
+ amount = self._amount / UNITS_PER_CM
368
+ if self._digits:
369
+ amount = round(amount, self._digits)
370
+ return amount
371
+
372
+ @property
373
+ def mm(self):
374
+ amount = self._amount / UNITS_PER_MM
375
+ if self._digits:
376
+ amount = round(amount, self._digits)
377
+ return amount
378
+
379
+ @property
380
+ def nm(self):
381
+ amount = self._amount / UNITS_PER_NM
382
+ if self._digits:
383
+ amount = round(amount, self._digits)
384
+ return amount
385
+
386
+ @property
387
+ def mil(self):
388
+ amount = self._amount / UNITS_PER_MIL
389
+ if self._digits:
390
+ amount = round(amount, self._digits)
391
+ return amount
392
+
393
+ @property
394
+ def um(self):
395
+ amount = self._amount / UNITS_PER_uM
396
+ if self._digits:
397
+ amount = round(amount, self._digits)
398
+ return amount
399
+
400
+ @property
401
+ def pt(self):
402
+ amount = self._amount / UNITS_PER_POINT
403
+ if self._digits:
404
+ amount = round(amount, self._digits)
405
+ return amount
406
+
407
+ @property
408
+ def spx(self):
409
+ amount = self._amount / self.units_per_spx
410
+ if self._digits:
411
+ amount = round(amount, self._digits)
412
+ return amount
413
+
414
+ @property
415
+ def units(self):
416
+ amount = self._amount
417
+ if self._digits:
418
+ amount = round(amount, self._digits)
419
+ return amount
420
+
421
+ @property
422
+ def percent(self):
423
+ if self._relative is None or self._relative == 0:
424
+ raise ValueError("Percent without relative length is meaningless.")
425
+ amount = 100.0 * self._amount / self._relative
426
+ if self._digits:
427
+ amount = round(amount, self._digits)
428
+ return amount
429
+
430
+ @property
431
+ def length_pixels(self):
432
+ amount = self.pixels
433
+ return f"{round(amount, 8)}px"
434
+
435
+ @property
436
+ def length_inches(self):
437
+ amount = self.inches
438
+ return f"{round(amount, 8)}in"
439
+
440
+ @property
441
+ def length_cm(self):
442
+ amount = self.cm
443
+ return f"{round(amount, 8)}cm"
444
+
445
+ @property
446
+ def length_mm(self):
447
+ amount = self.mm
448
+ return f"{round(amount, 8)}mm"
449
+
450
+ @property
451
+ def length_nm(self):
452
+ amount = self.nm
453
+ return f"{round(amount, 8)}nm"
454
+
455
+ @property
456
+ def length_mil(self):
457
+ amount = self.mil
458
+ return f"{round(amount, 8)}mil"
459
+
460
+ @property
461
+ def length_um(self):
462
+ amount = self.um
463
+ return f"{round(amount, 8)}um"
464
+
465
+ @property
466
+ def length_pt(self):
467
+ amount = self.pt
468
+ return f"{round(amount, 8)}pt"
469
+
470
+ @property
471
+ def length_spx(self):
472
+ amount = self.spx
473
+ return f"{round(amount, 8)}spx"
474
+
475
+ @property
476
+ def length_percent(self):
477
+ amount = self.percent
478
+ return f"{round(amount, 8)}%"
479
+
480
+ @property
481
+ def length_units(self):
482
+ return f"{self.units}"
483
+
484
+ def as_percent(self, relative_length):
485
+ return 100.00 * self._amount / Length(relative_length).units
486
+
487
+
488
+ class Angle:
489
+ """
490
+ Angle conversion and math, stores angle as a float in radians and
491
+ converts to other forms of angle. Failures to parse raise ValueError.
492
+ """
493
+
494
+ def __init__(self, angle, digits=None, preferred_units="rad"):
495
+ if isinstance(angle, Angle):
496
+ self._digits = angle._digits
497
+ self.angle = angle.angle
498
+ self.preferred_units = angle.preferred_units
499
+ return
500
+ self._digits = digits
501
+ if not isinstance(angle, str):
502
+ self.angle = float(angle)
503
+ self.preferred_units = preferred_units
504
+ return
505
+ angle = angle.lower()
506
+ if angle.endswith("deg"):
507
+ self.angle = float(angle[:-3]) * tau / 360.0
508
+ self.preferred_units = "deg"
509
+ elif angle.endswith("grad"):
510
+ self.angle = float(angle[:-4]) * tau / 400.0
511
+ self.preferred_units = "grad"
512
+ elif angle.endswith("rad"):
513
+ # Must be after 'grad' since 'grad' ends with 'rad' too.
514
+ self.angle = float(angle[:-3])
515
+ self.preferred_units = "rad"
516
+ elif angle.endswith("turn"):
517
+ self.angle = float(angle[:-4]) * tau
518
+ self.preferred_units = "turn"
519
+ elif angle.endswith("%"):
520
+ self.angle = float(angle[:-1]) * tau / 100.0
521
+ self.preferred_units = "%"
522
+ else:
523
+ self.angle = float(angle)
524
+ self.preferred_units = preferred_units
525
+
526
+ def __str__(self):
527
+ return self.angle_preferred
528
+
529
+ def __copy__(self):
530
+ return Angle(
531
+ self.angle, preferred_units=self.preferred_units, digits=self._digits
532
+ )
533
+
534
+ def __eq__(self, other):
535
+ if hasattr(other, "angle"):
536
+ other = other.angle
537
+ c1 = abs((self.angle % tau) - (other % tau)) <= 1e-11
538
+ return c1
539
+
540
+ def __add__(self, other):
541
+ if isinstance(other, Angle):
542
+ return Angle(
543
+ self.angle + other.angle,
544
+ preferred_units=self.preferred_units,
545
+ digits=self._digits,
546
+ )
547
+ return Angle(
548
+ self.angle + other,
549
+ preferred_units=self.preferred_units,
550
+ digits=self._digits,
551
+ )
552
+
553
+ def __sub__(self, other):
554
+ return -self + other
555
+
556
+ def __truediv__(self, other):
557
+ return Angle(
558
+ self.radians / other,
559
+ preferred_units=self.preferred_units,
560
+ digits=self._digits,
561
+ )
562
+
563
+ def __mul__(self, other):
564
+ return Angle(
565
+ self.radians * other,
566
+ preferred_units=self.preferred_units,
567
+ digits=self._digits,
568
+ )
569
+
570
+ def __radd__(self, other):
571
+ return self.__add__(other)
572
+
573
+ def __rsub__(self, other):
574
+ return self.__neg__().__add__(other)
575
+
576
+ def __rmul__(self, other):
577
+ return self.__mul__(other)
578
+
579
+ def __iadd__(self, other):
580
+ if isinstance(other, Angle):
581
+ other = other.angle
582
+ self.angle += other
583
+ return self
584
+
585
+ def __isub__(self, other):
586
+ if isinstance(other, Angle):
587
+ other = other.angle
588
+ self.angle -= other
589
+ return self
590
+
591
+ def __imul__(self, other):
592
+ if isinstance(other, Angle):
593
+ other = other.angle
594
+ self.angle *= other
595
+ return self
596
+
597
+ def __idiv__(self, other):
598
+ if isinstance(other, Angle):
599
+ other = other.angle
600
+ self.angle /= other
601
+ return self
602
+
603
+ def __float__(self):
604
+ return self.angle
605
+
606
+ def __neg__(self):
607
+ return Angle(
608
+ -self.angle, preferred_units=self.preferred_units, digits=self._digits
609
+ )
610
+
611
+ def normalize(self):
612
+ self.angle /= tau
613
+
614
+ @classmethod
615
+ def from_radians(cls, radians):
616
+ return cls(radians)
617
+
618
+ @classmethod
619
+ def from_degrees(cls, degrees):
620
+ return cls(tau * degrees / 360.0)
621
+
622
+ @classmethod
623
+ def from_gradians(cls, gradians):
624
+ return cls(tau * gradians / 400.0)
625
+
626
+ @classmethod
627
+ def from_turns(cls, turns):
628
+ return cls(tau * turns)
629
+
630
+ @property
631
+ def angle_preferred(self):
632
+ if self.preferred_units == "rad":
633
+ return self.angle_radians
634
+ elif self.preferred_units == "grad":
635
+ return self.angle_gradians
636
+ elif self.preferred_units == "deg":
637
+ return self.angle_degrees
638
+ elif self.preferred_units == "turn":
639
+ return self.angle_turns
640
+
641
+ @property
642
+ def radians(self):
643
+ return self.angle
644
+
645
+ @property
646
+ def degrees(self):
647
+ return self.angle * 360.0 / tau
648
+
649
+ @property
650
+ def gradians(self):
651
+ return self.angle * 400.0 / tau
652
+
653
+ @property
654
+ def turns(self):
655
+ return self.angle / tau
656
+
657
+ @property
658
+ def angle_radians(self):
659
+ digits = 4 if self._digits is None else self._digits
660
+ angle = f"{self.radians:.{digits}f}".rstrip("0").rstrip(".")
661
+ return f"{angle}rad"
662
+
663
+ @property
664
+ def angle_degrees(self):
665
+ digits = 4 if self._digits is None else self._digits
666
+ angle = f"{self.degrees:.{digits}f}".rstrip("0").rstrip(".")
667
+ return f"{angle}deg"
668
+
669
+ @property
670
+ def angle_gradians(self):
671
+ digits = 4 if self._digits is None else self._digits
672
+ angle = f"{self.gradians:.{digits}f}".rstrip("0").rstrip(".")
673
+ return f"{angle}grad"
674
+
675
+ @property
676
+ def angle_turns(self):
677
+ digits = 4 if self._digits is None else self._digits
678
+ angle = f"{self.turns:.{digits}f}".rstrip("0").rstrip(".")
679
+ return f"{angle}turn"
680
+
681
+ def is_orthogonal(self):
682
+ return (self.angle % (tau / 4.0)) == 0
683
+
684
+
685
+ def viewbox_transform(
686
+ e_x, e_y, e_width, e_height, vb_x, vb_y, vb_width, vb_height, aspect
687
+ ):
688
+ """
689
+ SVG 1.1 7.2, SVG 2.0 8.2 equivalent transform of an SVG viewport.
690
+ Regarding https://github.com/w3c/svgwg/issues/215 use 8.2 version.
691
+
692
+ It creates transform commands equal to that viewport expected.
693
+
694
+ Let e-x, e-y, e-width, e-height be the position and size of the element respectively.
695
+ Let vb-x, vb-y, vb-width, vb-height be the min-x, min-y, width and height values of the viewBox attribute
696
+ respectively.
697
+
698
+ Let align be align value of preserveAspectRatio, or 'xMidYMid' if preserveAspectRatio is not defined.
699
+ Let meetOrSlice be the meetOrSlice value of preserveAspectRatio, or 'meet' if preserveAspectRatio is not defined
700
+ or if meetOrSlice is missing from this value.
701
+
702
+ @param e_x: element_x value
703
+ @param e_y: element_y value
704
+ @param e_width: element_width value
705
+ @param e_height: element_height value
706
+ @param vb_x: viewbox_x value
707
+ @param vb_y: viewbox_y value
708
+ @param vb_width: viewbox_width value
709
+ @param vb_height: viewbox_height value
710
+ @param aspect: preserve aspect ratio value
711
+ @return: string of the SVG transform commands to account for the viewbox.
712
+ """
713
+ if (
714
+ e_x is None
715
+ or e_y is None
716
+ or e_width is None
717
+ or e_height is None
718
+ or vb_x is None
719
+ or vb_y is None
720
+ or vb_width is None
721
+ or vb_height is None
722
+ ):
723
+ return ""
724
+ if aspect is not None:
725
+ aspect_slice = aspect.split(" ")
726
+ try:
727
+ align = aspect_slice[0]
728
+ except IndexError:
729
+ align = "xMidyMid"
730
+ try:
731
+ meet_or_slice = aspect_slice[1]
732
+ except IndexError:
733
+ meet_or_slice = "meet"
734
+ else:
735
+ align = "xMidyMid"
736
+ meet_or_slice = "meet"
737
+ # Initialize scale-x to e-width/vb-width.
738
+ scale_x = e_width / vb_width
739
+ # Initialize scale-y to e-height/vb-height.
740
+ scale_y = e_height / vb_height
741
+
742
+ # If align is not 'none' and meetOrSlice is 'meet', set the larger of scale-x and scale-y to the smaller.
743
+ if align != "none" and meet_or_slice == "meet":
744
+ scale_x = scale_y = min(scale_x, scale_y)
745
+ # Otherwise, if align is not 'none' and meetOrSlice is 'slice', set the smaller of scale-x and scale-y to the larger
746
+ elif align != "none" and meet_or_slice == "slice":
747
+ scale_x = scale_y = max(scale_x, scale_y)
748
+ # Initialize translate-x to e-x - (vb-x * scale-x).
749
+ translate_x = e_x - (vb_x * scale_x)
750
+ # Initialize translate-y to e-y - (vb-y * scale-y)
751
+ translate_y = e_y - (vb_y * scale_y)
752
+ # If align contains 'xMid', add (e-width - vb-width * scale-x) / 2 to translate-x.
753
+ align = align.lower()
754
+ if "xmid" in align:
755
+ translate_x += (e_width - vb_width * scale_x) / 2.0
756
+ # If align contains 'xMax', add (e-width - vb-width * scale-x) to translate-x.
757
+ if "xmax" in align:
758
+ translate_x += e_width - vb_width * scale_x
759
+ # If align contains 'yMid', add (e-height - vb-height * scale-y) / 2 to translate-y.
760
+ if "ymid" in align:
761
+ translate_y += (e_height - vb_height * scale_y) / 2.0
762
+ # If align contains 'yMax', add (e-height - vb-height * scale-y) to translate-y.
763
+ if "ymax" in align:
764
+ translate_y += e_height - vb_height * scale_y
765
+ # The transform applied to content contained by the element is given by:
766
+ # translate(translate-x, translate-y) scale(scale-x, scale-y)
767
+ if isinstance(scale_x, Length) or isinstance(scale_y, Length):
768
+ raise ValueError
769
+ if translate_x == 0 and translate_y == 0:
770
+ if scale_x == 1 and scale_y == 1:
771
+ return "" # Nothing happens.
772
+ else:
773
+ return f"scale({scale_x:.12f}, {scale_y:.12f})"
774
+ else:
775
+ if scale_x == 1 and scale_y == 1:
776
+ return f"translate({translate_x:.12f}, {translate_y:.12f})"
777
+ else:
778
+ return (
779
+ f"translate({translate_x:.12f}, {translate_y:.12f}) "
780
+ f"scale({scale_x:.12f}, {scale_y:.12f})"
781
+ )
782
+
783
+
784
+ # TODO: Add in speed for units. mm/s in/s mm/minute.