meerk40t 0.9.3001__py2.py3-none-any.whl → 0.9.7020__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 (446) 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 +1194 -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 +1858 -1507
  50. meerk40t/core/elements/clipboard.py +229 -219
  51. meerk40t/core/elements/element_treeops.py +4595 -2837
  52. meerk40t/core/elements/element_types.py +125 -105
  53. meerk40t/core/elements/elements.py +4315 -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 +934 -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/testcases.py +105 -0
  66. meerk40t/core/elements/trace.py +651 -563
  67. meerk40t/core/elements/tree_commands.py +415 -409
  68. meerk40t/core/elements/undo_redo.py +116 -58
  69. meerk40t/core/elements/wordlist.py +319 -200
  70. meerk40t/core/exceptions.py +9 -9
  71. meerk40t/core/laserjob.py +220 -220
  72. meerk40t/core/logging.py +63 -63
  73. meerk40t/core/node/blobnode.py +83 -86
  74. meerk40t/core/node/bootstrap.py +105 -103
  75. meerk40t/core/node/branch_elems.py +40 -31
  76. meerk40t/core/node/branch_ops.py +45 -38
  77. meerk40t/core/node/branch_regmark.py +48 -41
  78. meerk40t/core/node/cutnode.py +29 -32
  79. meerk40t/core/node/effect_hatch.py +375 -257
  80. meerk40t/core/node/effect_warp.py +398 -0
  81. meerk40t/core/node/effect_wobble.py +441 -309
  82. meerk40t/core/node/elem_ellipse.py +404 -309
  83. meerk40t/core/node/elem_image.py +1082 -801
  84. meerk40t/core/node/elem_line.py +358 -292
  85. meerk40t/core/node/elem_path.py +259 -201
  86. meerk40t/core/node/elem_point.py +129 -102
  87. meerk40t/core/node/elem_polyline.py +310 -246
  88. meerk40t/core/node/elem_rect.py +376 -286
  89. meerk40t/core/node/elem_text.py +445 -418
  90. meerk40t/core/node/filenode.py +59 -40
  91. meerk40t/core/node/groupnode.py +138 -74
  92. meerk40t/core/node/image_processed.py +777 -766
  93. meerk40t/core/node/image_raster.py +156 -113
  94. meerk40t/core/node/layernode.py +31 -31
  95. meerk40t/core/node/mixins.py +135 -107
  96. meerk40t/core/node/node.py +1427 -1304
  97. meerk40t/core/node/nutils.py +117 -114
  98. meerk40t/core/node/op_cut.py +463 -335
  99. meerk40t/core/node/op_dots.py +296 -251
  100. meerk40t/core/node/op_engrave.py +414 -311
  101. meerk40t/core/node/op_image.py +755 -369
  102. meerk40t/core/node/op_raster.py +787 -522
  103. meerk40t/core/node/place_current.py +37 -40
  104. meerk40t/core/node/place_point.py +329 -126
  105. meerk40t/core/node/refnode.py +58 -47
  106. meerk40t/core/node/rootnode.py +225 -219
  107. meerk40t/core/node/util_console.py +48 -48
  108. meerk40t/core/node/util_goto.py +84 -65
  109. meerk40t/core/node/util_home.py +61 -61
  110. meerk40t/core/node/util_input.py +102 -102
  111. meerk40t/core/node/util_output.py +102 -102
  112. meerk40t/core/node/util_wait.py +65 -65
  113. meerk40t/core/parameters.py +709 -707
  114. meerk40t/core/planner.py +875 -785
  115. meerk40t/core/plotplanner.py +656 -652
  116. meerk40t/core/space.py +120 -113
  117. meerk40t/core/spoolers.py +706 -705
  118. meerk40t/core/svg_io.py +1836 -1549
  119. meerk40t/core/treeop.py +534 -445
  120. meerk40t/core/undos.py +278 -124
  121. meerk40t/core/units.py +784 -680
  122. meerk40t/core/view.py +393 -322
  123. meerk40t/core/webhelp.py +62 -62
  124. meerk40t/core/wordlist.py +513 -504
  125. meerk40t/cylinder/cylinder.py +247 -0
  126. meerk40t/cylinder/gui/cylindersettings.py +41 -0
  127. meerk40t/cylinder/gui/gui.py +24 -0
  128. meerk40t/device/__init__.py +1 -1
  129. meerk40t/device/basedevice.py +322 -123
  130. meerk40t/device/devicechoices.py +50 -0
  131. meerk40t/device/dummydevice.py +163 -128
  132. meerk40t/device/gui/defaultactions.py +618 -602
  133. meerk40t/device/gui/effectspanel.py +114 -0
  134. meerk40t/device/gui/formatterpanel.py +253 -290
  135. meerk40t/device/gui/warningpanel.py +337 -260
  136. meerk40t/device/mixins.py +13 -13
  137. meerk40t/dxf/__init__.py +1 -1
  138. meerk40t/dxf/dxf_io.py +766 -554
  139. meerk40t/dxf/plugin.py +47 -35
  140. meerk40t/external_plugins.py +79 -79
  141. meerk40t/external_plugins_build.py +28 -28
  142. meerk40t/extra/cag.py +112 -116
  143. meerk40t/extra/coolant.py +403 -0
  144. meerk40t/extra/encode_detect.py +204 -0
  145. meerk40t/extra/ezd.py +1165 -1165
  146. meerk40t/extra/hershey.py +834 -340
  147. meerk40t/extra/imageactions.py +322 -316
  148. meerk40t/extra/inkscape.py +628 -622
  149. meerk40t/extra/lbrn.py +424 -424
  150. meerk40t/extra/outerworld.py +283 -0
  151. meerk40t/extra/param_functions.py +1542 -1556
  152. meerk40t/extra/potrace.py +257 -253
  153. meerk40t/extra/serial_exchange.py +118 -0
  154. meerk40t/extra/updater.py +602 -453
  155. meerk40t/extra/vectrace.py +147 -146
  156. meerk40t/extra/winsleep.py +83 -83
  157. meerk40t/extra/xcs_reader.py +597 -0
  158. meerk40t/fill/fills.py +781 -335
  159. meerk40t/fill/patternfill.py +1061 -1061
  160. meerk40t/fill/patterns.py +614 -567
  161. meerk40t/grbl/control.py +87 -87
  162. meerk40t/grbl/controller.py +990 -903
  163. meerk40t/grbl/device.py +1084 -768
  164. meerk40t/grbl/driver.py +989 -771
  165. meerk40t/grbl/emulator.py +532 -497
  166. meerk40t/grbl/gcodejob.py +783 -767
  167. meerk40t/grbl/gui/grblconfiguration.py +373 -298
  168. meerk40t/grbl/gui/grblcontroller.py +485 -271
  169. meerk40t/grbl/gui/grblhardwareconfig.py +269 -153
  170. meerk40t/grbl/gui/grbloperationconfig.py +105 -0
  171. meerk40t/grbl/gui/gui.py +147 -116
  172. meerk40t/grbl/interpreter.py +44 -44
  173. meerk40t/grbl/loader.py +22 -22
  174. meerk40t/grbl/mock_connection.py +56 -56
  175. meerk40t/grbl/plugin.py +294 -264
  176. meerk40t/grbl/serial_connection.py +93 -88
  177. meerk40t/grbl/tcp_connection.py +81 -79
  178. meerk40t/grbl/ws_connection.py +112 -0
  179. meerk40t/gui/__init__.py +1 -1
  180. meerk40t/gui/about.py +2042 -296
  181. meerk40t/gui/alignment.py +1644 -1608
  182. meerk40t/gui/autoexec.py +199 -0
  183. meerk40t/gui/basicops.py +791 -670
  184. meerk40t/gui/bufferview.py +77 -71
  185. meerk40t/gui/busy.py +232 -133
  186. meerk40t/gui/choicepropertypanel.py +1662 -1469
  187. meerk40t/gui/consolepanel.py +706 -542
  188. meerk40t/gui/devicepanel.py +687 -581
  189. meerk40t/gui/dialogoptions.py +110 -107
  190. meerk40t/gui/executejob.py +316 -306
  191. meerk40t/gui/fonts.py +90 -90
  192. meerk40t/gui/functionwrapper.py +252 -0
  193. meerk40t/gui/gui_mixins.py +729 -0
  194. meerk40t/gui/guicolors.py +205 -182
  195. meerk40t/gui/help_assets/help_assets.py +218 -201
  196. meerk40t/gui/helper.py +154 -0
  197. meerk40t/gui/hersheymanager.py +1440 -846
  198. meerk40t/gui/icons.py +3422 -2747
  199. meerk40t/gui/imagesplitter.py +555 -508
  200. meerk40t/gui/keymap.py +354 -344
  201. meerk40t/gui/laserpanel.py +897 -806
  202. meerk40t/gui/laserrender.py +1470 -1232
  203. meerk40t/gui/lasertoolpanel.py +805 -793
  204. meerk40t/gui/magnetoptions.py +436 -0
  205. meerk40t/gui/materialmanager.py +2944 -0
  206. meerk40t/gui/materialtest.py +1722 -1694
  207. meerk40t/gui/mkdebug.py +646 -359
  208. meerk40t/gui/mwindow.py +163 -140
  209. meerk40t/gui/navigationpanels.py +2605 -2467
  210. meerk40t/gui/notes.py +143 -142
  211. meerk40t/gui/opassignment.py +414 -410
  212. meerk40t/gui/operation_info.py +310 -299
  213. meerk40t/gui/plugin.py +500 -328
  214. meerk40t/gui/position.py +714 -669
  215. meerk40t/gui/preferences.py +901 -650
  216. meerk40t/gui/propertypanels/attributes.py +1461 -1131
  217. meerk40t/gui/propertypanels/blobproperty.py +117 -114
  218. meerk40t/gui/propertypanels/consoleproperty.py +83 -80
  219. meerk40t/gui/propertypanels/gotoproperty.py +77 -0
  220. meerk40t/gui/propertypanels/groupproperties.py +223 -217
  221. meerk40t/gui/propertypanels/hatchproperty.py +489 -469
  222. meerk40t/gui/propertypanels/imageproperty.py +2244 -1384
  223. meerk40t/gui/propertypanels/inputproperty.py +59 -58
  224. meerk40t/gui/propertypanels/opbranchproperties.py +82 -80
  225. meerk40t/gui/propertypanels/operationpropertymain.py +1890 -1638
  226. meerk40t/gui/propertypanels/outputproperty.py +59 -58
  227. meerk40t/gui/propertypanels/pathproperty.py +389 -380
  228. meerk40t/gui/propertypanels/placementproperty.py +1214 -383
  229. meerk40t/gui/propertypanels/pointproperty.py +140 -136
  230. meerk40t/gui/propertypanels/propertywindow.py +313 -181
  231. meerk40t/gui/propertypanels/rasterwizardpanels.py +996 -912
  232. meerk40t/gui/propertypanels/regbranchproperties.py +76 -0
  233. meerk40t/gui/propertypanels/textproperty.py +770 -755
  234. meerk40t/gui/propertypanels/waitproperty.py +56 -55
  235. meerk40t/gui/propertypanels/warpproperty.py +121 -0
  236. meerk40t/gui/propertypanels/wobbleproperty.py +255 -204
  237. meerk40t/gui/ribbon.py +2471 -2210
  238. meerk40t/gui/scene/scene.py +1100 -1051
  239. meerk40t/gui/scene/sceneconst.py +22 -22
  240. meerk40t/gui/scene/scenepanel.py +439 -349
  241. meerk40t/gui/scene/scenespacewidget.py +365 -365
  242. meerk40t/gui/scene/widget.py +518 -505
  243. meerk40t/gui/scenewidgets/affinemover.py +215 -215
  244. meerk40t/gui/scenewidgets/attractionwidget.py +315 -309
  245. meerk40t/gui/scenewidgets/bedwidget.py +120 -97
  246. meerk40t/gui/scenewidgets/elementswidget.py +137 -107
  247. meerk40t/gui/scenewidgets/gridwidget.py +785 -745
  248. meerk40t/gui/scenewidgets/guidewidget.py +765 -765
  249. meerk40t/gui/scenewidgets/laserpathwidget.py +66 -66
  250. meerk40t/gui/scenewidgets/machineoriginwidget.py +86 -86
  251. meerk40t/gui/scenewidgets/nodeselector.py +28 -28
  252. meerk40t/gui/scenewidgets/rectselectwidget.py +592 -346
  253. meerk40t/gui/scenewidgets/relocatewidget.py +33 -33
  254. meerk40t/gui/scenewidgets/reticlewidget.py +83 -83
  255. meerk40t/gui/scenewidgets/selectionwidget.py +2958 -2756
  256. meerk40t/gui/simpleui.py +362 -333
  257. meerk40t/gui/simulation.py +2451 -2094
  258. meerk40t/gui/snapoptions.py +208 -203
  259. meerk40t/gui/spoolerpanel.py +1227 -1180
  260. meerk40t/gui/statusbarwidgets/defaultoperations.py +480 -353
  261. meerk40t/gui/statusbarwidgets/infowidget.py +520 -483
  262. meerk40t/gui/statusbarwidgets/opassignwidget.py +356 -355
  263. meerk40t/gui/statusbarwidgets/selectionwidget.py +172 -171
  264. meerk40t/gui/statusbarwidgets/shapepropwidget.py +754 -236
  265. meerk40t/gui/statusbarwidgets/statusbar.py +272 -260
  266. meerk40t/gui/statusbarwidgets/statusbarwidget.py +268 -270
  267. meerk40t/gui/statusbarwidgets/strokewidget.py +267 -251
  268. meerk40t/gui/themes.py +200 -78
  269. meerk40t/gui/tips.py +590 -0
  270. meerk40t/gui/toolwidgets/circlebrush.py +35 -35
  271. meerk40t/gui/toolwidgets/toolcircle.py +248 -242
  272. meerk40t/gui/toolwidgets/toolcontainer.py +82 -77
  273. meerk40t/gui/toolwidgets/tooldraw.py +97 -90
  274. meerk40t/gui/toolwidgets/toolellipse.py +219 -212
  275. meerk40t/gui/toolwidgets/toolimagecut.py +25 -132
  276. meerk40t/gui/toolwidgets/toolline.py +39 -144
  277. meerk40t/gui/toolwidgets/toollinetext.py +79 -236
  278. meerk40t/gui/toolwidgets/toollinetext_inline.py +296 -0
  279. meerk40t/gui/toolwidgets/toolmeasure.py +163 -216
  280. meerk40t/gui/toolwidgets/toolnodeedit.py +2088 -2074
  281. meerk40t/gui/toolwidgets/toolnodemove.py +92 -94
  282. meerk40t/gui/toolwidgets/toolparameter.py +754 -668
  283. meerk40t/gui/toolwidgets/toolplacement.py +108 -108
  284. meerk40t/gui/toolwidgets/toolpoint.py +68 -59
  285. meerk40t/gui/toolwidgets/toolpointlistbuilder.py +294 -0
  286. meerk40t/gui/toolwidgets/toolpointmove.py +183 -0
  287. meerk40t/gui/toolwidgets/toolpolygon.py +288 -403
  288. meerk40t/gui/toolwidgets/toolpolyline.py +38 -196
  289. meerk40t/gui/toolwidgets/toolrect.py +211 -207
  290. meerk40t/gui/toolwidgets/toolrelocate.py +72 -72
  291. meerk40t/gui/toolwidgets/toolribbon.py +598 -113
  292. meerk40t/gui/toolwidgets/tooltabedit.py +546 -0
  293. meerk40t/gui/toolwidgets/tooltext.py +98 -89
  294. meerk40t/gui/toolwidgets/toolvector.py +213 -204
  295. meerk40t/gui/toolwidgets/toolwidget.py +39 -39
  296. meerk40t/gui/usbconnect.py +98 -91
  297. meerk40t/gui/utilitywidgets/buttonwidget.py +18 -18
  298. meerk40t/gui/utilitywidgets/checkboxwidget.py +90 -90
  299. meerk40t/gui/utilitywidgets/controlwidget.py +14 -14
  300. meerk40t/gui/utilitywidgets/cyclocycloidwidget.py +343 -340
  301. meerk40t/gui/utilitywidgets/debugwidgets.py +148 -0
  302. meerk40t/gui/utilitywidgets/handlewidget.py +27 -27
  303. meerk40t/gui/utilitywidgets/harmonograph.py +450 -447
  304. meerk40t/gui/utilitywidgets/openclosewidget.py +40 -40
  305. meerk40t/gui/utilitywidgets/rotationwidget.py +54 -54
  306. meerk40t/gui/utilitywidgets/scalewidget.py +75 -75
  307. meerk40t/gui/utilitywidgets/seekbarwidget.py +183 -183
  308. meerk40t/gui/utilitywidgets/togglewidget.py +142 -142
  309. meerk40t/gui/utilitywidgets/toolbarwidget.py +8 -8
  310. meerk40t/gui/wordlisteditor.py +985 -931
  311. meerk40t/gui/wxmeerk40t.py +1447 -1169
  312. meerk40t/gui/wxmmain.py +5644 -4112
  313. meerk40t/gui/wxmribbon.py +1591 -1076
  314. meerk40t/gui/wxmscene.py +1631 -1453
  315. meerk40t/gui/wxmtree.py +2416 -2089
  316. meerk40t/gui/wxutils.py +1769 -1099
  317. meerk40t/gui/zmatrix.py +102 -102
  318. meerk40t/image/__init__.py +1 -1
  319. meerk40t/image/dither.py +429 -0
  320. meerk40t/image/imagetools.py +2793 -2269
  321. meerk40t/internal_plugins.py +150 -130
  322. meerk40t/kernel/__init__.py +63 -12
  323. meerk40t/kernel/channel.py +259 -212
  324. meerk40t/kernel/context.py +538 -538
  325. meerk40t/kernel/exceptions.py +41 -41
  326. meerk40t/kernel/functions.py +463 -414
  327. meerk40t/kernel/jobs.py +100 -100
  328. meerk40t/kernel/kernel.py +3828 -3571
  329. meerk40t/kernel/lifecycles.py +71 -71
  330. meerk40t/kernel/module.py +49 -49
  331. meerk40t/kernel/service.py +147 -147
  332. meerk40t/kernel/settings.py +383 -343
  333. meerk40t/lihuiyu/controller.py +883 -876
  334. meerk40t/lihuiyu/device.py +1181 -1069
  335. meerk40t/lihuiyu/driver.py +1466 -1372
  336. meerk40t/lihuiyu/gui/gui.py +127 -106
  337. meerk40t/lihuiyu/gui/lhyaccelgui.py +377 -363
  338. meerk40t/lihuiyu/gui/lhycontrollergui.py +741 -651
  339. meerk40t/lihuiyu/gui/lhydrivergui.py +470 -446
  340. meerk40t/lihuiyu/gui/lhyoperationproperties.py +238 -237
  341. meerk40t/lihuiyu/gui/tcpcontroller.py +226 -190
  342. meerk40t/lihuiyu/interpreter.py +53 -53
  343. meerk40t/lihuiyu/laserspeed.py +450 -450
  344. meerk40t/lihuiyu/loader.py +90 -90
  345. meerk40t/lihuiyu/parser.py +404 -404
  346. meerk40t/lihuiyu/plugin.py +101 -102
  347. meerk40t/lihuiyu/tcp_connection.py +111 -109
  348. meerk40t/main.py +231 -165
  349. meerk40t/moshi/builder.py +788 -781
  350. meerk40t/moshi/controller.py +505 -499
  351. meerk40t/moshi/device.py +495 -442
  352. meerk40t/moshi/driver.py +862 -696
  353. meerk40t/moshi/gui/gui.py +78 -76
  354. meerk40t/moshi/gui/moshicontrollergui.py +538 -522
  355. meerk40t/moshi/gui/moshidrivergui.py +87 -75
  356. meerk40t/moshi/plugin.py +43 -43
  357. meerk40t/network/console_server.py +140 -57
  358. meerk40t/network/kernelserver.py +10 -9
  359. meerk40t/network/tcp_server.py +142 -140
  360. meerk40t/network/udp_server.py +103 -77
  361. meerk40t/network/web_server.py +404 -0
  362. meerk40t/newly/controller.py +1158 -1144
  363. meerk40t/newly/device.py +874 -732
  364. meerk40t/newly/driver.py +540 -412
  365. meerk40t/newly/gui/gui.py +219 -188
  366. meerk40t/newly/gui/newlyconfig.py +116 -101
  367. meerk40t/newly/gui/newlycontroller.py +193 -186
  368. meerk40t/newly/gui/operationproperties.py +51 -51
  369. meerk40t/newly/mock_connection.py +82 -82
  370. meerk40t/newly/newly_params.py +56 -56
  371. meerk40t/newly/plugin.py +1214 -1246
  372. meerk40t/newly/usb_connection.py +322 -322
  373. meerk40t/rotary/gui/gui.py +52 -46
  374. meerk40t/rotary/gui/rotarysettings.py +240 -232
  375. meerk40t/rotary/rotary.py +202 -98
  376. meerk40t/ruida/control.py +291 -91
  377. meerk40t/ruida/controller.py +138 -1088
  378. meerk40t/ruida/device.py +676 -231
  379. meerk40t/ruida/driver.py +534 -472
  380. meerk40t/ruida/emulator.py +1494 -1491
  381. meerk40t/ruida/exceptions.py +4 -4
  382. meerk40t/ruida/gui/gui.py +71 -76
  383. meerk40t/ruida/gui/ruidaconfig.py +239 -72
  384. meerk40t/ruida/gui/ruidacontroller.py +187 -184
  385. meerk40t/ruida/gui/ruidaoperationproperties.py +48 -47
  386. meerk40t/ruida/loader.py +54 -52
  387. meerk40t/ruida/mock_connection.py +57 -109
  388. meerk40t/ruida/plugin.py +124 -87
  389. meerk40t/ruida/rdjob.py +2084 -945
  390. meerk40t/ruida/serial_connection.py +116 -0
  391. meerk40t/ruida/tcp_connection.py +146 -0
  392. meerk40t/ruida/udp_connection.py +73 -0
  393. meerk40t/svgelements.py +9671 -9669
  394. meerk40t/tools/driver_to_path.py +584 -579
  395. meerk40t/tools/geomstr.py +5583 -4680
  396. meerk40t/tools/jhfparser.py +357 -292
  397. meerk40t/tools/kerftest.py +904 -890
  398. meerk40t/tools/livinghinges.py +1168 -1033
  399. meerk40t/tools/pathtools.py +987 -949
  400. meerk40t/tools/pmatrix.py +234 -0
  401. meerk40t/tools/pointfinder.py +942 -942
  402. meerk40t/tools/polybool.py +941 -940
  403. meerk40t/tools/rasterplotter.py +1660 -547
  404. meerk40t/tools/shxparser.py +1047 -901
  405. meerk40t/tools/ttfparser.py +726 -446
  406. meerk40t/tools/zinglplotter.py +595 -593
  407. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/LICENSE +21 -21
  408. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/METADATA +150 -139
  409. meerk40t-0.9.7020.dist-info/RECORD +446 -0
  410. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/WHEEL +1 -1
  411. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/top_level.txt +0 -1
  412. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/zip-safe +1 -1
  413. meerk40t/balormk/elementlightjob.py +0 -159
  414. meerk40t-0.9.3001.dist-info/RECORD +0 -437
  415. test/bootstrap.py +0 -63
  416. test/test_cli.py +0 -12
  417. test/test_core_cutcode.py +0 -418
  418. test/test_core_elements.py +0 -144
  419. test/test_core_plotplanner.py +0 -397
  420. test/test_core_viewports.py +0 -312
  421. test/test_drivers_grbl.py +0 -108
  422. test/test_drivers_lihuiyu.py +0 -443
  423. test/test_drivers_newly.py +0 -113
  424. test/test_element_degenerate_points.py +0 -43
  425. test/test_elements_classify.py +0 -97
  426. test/test_elements_penbox.py +0 -22
  427. test/test_file_svg.py +0 -176
  428. test/test_fill.py +0 -155
  429. test/test_geomstr.py +0 -1523
  430. test/test_geomstr_nodes.py +0 -18
  431. test/test_imagetools_actualize.py +0 -306
  432. test/test_imagetools_wizard.py +0 -258
  433. test/test_kernel.py +0 -200
  434. test/test_laser_speeds.py +0 -3303
  435. test/test_length.py +0 -57
  436. test/test_lifecycle.py +0 -66
  437. test/test_operations.py +0 -251
  438. test/test_operations_hatch.py +0 -57
  439. test/test_ruida.py +0 -19
  440. test/test_spooler.py +0 -22
  441. test/test_tools_rasterplotter.py +0 -29
  442. test/test_wobble.py +0 -133
  443. test/test_zingl.py +0 -124
  444. {test → meerk40t/cylinder}/__init__.py +0 -0
  445. /meerk40t/{core/element_commands.py → cylinder/gui/__init__.py} +0 -0
  446. {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/entry_points.txt +0 -0
@@ -1,593 +1,595 @@
1
- from math import ceil, cos, floor, sin, sqrt, tan, tau
2
-
3
- from meerk40t.svgelements import Point
4
-
5
- """
6
- The Zingl-Bresenham plotting algorithms are from Alois Zingl's "The Beauty of Bresenham's Algorithm"
7
- ( http://members.chello.at/easyfilter/bresenham.html ).
8
-
9
- In the case of Zingl's work this isn't explicit from his website, however from personal
10
- correspondence "'Free and open source' means you can do anything with it like the MIT licence."
11
-
12
- The Zingl-Bresenham algorithms are provided in a static fashion and generate x and y locations.
13
-
14
- This work is MIT Licensed.
15
- """
16
-
17
-
18
- class ZinglPlotter:
19
- @staticmethod
20
- def plot_arc(arc):
21
- """
22
- Plots an arc by converting it into a series of cubic Bézier curves and plotting those instead.
23
-
24
- @param arc:
25
- @return:
26
- """
27
- # TODO: Should actually plot the arc according to the pixel-perfect standard.
28
- # TODO: In this case we would plot a Bernstein weighted bezier curve.
29
- sweep_limit = tau / 12
30
- arc_required = int(ceil(abs(arc.sweep) / sweep_limit))
31
- if arc_required == 0:
32
- return
33
- slice = arc.sweep / float(arc_required)
34
-
35
- theta = arc.get_rotation()
36
- rx = arc.rx
37
- ry = arc.ry
38
- p_start = arc.start
39
- current_t = arc.get_start_t()
40
- x0 = arc.center[0]
41
- y0 = arc.center[1]
42
- cos_theta = cos(theta)
43
- sin_theta = sin(theta)
44
-
45
- for i in range(0, arc_required):
46
- next_t = current_t + slice
47
-
48
- alpha = sin(slice) * (sqrt(4 + 3 * pow(tan(slice / 2.0), 2)) - 1) / 3.0
49
-
50
- cos_start_t = cos(current_t)
51
- sin_start_t = sin(current_t)
52
-
53
- ePrimen1x = -rx * cos_theta * sin_start_t - ry * sin_theta * cos_start_t
54
- ePrimen1y = -rx * sin_theta * sin_start_t + ry * cos_theta * cos_start_t
55
-
56
- cos_end_t = cos(next_t)
57
- sin_end_t = sin(next_t)
58
-
59
- p2En2x = x0 + rx * cos_end_t * cos_theta - ry * sin_end_t * sin_theta
60
- p2En2y = y0 + rx * cos_end_t * sin_theta + ry * sin_end_t * cos_theta
61
- p_end = (p2En2x, p2En2y)
62
- if i == arc_required - 1:
63
- p_end = arc.end
64
-
65
- ePrimen2x = -rx * cos_theta * sin_end_t - ry * sin_theta * cos_end_t
66
- ePrimen2y = -rx * sin_theta * sin_end_t + ry * cos_theta * cos_end_t
67
-
68
- p_c1 = (p_start[0] + alpha * ePrimen1x, p_start[1] + alpha * ePrimen1y)
69
- p_c2 = (p_end[0] - alpha * ePrimen2x, p_end[1] - alpha * ePrimen2y)
70
-
71
- yield from ZinglPlotter.plot_cubic_bezier(
72
- p_start[0],
73
- p_start[1],
74
- p_c1[0],
75
- p_c1[1],
76
- p_c2[0],
77
- p_c2[1],
78
- p_end[0],
79
- p_end[1],
80
- )
81
- p_start = Point(p_end)
82
- current_t = next_t
83
-
84
- @staticmethod
85
- def plot_line(x0, y0, x1, y1):
86
- """
87
- Zingl-Bresenham line draw algorithm
88
-
89
- yields x, y
90
- """
91
- x0 = int(x0)
92
- y0 = int(y0)
93
- x1 = int(x1)
94
- y1 = int(y1)
95
- dx = abs(x1 - x0)
96
- dy = -abs(y1 - y0)
97
-
98
- if x0 < x1:
99
- sx = 1
100
- else:
101
- sx = -1
102
- if y0 < y1:
103
- sy = 1
104
- else:
105
- sy = -1
106
-
107
- err = dx + dy # error value e_xy
108
-
109
- while True: # /* loop */
110
- yield x0, y0
111
- if x0 == x1 and y0 == y1:
112
- break
113
- e2 = 2 * err
114
- if e2 >= dy: # e_xy+e_y < 0
115
- err += dy
116
- x0 += sx
117
- if e2 <= dx: # e_xy+e_y < 0
118
- err += dx
119
- y0 += sy
120
-
121
- @staticmethod
122
- def plot_quad_bezier_seg(x0, y0, x1, y1, x2, y2):
123
- """plot a limited quadratic Bezier segment
124
-
125
- This algorithm can plot curves that do not inflect.
126
-
127
- This is used as part of the general algorithm, which breaks at the inflection point.
128
-
129
- yields x, y
130
- """
131
- sx = x2 - x1
132
- sy = y2 - y1
133
- xx = x0 - x1
134
- yy = y0 - y1
135
- xy = 0 # relative values for checks */
136
- dx = 0
137
- dy = 0
138
- err = 0
139
- cur = xx * sy - yy * sx # /* curvature */
140
- points = None
141
-
142
- assert xx * sx <= 0 and yy * sy <= 0 # /* sign of gradient must not change */
143
-
144
- if sx * sx + sy * sy > xx * xx + yy * yy: # /* begin with shorter part */
145
- x2 = x0
146
- x0 = sx + x1
147
- y2 = y0
148
- y0 = sy + y1
149
- cur = -cur # /* swap P0 P2 */
150
- points = []
151
- if cur != 0: # /* no straight line */
152
- xx += sx
153
- if x0 < x2:
154
- sx = 1 # /* x step direction */
155
- else:
156
- sx = -1 # /* x step direction */
157
- xx *= sx
158
- yy += sy
159
- if y0 < y2:
160
- sy = 1
161
- else:
162
- sy = -1
163
- yy *= sy # /* y step direction */
164
- xy = 2 * xx * yy
165
- xx *= xx
166
- yy *= yy # /* differences 2nd degree */
167
- if cur * sx * sy < 0: # /* negated curvature? */
168
- xx = -xx
169
- yy = -yy
170
- xy = -xy
171
- cur = -cur
172
- dx = 4.0 * sy * cur * (x1 - x0) + xx - xy # /* differences 1st degree */
173
- dy = 4.0 * sx * cur * (y0 - y1) + yy - xy
174
- xx += xx
175
- yy += yy
176
- err = dx + dy + xy # /* error 1st step */
177
- while True:
178
- if points is None:
179
- yield int(x0), int(y0) # /* plot curve */
180
- else:
181
- points.append((int(x0), int(y0)))
182
- if x0 == x2 and y0 == y2:
183
- if points is not None:
184
- for plot in reversed(points):
185
- yield plot
186
- return # /* last pixel -> curve finished */
187
- y1 = 2 * err < dx # /* save value for test of y step */
188
- if 2 * err > dy:
189
- x0 += sx
190
- dx -= xy
191
- dy += yy
192
- err += dy
193
- # /* x step */
194
- if y1 != 0:
195
- y0 += sy
196
- dy -= xy
197
- dx += xx
198
- err += dx
199
- # /* y step */
200
- if not (dy < 0 < dx): # /* gradient negates -> algorithm fails */
201
- break
202
- for plot in ZinglPlotter.plot_line(
203
- x0, y0, x2, y2
204
- ): # /* plot remaining part to end */:
205
- if points is None:
206
- yield plot # /* plot curve */
207
- else:
208
- points.append(
209
- plot
210
- ) # plotLine(x0,y0, x2,y2) #/* plot remaining part to end */
211
- if points is not None:
212
- for plot in reversed(points):
213
- yield plot
214
-
215
- @staticmethod
216
- def plot_quad_bezier(x0, y0, x1, y1, x2, y2):
217
- """
218
- Zingl-Bresenham quad bezier draw algorithm.
219
-
220
- Plot any quadratic Bezier curve
221
-
222
- yields x, y
223
- """
224
-
225
- x0 = int(x0)
226
- y0 = int(y0)
227
- # control points are permitted fractional elements.
228
- x2 = int(x2)
229
- y2 = int(y2)
230
- x = x0 - x1
231
- y = y0 - y1
232
- t = x0 - 2 * x1 + x2
233
- r = 0
234
- points = None
235
-
236
- if x * (x2 - x1) > 0: # /* horizontal cut at P4? */
237
- if y * (y2 - y1) > 0: # /* vertical cut at P6 too? */
238
- if abs((y0 - 2 * y1 + y2) / t * x) > abs(y): # /* which first? */
239
- x0 = x2
240
- x2 = x + x1
241
- y0 = y2
242
- y2 = y + y1 # /* swap points */
243
- points = []
244
- # /* now horizontal cut at P4 comes first */
245
- t = (x0 - x1) / t
246
- r = (1 - t) * ((1 - t) * y0 + 2.0 * t * y1) + t * t * y2 # /* By(t=P4) */
247
- t = (x0 * x2 - x1 * x1) * t / (x0 - x1) # /* gradient dP4/dx=0 */
248
- x = floor(t + 0.5)
249
- y = floor(r + 0.5)
250
- r = (y1 - y0) * (t - x0) / (x1 - x0) + y0 # /* intersect P3 | P0 P1 */
251
- for plot in ZinglPlotter.plot_quad_bezier_seg(
252
- x0, y0, x, floor(r + 0.5), x, y
253
- ):
254
- if points is None:
255
- yield plot
256
- else:
257
- points.append(plot)
258
- r = (y1 - y2) * (t - x2) / (x1 - x2) + y2 # /* intersect P4 | P1 P2 */
259
- x0 = x1 = x
260
- y0 = y
261
- y1 = floor(r + 0.5) # /* P0 = P4, P1 = P8 */
262
- if (y0 - y1) * (y2 - y1) > 0: # /* vertical cut at P6? */
263
- t = y0 - 2 * y1 + y2
264
- t = (y0 - y1) / t
265
- r = (1 - t) * ((1 - t) * x0 + 2.0 * t * x1) + t * t * x2 # /* Bx(t=P6) */
266
- t = (y0 * y2 - y1 * y1) * t / (y0 - y1) # /* gradient dP6/dy=0 */
267
- x = floor(r + 0.5)
268
- y = floor(t + 0.5)
269
- r = (x1 - x0) * (t - y0) / (y1 - y0) + x0 # /* intersect P6 | P0 P1 */
270
- for plot in ZinglPlotter.plot_quad_bezier_seg(
271
- x0, y0, floor(r + 0.5), y, x, y
272
- ):
273
- if points is None:
274
- yield plot
275
- else:
276
- points.append(plot)
277
- r = (x1 - x2) * (t - y2) / (y1 - y2) + x2 # /* intersect P7 | P1 P2 */
278
- x0 = x
279
- x1 = floor(r + 0.5)
280
- y0 = y1 = y # /* P0 = P6, P1 = P7 */
281
- for plot in ZinglPlotter.plot_quad_bezier_seg(
282
- x0, y0, x1, y1, x2, y2
283
- ): # /* remaining part */
284
- if points is None:
285
- yield plot
286
- else:
287
- points.append(plot)
288
- if points is not None:
289
- for plot in reversed(points):
290
- yield plot
291
-
292
- @staticmethod
293
- def plot_cubic_bezier_seg(x0, y0, x1, y1, x2, y2, x3, y3):
294
- """
295
- Plot limited cubic Bezier segment
296
-
297
- This algorithm can plot curves that do not inflect.
298
-
299
- It is used as part of the general algorithm, which breaks at the infection point(s)
300
-
301
- yields x, y
302
- """
303
- second_leg = []
304
- f = 0
305
- fx = 0
306
- fy = 0
307
- leg = 1
308
- if x0 < x3:
309
- sx = 1
310
- else:
311
- sx = -1
312
- if y0 < y3:
313
- sy = 1 # /* step direction */
314
- else:
315
- sy = -1 # /* step direction */
316
- xc = -abs(x0 + x1 - x2 - x3)
317
- xa = xc - 4 * sx * (x1 - x2)
318
- xb = sx * (x0 - x1 - x2 + x3)
319
- yc = -abs(y0 + y1 - y2 - y3)
320
- ya = yc - 4 * sy * (y1 - y2)
321
- yb = sy * (y0 - y1 - y2 + y3)
322
- ab = 0
323
- ac = 0
324
- bc = 0
325
- cb = 0
326
- xx = 0
327
- xy = 0
328
- yy = 0
329
- dx = 0
330
- dy = 0
331
- ex = 0
332
- pxy = 0
333
- EP = 0.01
334
- # /* check for curve restrains */
335
- # /* slope P0-P1 == P2-P3 and (P0-P3 == P1-P2 or no slope change)
336
- # if (x1 - x0) * (x2 - x3) < EP and ((x3 - x0) * (x1 - x2) < EP or xb * xb < xa * xc + EP):
337
- # return
338
- # if (y1 - y0) * (y2 - y3) < EP and ((y3 - y0) * (y1 - y2) < EP or yb * yb < ya * yc + EP):
339
- # return
340
-
341
- if xa == 0 and ya == 0: # /* quadratic Bezier */
342
- # return plot_quad_bezier_seg(x0, y0, (3 * x1 - x0) >> 1, (3 * y1 - y0) >> 1, x3, y3)
343
- sx = floor((3 * x1 - x0 + 1) / 2)
344
- sy = floor((3 * y1 - y0 + 1) / 2) # /* new midpoint */
345
-
346
- for plot in ZinglPlotter.plot_quad_bezier_seg(x0, y0, sx, sy, x3, y3):
347
- yield plot
348
- return
349
- x1 = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + 1 # /* line lengths */
350
- x2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3) + 1
351
-
352
- while True: # /* loop over both ends */
353
- ab = xa * yb - xb * ya
354
- ac = xa * yc - xc * ya
355
- bc = xb * yc - xc * yb
356
- ex = (
357
- ab * (ab + ac - 3 * bc) + ac * ac
358
- ) # /* P0 part of self-intersection loop? */
359
- if ex > 0:
360
- f = 1 # /* calc resolution */
361
- else:
362
- f = floor(sqrt(1 + 1024 / x1)) # /* calc resolution */
363
- ab *= f
364
- ac *= f
365
- bc *= f
366
- ex *= f * f # /* increase resolution */
367
- xy = 9 * (ab + ac + bc) / 8
368
- cb = 8 * (xa - ya) # /* init differences of 1st degree */
369
- dx = 27 * (
370
- 8 * ab * (yb * yb - ya * yc) + ex * (ya + 2 * yb + yc)
371
- ) / 64 - ya * ya * (xy - ya)
372
- dy = 27 * (
373
- 8 * ab * (xb * xb - xa * xc) - ex * (xa + 2 * xb + xc)
374
- ) / 64 - xa * xa * (xy + xa)
375
- # /* init differences of 2nd degree */
376
- xx = (
377
- 3
378
- * (
379
- 3 * ab * (3 * yb * yb - ya * ya - 2 * ya * yc)
380
- - ya * (3 * ac * (ya + yb) + ya * cb)
381
- )
382
- / 4
383
- )
384
- yy = (
385
- 3
386
- * (
387
- 3 * ab * (3 * xb * xb - xa * xa - 2 * xa * xc)
388
- - xa * (3 * ac * (xa + xb) + xa * cb)
389
- )
390
- / 4
391
- )
392
- xy = xa * ya * (6 * ab + 6 * ac - 3 * bc + cb)
393
- ac = ya * ya
394
- cb = xa * xa
395
- xy = (
396
- 3 * (xy + 9 * f * (cb * yb * yc - xb * xc * ac) - 18 * xb * yb * ab) / 8
397
- )
398
-
399
- if ex < 0: # /* negate values if inside self-intersection loop */
400
- dx = -dx
401
- dy = -dy
402
- xx = -xx
403
- yy = -yy
404
- xy = -xy
405
- ac = -ac
406
- cb = -cb # /* init differences of 3rd degree */
407
- ab = 6 * ya * ac
408
- ac = -6 * xa * ac
409
- bc = 6 * ya * cb
410
- cb = -6 * xa * cb
411
- dx += xy
412
- ex = dx + dy
413
- dy += xy # /* error of 1st step */
414
- try:
415
- pxy = 0
416
- fx = fy = f
417
- while x0 != x3 and y0 != y3:
418
- if leg == 0:
419
- second_leg.append((x0, y0)) # /* plot curve */
420
- else:
421
- yield x0, y0 # /* plot curve */
422
- while True: # /* move sub-steps of one pixel */
423
- if pxy == 0:
424
- if dx > xy or dy < xy:
425
- raise StopIteration # /* confusing */
426
- if pxy == 1:
427
- if dx > 0 or dy < 0:
428
- raise StopIteration # /* values */
429
- y1 = 2 * ex - dy # /* save value for test of y step */
430
- if 2 * ex >= dx: # /* x sub-step */
431
- fx -= 1
432
- dx += xx
433
- ex += dx
434
- xy += ac
435
- dy += xy
436
- yy += bc
437
- xx += ab
438
- elif y1 > 0:
439
- raise StopIteration
440
- if y1 <= 0: # /* y sub-step */
441
- fy -= 1
442
- dy += yy
443
- ex += dy
444
- xy += bc
445
- dx += xy
446
- xx += ac
447
- yy += cb
448
- if not (fx > 0 and fy > 0): # /* pixel complete? */
449
- break
450
- if 2 * fx <= f:
451
- x0 += sx
452
- fx += f # /* x step */
453
- if 2 * fy <= f:
454
- y0 += sy
455
- fy += f # /* y step */
456
- if pxy == 0 and dx < 0 and dy > 0:
457
- pxy = 1 # /* pixel ahead valid */
458
- except StopIteration:
459
- pass
460
- xx = x0
461
- x0 = x3
462
- x3 = xx
463
- sx = -sx
464
- xb = -xb # /* swap legs */
465
- yy = y0
466
- y0 = y3
467
- y3 = yy
468
- sy = -sy
469
- yb = -yb
470
- x1 = x2
471
- if not (leg != 0):
472
- break
473
- leg -= 1 # /* try other end */
474
- for plot in ZinglPlotter.plot_line(
475
- x3, y3, x0, y0
476
- ): # /* remaining part in case of cusp or crunode */
477
- second_leg.append(plot)
478
- for plot in reversed(second_leg):
479
- yield plot
480
-
481
- @staticmethod
482
- def plot_cubic_bezier(x0, y0, x1, y1, x2, y2, x3, y3):
483
- """
484
- Zingl-Bresenham cubic bezier draw algorithm
485
-
486
- Plot any quadratic Bezier curve
487
-
488
- yields x, y
489
- """
490
- x0 = int(x0)
491
- y0 = int(y0)
492
- # control points are permitted fractional elements.
493
- x3 = int(x3)
494
- y3 = int(y3)
495
- n = 0
496
- i = 0
497
- xc = x0 + x1 - x2 - x3
498
- xa = xc - 4 * (x1 - x2)
499
- xb = x0 - x1 - x2 + x3
500
- xd = xb + 4 * (x1 + x2)
501
- yc = y0 + y1 - y2 - y3
502
- ya = yc - 4 * (y1 - y2)
503
- yb = y0 - y1 - y2 + y3
504
- yd = yb + 4 * (y1 + y2)
505
- fx0 = x0
506
- fx1 = 0
507
- fx2 = 0
508
- fx3 = 0
509
- fy0 = y0
510
- fy1 = 0
511
- fy2 = 0
512
- fy3 = 0
513
- t1 = xb * xb - xa * xc
514
- t2 = 0
515
- t = [0] * 5
516
- # /* sub-divide curve at gradient sign changes */
517
- if xa == 0: # /* horizontal */
518
- if abs(xc) < 2 * abs(xb):
519
- t[n] = xc / (2.0 * xb) # /* one change */
520
- n += 1
521
- elif t1 > 0.0: # /* two changes */
522
- t2 = sqrt(t1)
523
- t1 = (xb - t2) / xa
524
- if abs(t1) < 1.0:
525
- t[n] = t1
526
- n += 1
527
- t1 = (xb + t2) / xa
528
- if abs(t1) < 1.0:
529
- t[n] = t1
530
- n += 1
531
- t1 = yb * yb - ya * yc
532
- if ya == 0: # /* vertical */
533
- if abs(yc) < 2 * abs(yb):
534
- t[n] = yc / (2.0 * yb) # /* one change */
535
- n += 1
536
- elif t1 > 0.0: # /* two changes */
537
- t2 = sqrt(t1)
538
- t1 = (yb - t2) / ya
539
- if abs(t1) < 1.0:
540
- t[n] = t1
541
- n += 1
542
- t1 = (yb + t2) / ya
543
- if abs(t1) < 1.0:
544
- t[n] = t1
545
- n += 1
546
- i = 1
547
- while i < n: # /* bubble sort of 4 points */
548
- t1 = t[i - 1]
549
- if t1 > t[i]:
550
- t[i - 1] = t[i]
551
- t[i] = t1
552
- i = 0
553
- i += 1
554
- t1 = -1.0
555
- t[n] = 1.0 # /* begin / end point */
556
- for i in range(0, n + 1): # /* plot each segment separately */
557
- t2 = t[i] # /* sub-divide at t[i-1], t[i] */
558
- fx1 = (
559
- t1 * (t1 * xb - 2 * xc) - t2 * (t1 * (t1 * xa - 2 * xb) + xc) + xd
560
- ) / 8 - fx0
561
- fy1 = (
562
- t1 * (t1 * yb - 2 * yc) - t2 * (t1 * (t1 * ya - 2 * yb) + yc) + yd
563
- ) / 8 - fy0
564
- fx2 = (
565
- t2 * (t2 * xb - 2 * xc) - t1 * (t2 * (t2 * xa - 2 * xb) + xc) + xd
566
- ) / 8 - fx0
567
- fy2 = (
568
- t2 * (t2 * yb - 2 * yc) - t1 * (t2 * (t2 * ya - 2 * yb) + yc) + yd
569
- ) / 8 - fy0
570
- fx3 = (t2 * (t2 * (3 * xb - t2 * xa) - 3 * xc) + xd) / 8
571
- fx0 -= fx3
572
- fy3 = (t2 * (t2 * (3 * yb - t2 * ya) - 3 * yc) + yd) / 8
573
- fy0 -= fy3
574
- x3 = floor(fx3 + 0.5)
575
- y3 = floor(fy3 + 0.5) # /* scale bounds */
576
- if fx0 != 0.0:
577
- fx0 = (x0 - x3) / fx0
578
- fx1 *= fx0
579
- fx2 *= fx0
580
- if fy0 != 0.0:
581
- fy0 = (y0 - y3) / fy0
582
- fy1 *= fy0
583
- fy2 *= fy0
584
- if x0 != x3 or y0 != y3: # /* segment t1 - t2 */
585
- # plotCubicBezierSeg(x0,y0, x0+fx1,y0+fy1, x0+fx2,y0+fy2, x3,y3)
586
- yield from ZinglPlotter.plot_cubic_bezier_seg(
587
- x0, y0, x0 + fx1, y0 + fy1, x0 + fx2, y0 + fy2, x3, y3
588
- )
589
- x0 = x3
590
- y0 = y3
591
- fx0 = fx3
592
- fy0 = fy3
593
- t1 = t2
1
+ from math import ceil, cos, floor, sin, sqrt, tan, tau
2
+
3
+ from meerk40t.svgelements import Point
4
+
5
+ """
6
+ The Zingl-Bresenham plotting algorithms are from Alois Zingl's "The Beauty of Bresenham's Algorithm"
7
+ ( http://members.chello.at/easyfilter/bresenham.html ).
8
+
9
+ In the case of Zingl's work this isn't explicit from his website, however from personal
10
+ correspondence "'Free and open source' means you can do anything with it like the MIT licence."
11
+
12
+ The Zingl-Bresenham algorithms are provided in a static fashion and generate x and y locations.
13
+
14
+ This work is MIT Licensed.
15
+ """
16
+
17
+
18
+ class ZinglPlotter:
19
+ @staticmethod
20
+ def plot_arc(arc):
21
+ """
22
+ Plots an arc by converting it into a series of cubic Bézier curves and plotting those instead.
23
+
24
+ @param arc:
25
+ @return:
26
+ """
27
+ # TODO: Should actually plot the arc according to the pixel-perfect standard.
28
+ # TODO: In this case we would plot a Bernstein weighted bezier curve.
29
+ sweep_limit = tau / 12
30
+ arc_required = int(ceil(abs(arc.sweep) / sweep_limit))
31
+ if arc_required == 0:
32
+ return
33
+ arc_slice = arc.sweep / float(arc_required)
34
+
35
+ theta = arc.get_rotation()
36
+ rx = arc.rx
37
+ ry = arc.ry
38
+ p_start = arc.start
39
+ current_t = arc.get_start_t()
40
+ x0 = arc.center[0]
41
+ y0 = arc.center[1]
42
+ cos_theta = cos(theta)
43
+ sin_theta = sin(theta)
44
+
45
+ for i in range(0, arc_required):
46
+ next_t = current_t + arc_slice
47
+
48
+ alpha = (
49
+ sin(arc_slice) * (sqrt(4 + 3 * pow(tan(arc_slice / 2.0), 2)) - 1) / 3.0
50
+ )
51
+
52
+ cos_start_t = cos(current_t)
53
+ sin_start_t = sin(current_t)
54
+
55
+ ePrimen1x = -rx * cos_theta * sin_start_t - ry * sin_theta * cos_start_t
56
+ ePrimen1y = -rx * sin_theta * sin_start_t + ry * cos_theta * cos_start_t
57
+
58
+ cos_end_t = cos(next_t)
59
+ sin_end_t = sin(next_t)
60
+
61
+ p2En2x = x0 + rx * cos_end_t * cos_theta - ry * sin_end_t * sin_theta
62
+ p2En2y = y0 + rx * cos_end_t * sin_theta + ry * sin_end_t * cos_theta
63
+ p_end = (p2En2x, p2En2y)
64
+ if i == arc_required - 1:
65
+ p_end = arc.end
66
+
67
+ ePrimen2x = -rx * cos_theta * sin_end_t - ry * sin_theta * cos_end_t
68
+ ePrimen2y = -rx * sin_theta * sin_end_t + ry * cos_theta * cos_end_t
69
+
70
+ p_c1 = (p_start[0] + alpha * ePrimen1x, p_start[1] + alpha * ePrimen1y)
71
+ p_c2 = (p_end[0] - alpha * ePrimen2x, p_end[1] - alpha * ePrimen2y)
72
+
73
+ yield from ZinglPlotter.plot_cubic_bezier(
74
+ p_start[0],
75
+ p_start[1],
76
+ p_c1[0],
77
+ p_c1[1],
78
+ p_c2[0],
79
+ p_c2[1],
80
+ p_end[0],
81
+ p_end[1],
82
+ )
83
+ p_start = Point(p_end)
84
+ current_t = next_t
85
+
86
+ @staticmethod
87
+ def plot_line(x0, y0, x1, y1):
88
+ """
89
+ Zingl-Bresenham line draw algorithm
90
+
91
+ yields x, y
92
+ """
93
+ x0 = int(x0)
94
+ y0 = int(y0)
95
+ x1 = int(x1)
96
+ y1 = int(y1)
97
+ dx = abs(x1 - x0)
98
+ dy = -abs(y1 - y0)
99
+
100
+ if x0 < x1:
101
+ sx = 1
102
+ else:
103
+ sx = -1
104
+ if y0 < y1:
105
+ sy = 1
106
+ else:
107
+ sy = -1
108
+
109
+ err = dx + dy # error value e_xy
110
+
111
+ while True: # /* loop */
112
+ yield x0, y0
113
+ if x0 == x1 and y0 == y1:
114
+ break
115
+ e2 = 2 * err
116
+ if e2 >= dy: # e_xy+e_y < 0
117
+ err += dy
118
+ x0 += sx
119
+ if e2 <= dx: # e_xy+e_y < 0
120
+ err += dx
121
+ y0 += sy
122
+
123
+ @staticmethod
124
+ def plot_quad_bezier_seg(x0, y0, x1, y1, x2, y2):
125
+ """plot a limited quadratic Bezier segment
126
+
127
+ This algorithm can plot curves that do not inflect.
128
+
129
+ This is used as part of the general algorithm, which breaks at the inflection point.
130
+
131
+ yields x, y
132
+ """
133
+ sx = x2 - x1
134
+ sy = y2 - y1
135
+ xx = x0 - x1
136
+ yy = y0 - y1
137
+ xy = 0 # relative values for checks */
138
+ dx = 0
139
+ dy = 0
140
+ err = 0
141
+ cur = xx * sy - yy * sx # /* curvature */
142
+ points = None
143
+
144
+ assert xx * sx <= 0 and yy * sy <= 0 # /* sign of gradient must not change */
145
+
146
+ if sx * sx + sy * sy > xx * xx + yy * yy: # /* begin with shorter part */
147
+ x2 = x0
148
+ x0 = sx + x1
149
+ y2 = y0
150
+ y0 = sy + y1
151
+ cur = -cur # /* swap P0 P2 */
152
+ points = []
153
+ if cur != 0: # /* no straight line */
154
+ xx += sx
155
+ if x0 < x2:
156
+ sx = 1 # /* x step direction */
157
+ else:
158
+ sx = -1 # /* x step direction */
159
+ xx *= sx
160
+ yy += sy
161
+ if y0 < y2:
162
+ sy = 1
163
+ else:
164
+ sy = -1
165
+ yy *= sy # /* y step direction */
166
+ xy = 2 * xx * yy
167
+ xx *= xx
168
+ yy *= yy # /* differences 2nd degree */
169
+ if cur * sx * sy < 0: # /* negated curvature? */
170
+ xx = -xx
171
+ yy = -yy
172
+ xy = -xy
173
+ cur = -cur
174
+ dx = 4.0 * sy * cur * (x1 - x0) + xx - xy # /* differences 1st degree */
175
+ dy = 4.0 * sx * cur * (y0 - y1) + yy - xy
176
+ xx += xx
177
+ yy += yy
178
+ err = dx + dy + xy # /* error 1st step */
179
+ while True:
180
+ if points is None:
181
+ yield int(x0), int(y0) # /* plot curve */
182
+ else:
183
+ points.append((int(x0), int(y0)))
184
+ if x0 == x2 and y0 == y2:
185
+ if points is not None:
186
+ for plot in reversed(points):
187
+ yield plot
188
+ return # /* last pixel -> curve finished */
189
+ y1 = 2 * err < dx # /* save value for test of y step */
190
+ if 2 * err > dy:
191
+ x0 += sx
192
+ dx -= xy
193
+ dy += yy
194
+ err += dy
195
+ # /* x step */
196
+ if y1 != 0:
197
+ y0 += sy
198
+ dy -= xy
199
+ dx += xx
200
+ err += dx
201
+ # /* y step */
202
+ if not (dy < 0 < dx): # /* gradient negates -> algorithm fails */
203
+ break
204
+ for plot in ZinglPlotter.plot_line(
205
+ x0, y0, x2, y2
206
+ ): # /* plot remaining part to end */:
207
+ if points is None:
208
+ yield plot # /* plot curve */
209
+ else:
210
+ points.append(
211
+ plot
212
+ ) # plotLine(x0,y0, x2,y2) #/* plot remaining part to end */
213
+ if points is not None:
214
+ for plot in reversed(points):
215
+ yield plot
216
+
217
+ @staticmethod
218
+ def plot_quad_bezier(x0, y0, x1, y1, x2, y2):
219
+ """
220
+ Zingl-Bresenham quad bezier draw algorithm.
221
+
222
+ Plot any quadratic Bezier curve
223
+
224
+ yields x, y
225
+ """
226
+
227
+ x0 = int(x0)
228
+ y0 = int(y0)
229
+ # control points are permitted fractional elements.
230
+ x2 = int(x2)
231
+ y2 = int(y2)
232
+ x = x0 - x1
233
+ y = y0 - y1
234
+ t = x0 - 2 * x1 + x2
235
+ r = 0
236
+ points = None
237
+
238
+ if x * (x2 - x1) > 0: # /* horizontal cut at P4? */
239
+ if y * (y2 - y1) > 0: # /* vertical cut at P6 too? */
240
+ if abs((y0 - 2 * y1 + y2) / t * x) > abs(y): # /* which first? */
241
+ x0 = x2
242
+ x2 = x + x1
243
+ y0 = y2
244
+ y2 = y + y1 # /* swap points */
245
+ points = []
246
+ # /* now horizontal cut at P4 comes first */
247
+ t = (x0 - x1) / t
248
+ r = (1 - t) * ((1 - t) * y0 + 2.0 * t * y1) + t * t * y2 # /* By(t=P4) */
249
+ t = (x0 * x2 - x1 * x1) * t / (x0 - x1) # /* gradient dP4/dx=0 */
250
+ x = floor(t + 0.5)
251
+ y = floor(r + 0.5)
252
+ r = (y1 - y0) * (t - x0) / (x1 - x0) + y0 # /* intersect P3 | P0 P1 */
253
+ for plot in ZinglPlotter.plot_quad_bezier_seg(
254
+ x0, y0, x, floor(r + 0.5), x, y
255
+ ):
256
+ if points is None:
257
+ yield plot
258
+ else:
259
+ points.append(plot)
260
+ r = (y1 - y2) * (t - x2) / (x1 - x2) + y2 # /* intersect P4 | P1 P2 */
261
+ x0 = x1 = x
262
+ y0 = y
263
+ y1 = floor(r + 0.5) # /* P0 = P4, P1 = P8 */
264
+ if (y0 - y1) * (y2 - y1) > 0: # /* vertical cut at P6? */
265
+ t = y0 - 2 * y1 + y2
266
+ t = (y0 - y1) / t
267
+ r = (1 - t) * ((1 - t) * x0 + 2.0 * t * x1) + t * t * x2 # /* Bx(t=P6) */
268
+ t = (y0 * y2 - y1 * y1) * t / (y0 - y1) # /* gradient dP6/dy=0 */
269
+ x = floor(r + 0.5)
270
+ y = floor(t + 0.5)
271
+ r = (x1 - x0) * (t - y0) / (y1 - y0) + x0 # /* intersect P6 | P0 P1 */
272
+ for plot in ZinglPlotter.plot_quad_bezier_seg(
273
+ x0, y0, floor(r + 0.5), y, x, y
274
+ ):
275
+ if points is None:
276
+ yield plot
277
+ else:
278
+ points.append(plot)
279
+ r = (x1 - x2) * (t - y2) / (y1 - y2) + x2 # /* intersect P7 | P1 P2 */
280
+ x0 = x
281
+ x1 = floor(r + 0.5)
282
+ y0 = y1 = y # /* P0 = P6, P1 = P7 */
283
+ for plot in ZinglPlotter.plot_quad_bezier_seg(
284
+ x0, y0, x1, y1, x2, y2
285
+ ): # /* remaining part */
286
+ if points is None:
287
+ yield plot
288
+ else:
289
+ points.append(plot)
290
+ if points is not None:
291
+ for plot in reversed(points):
292
+ yield plot
293
+
294
+ @staticmethod
295
+ def plot_cubic_bezier_seg(x0, y0, x1, y1, x2, y2, x3, y3):
296
+ """
297
+ Plot limited cubic Bezier segment
298
+
299
+ This algorithm can plot curves that do not inflect.
300
+
301
+ It is used as part of the general algorithm, which breaks at the infection point(s)
302
+
303
+ yields x, y
304
+ """
305
+ second_leg = []
306
+ f = 0
307
+ fx = 0
308
+ fy = 0
309
+ leg = 1
310
+ if x0 < x3:
311
+ sx = 1
312
+ else:
313
+ sx = -1
314
+ if y0 < y3:
315
+ sy = 1 # /* step direction */
316
+ else:
317
+ sy = -1 # /* step direction */
318
+ xc = -abs(x0 + x1 - x2 - x3)
319
+ xa = xc - 4 * sx * (x1 - x2)
320
+ xb = sx * (x0 - x1 - x2 + x3)
321
+ yc = -abs(y0 + y1 - y2 - y3)
322
+ ya = yc - 4 * sy * (y1 - y2)
323
+ yb = sy * (y0 - y1 - y2 + y3)
324
+ ab = 0
325
+ ac = 0
326
+ bc = 0
327
+ cb = 0
328
+ xx = 0
329
+ xy = 0
330
+ yy = 0
331
+ dx = 0
332
+ dy = 0
333
+ ex = 0
334
+ pxy = 0
335
+ EP = 0.01
336
+ # /* check for curve restrains */
337
+ # /* slope P0-P1 == P2-P3 and (P0-P3 == P1-P2 or no slope change)
338
+ # if (x1 - x0) * (x2 - x3) < EP and ((x3 - x0) * (x1 - x2) < EP or xb * xb < xa * xc + EP):
339
+ # return
340
+ # if (y1 - y0) * (y2 - y3) < EP and ((y3 - y0) * (y1 - y2) < EP or yb * yb < ya * yc + EP):
341
+ # return
342
+
343
+ if xa == 0 and ya == 0: # /* quadratic Bezier */
344
+ # return plot_quad_bezier_seg(x0, y0, (3 * x1 - x0) >> 1, (3 * y1 - y0) >> 1, x3, y3)
345
+ sx = floor((3 * x1 - x0 + 1) / 2)
346
+ sy = floor((3 * y1 - y0 + 1) / 2) # /* new midpoint */
347
+
348
+ for plot in ZinglPlotter.plot_quad_bezier_seg(x0, y0, sx, sy, x3, y3):
349
+ yield plot
350
+ return
351
+ x1 = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + 1 # /* line lengths */
352
+ x2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3) + 1
353
+
354
+ while True: # /* loop over both ends */
355
+ ab = xa * yb - xb * ya
356
+ ac = xa * yc - xc * ya
357
+ bc = xb * yc - xc * yb
358
+ ex = (
359
+ ab * (ab + ac - 3 * bc) + ac * ac
360
+ ) # /* P0 part of self-intersection loop? */
361
+ if ex > 0:
362
+ f = 1 # /* calc resolution */
363
+ else:
364
+ f = floor(sqrt(1 + 1024 / x1)) # /* calc resolution */
365
+ ab *= f
366
+ ac *= f
367
+ bc *= f
368
+ ex *= f * f # /* increase resolution */
369
+ xy = 9 * (ab + ac + bc) / 8
370
+ cb = 8 * (xa - ya) # /* init differences of 1st degree */
371
+ dx = 27 * (
372
+ 8 * ab * (yb * yb - ya * yc) + ex * (ya + 2 * yb + yc)
373
+ ) / 64 - ya * ya * (xy - ya)
374
+ dy = 27 * (
375
+ 8 * ab * (xb * xb - xa * xc) - ex * (xa + 2 * xb + xc)
376
+ ) / 64 - xa * xa * (xy + xa)
377
+ # /* init differences of 2nd degree */
378
+ xx = (
379
+ 3
380
+ * (
381
+ 3 * ab * (3 * yb * yb - ya * ya - 2 * ya * yc)
382
+ - ya * (3 * ac * (ya + yb) + ya * cb)
383
+ )
384
+ / 4
385
+ )
386
+ yy = (
387
+ 3
388
+ * (
389
+ 3 * ab * (3 * xb * xb - xa * xa - 2 * xa * xc)
390
+ - xa * (3 * ac * (xa + xb) + xa * cb)
391
+ )
392
+ / 4
393
+ )
394
+ xy = xa * ya * (6 * ab + 6 * ac - 3 * bc + cb)
395
+ ac = ya * ya
396
+ cb = xa * xa
397
+ xy = (
398
+ 3 * (xy + 9 * f * (cb * yb * yc - xb * xc * ac) - 18 * xb * yb * ab) / 8
399
+ )
400
+
401
+ if ex < 0: # /* negate values if inside self-intersection loop */
402
+ dx = -dx
403
+ dy = -dy
404
+ xx = -xx
405
+ yy = -yy
406
+ xy = -xy
407
+ ac = -ac
408
+ cb = -cb # /* init differences of 3rd degree */
409
+ ab = 6 * ya * ac
410
+ ac = -6 * xa * ac
411
+ bc = 6 * ya * cb
412
+ cb = -6 * xa * cb
413
+ dx += xy
414
+ ex = dx + dy
415
+ dy += xy # /* error of 1st step */
416
+ try:
417
+ pxy = 0
418
+ fx = fy = f
419
+ while x0 != x3 and y0 != y3:
420
+ if leg == 0:
421
+ second_leg.append((x0, y0)) # /* plot curve */
422
+ else:
423
+ yield x0, y0 # /* plot curve */
424
+ while True: # /* move sub-steps of one pixel */
425
+ if pxy == 0:
426
+ if dx > xy or dy < xy:
427
+ raise StopIteration # /* confusing */
428
+ if pxy == 1:
429
+ if dx > 0 or dy < 0:
430
+ raise StopIteration # /* values */
431
+ y1 = 2 * ex - dy # /* save value for test of y step */
432
+ if 2 * ex >= dx: # /* x sub-step */
433
+ fx -= 1
434
+ dx += xx
435
+ ex += dx
436
+ xy += ac
437
+ dy += xy
438
+ yy += bc
439
+ xx += ab
440
+ elif y1 > 0:
441
+ raise StopIteration
442
+ if y1 <= 0: # /* y sub-step */
443
+ fy -= 1
444
+ dy += yy
445
+ ex += dy
446
+ xy += bc
447
+ dx += xy
448
+ xx += ac
449
+ yy += cb
450
+ if not (fx > 0 and fy > 0): # /* pixel complete? */
451
+ break
452
+ if 2 * fx <= f:
453
+ x0 += sx
454
+ fx += f # /* x step */
455
+ if 2 * fy <= f:
456
+ y0 += sy
457
+ fy += f # /* y step */
458
+ if pxy == 0 and dx < 0 and dy > 0:
459
+ pxy = 1 # /* pixel ahead valid */
460
+ except StopIteration:
461
+ pass
462
+ xx = x0
463
+ x0 = x3
464
+ x3 = xx
465
+ sx = -sx
466
+ xb = -xb # /* swap legs */
467
+ yy = y0
468
+ y0 = y3
469
+ y3 = yy
470
+ sy = -sy
471
+ yb = -yb
472
+ x1 = x2
473
+ if not (leg != 0):
474
+ break
475
+ leg -= 1 # /* try other end */
476
+ for plot in ZinglPlotter.plot_line(
477
+ x3, y3, x0, y0
478
+ ): # /* remaining part in case of cusp or crunode */
479
+ second_leg.append(plot)
480
+ for plot in reversed(second_leg):
481
+ yield plot
482
+
483
+ @staticmethod
484
+ def plot_cubic_bezier(x0, y0, x1, y1, x2, y2, x3, y3):
485
+ """
486
+ Zingl-Bresenham cubic bezier draw algorithm
487
+
488
+ Plot any quadratic Bezier curve
489
+
490
+ yields x, y
491
+ """
492
+ x0 = int(x0)
493
+ y0 = int(y0)
494
+ # control points are permitted fractional elements.
495
+ x3 = int(x3)
496
+ y3 = int(y3)
497
+ n = 0
498
+ i = 0
499
+ xc = x0 + x1 - x2 - x3
500
+ xa = xc - 4 * (x1 - x2)
501
+ xb = x0 - x1 - x2 + x3
502
+ xd = xb + 4 * (x1 + x2)
503
+ yc = y0 + y1 - y2 - y3
504
+ ya = yc - 4 * (y1 - y2)
505
+ yb = y0 - y1 - y2 + y3
506
+ yd = yb + 4 * (y1 + y2)
507
+ fx0 = x0
508
+ fx1 = 0
509
+ fx2 = 0
510
+ fx3 = 0
511
+ fy0 = y0
512
+ fy1 = 0
513
+ fy2 = 0
514
+ fy3 = 0
515
+ t1 = xb * xb - xa * xc
516
+ t2 = 0
517
+ t = [0] * 5
518
+ # /* sub-divide curve at gradient sign changes */
519
+ if xa == 0: # /* horizontal */
520
+ if abs(xc) < 2 * abs(xb):
521
+ t[n] = xc / (2.0 * xb) # /* one change */
522
+ n += 1
523
+ elif t1 > 0.0: # /* two changes */
524
+ t2 = sqrt(t1)
525
+ t1 = (xb - t2) / xa
526
+ if abs(t1) < 1.0:
527
+ t[n] = t1
528
+ n += 1
529
+ t1 = (xb + t2) / xa
530
+ if abs(t1) < 1.0:
531
+ t[n] = t1
532
+ n += 1
533
+ t1 = yb * yb - ya * yc
534
+ if ya == 0: # /* vertical */
535
+ if abs(yc) < 2 * abs(yb):
536
+ t[n] = yc / (2.0 * yb) # /* one change */
537
+ n += 1
538
+ elif t1 > 0.0: # /* two changes */
539
+ t2 = sqrt(t1)
540
+ t1 = (yb - t2) / ya
541
+ if abs(t1) < 1.0:
542
+ t[n] = t1
543
+ n += 1
544
+ t1 = (yb + t2) / ya
545
+ if abs(t1) < 1.0:
546
+ t[n] = t1
547
+ n += 1
548
+ i = 1
549
+ while i < n: # /* bubble sort of 4 points */
550
+ t1 = t[i - 1]
551
+ if t1 > t[i]:
552
+ t[i - 1] = t[i]
553
+ t[i] = t1
554
+ i = 0
555
+ i += 1
556
+ t1 = -1.0
557
+ t[n] = 1.0 # /* begin / end point */
558
+ for i in range(0, n + 1): # /* plot each segment separately */
559
+ t2 = t[i] # /* sub-divide at t[i-1], t[i] */
560
+ fx1 = (
561
+ t1 * (t1 * xb - 2 * xc) - t2 * (t1 * (t1 * xa - 2 * xb) + xc) + xd
562
+ ) / 8 - fx0
563
+ fy1 = (
564
+ t1 * (t1 * yb - 2 * yc) - t2 * (t1 * (t1 * ya - 2 * yb) + yc) + yd
565
+ ) / 8 - fy0
566
+ fx2 = (
567
+ t2 * (t2 * xb - 2 * xc) - t1 * (t2 * (t2 * xa - 2 * xb) + xc) + xd
568
+ ) / 8 - fx0
569
+ fy2 = (
570
+ t2 * (t2 * yb - 2 * yc) - t1 * (t2 * (t2 * ya - 2 * yb) + yc) + yd
571
+ ) / 8 - fy0
572
+ fx3 = (t2 * (t2 * (3 * xb - t2 * xa) - 3 * xc) + xd) / 8
573
+ fx0 -= fx3
574
+ fy3 = (t2 * (t2 * (3 * yb - t2 * ya) - 3 * yc) + yd) / 8
575
+ fy0 -= fy3
576
+ x3 = floor(fx3 + 0.5)
577
+ y3 = floor(fy3 + 0.5) # /* scale bounds */
578
+ if fx0 != 0.0:
579
+ fx0 = (x0 - x3) / fx0
580
+ fx1 *= fx0
581
+ fx2 *= fx0
582
+ if fy0 != 0.0:
583
+ fy0 = (y0 - y3) / fy0
584
+ fy1 *= fy0
585
+ fy2 *= fy0
586
+ if x0 != x3 or y0 != y3: # /* segment t1 - t2 */
587
+ # plotCubicBezierSeg(x0,y0, x0+fx1,y0+fy1, x0+fx2,y0+fy2, x3,y3)
588
+ yield from ZinglPlotter.plot_cubic_bezier_seg(
589
+ x0, y0, x0 + fx1, y0 + fy1, x0 + fx2, y0 + fy2, x3, y3
590
+ )
591
+ x0 = x3
592
+ y0 = y3
593
+ fx0 = fx3
594
+ fy0 = fy3
595
+ t1 = t2