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.
- meerk40t/__init__.py +1 -1
- meerk40t/balormk/balor_params.py +167 -167
- meerk40t/balormk/clone_loader.py +457 -457
- meerk40t/balormk/controller.py +1566 -1512
- meerk40t/balormk/cylindermod.py +64 -0
- meerk40t/balormk/device.py +966 -1959
- meerk40t/balormk/driver.py +778 -591
- meerk40t/balormk/galvo_commands.py +1194 -0
- meerk40t/balormk/gui/balorconfig.py +237 -111
- meerk40t/balormk/gui/balorcontroller.py +191 -184
- meerk40t/balormk/gui/baloroperationproperties.py +116 -115
- meerk40t/balormk/gui/corscene.py +845 -0
- meerk40t/balormk/gui/gui.py +179 -147
- meerk40t/balormk/livelightjob.py +466 -382
- meerk40t/balormk/mock_connection.py +131 -109
- meerk40t/balormk/plugin.py +133 -135
- meerk40t/balormk/usb_connection.py +306 -301
- meerk40t/camera/__init__.py +1 -1
- meerk40t/camera/camera.py +514 -397
- meerk40t/camera/gui/camerapanel.py +1241 -1095
- meerk40t/camera/gui/gui.py +58 -58
- meerk40t/camera/plugin.py +441 -399
- meerk40t/ch341/__init__.py +27 -27
- meerk40t/ch341/ch341device.py +628 -628
- meerk40t/ch341/libusb.py +595 -589
- meerk40t/ch341/mock.py +171 -171
- meerk40t/ch341/windriver.py +157 -157
- meerk40t/constants.py +13 -0
- meerk40t/core/__init__.py +1 -1
- meerk40t/core/bindalias.py +550 -539
- meerk40t/core/core.py +47 -47
- meerk40t/core/cutcode/cubiccut.py +73 -73
- meerk40t/core/cutcode/cutcode.py +315 -312
- meerk40t/core/cutcode/cutgroup.py +141 -137
- meerk40t/core/cutcode/cutobject.py +192 -185
- meerk40t/core/cutcode/dwellcut.py +37 -37
- meerk40t/core/cutcode/gotocut.py +29 -29
- meerk40t/core/cutcode/homecut.py +29 -29
- meerk40t/core/cutcode/inputcut.py +34 -34
- meerk40t/core/cutcode/linecut.py +33 -33
- meerk40t/core/cutcode/outputcut.py +34 -34
- meerk40t/core/cutcode/plotcut.py +335 -335
- meerk40t/core/cutcode/quadcut.py +61 -61
- meerk40t/core/cutcode/rastercut.py +168 -148
- meerk40t/core/cutcode/waitcut.py +34 -34
- meerk40t/core/cutplan.py +1843 -1316
- meerk40t/core/drivers.py +330 -329
- meerk40t/core/elements/align.py +801 -669
- meerk40t/core/elements/branches.py +1858 -1507
- meerk40t/core/elements/clipboard.py +229 -219
- meerk40t/core/elements/element_treeops.py +4595 -2837
- meerk40t/core/elements/element_types.py +125 -105
- meerk40t/core/elements/elements.py +4315 -3617
- meerk40t/core/elements/files.py +117 -64
- meerk40t/core/elements/geometry.py +473 -224
- meerk40t/core/elements/grid.py +467 -316
- meerk40t/core/elements/materials.py +158 -94
- meerk40t/core/elements/notes.py +50 -38
- meerk40t/core/elements/offset_clpr.py +934 -912
- meerk40t/core/elements/offset_mk.py +963 -955
- meerk40t/core/elements/penbox.py +339 -267
- meerk40t/core/elements/placements.py +300 -83
- meerk40t/core/elements/render.py +785 -687
- meerk40t/core/elements/shapes.py +2618 -2092
- meerk40t/core/elements/testcases.py +105 -0
- meerk40t/core/elements/trace.py +651 -563
- meerk40t/core/elements/tree_commands.py +415 -409
- meerk40t/core/elements/undo_redo.py +116 -58
- meerk40t/core/elements/wordlist.py +319 -200
- meerk40t/core/exceptions.py +9 -9
- meerk40t/core/laserjob.py +220 -220
- meerk40t/core/logging.py +63 -63
- meerk40t/core/node/blobnode.py +83 -86
- meerk40t/core/node/bootstrap.py +105 -103
- meerk40t/core/node/branch_elems.py +40 -31
- meerk40t/core/node/branch_ops.py +45 -38
- meerk40t/core/node/branch_regmark.py +48 -41
- meerk40t/core/node/cutnode.py +29 -32
- meerk40t/core/node/effect_hatch.py +375 -257
- meerk40t/core/node/effect_warp.py +398 -0
- meerk40t/core/node/effect_wobble.py +441 -309
- meerk40t/core/node/elem_ellipse.py +404 -309
- meerk40t/core/node/elem_image.py +1082 -801
- meerk40t/core/node/elem_line.py +358 -292
- meerk40t/core/node/elem_path.py +259 -201
- meerk40t/core/node/elem_point.py +129 -102
- meerk40t/core/node/elem_polyline.py +310 -246
- meerk40t/core/node/elem_rect.py +376 -286
- meerk40t/core/node/elem_text.py +445 -418
- meerk40t/core/node/filenode.py +59 -40
- meerk40t/core/node/groupnode.py +138 -74
- meerk40t/core/node/image_processed.py +777 -766
- meerk40t/core/node/image_raster.py +156 -113
- meerk40t/core/node/layernode.py +31 -31
- meerk40t/core/node/mixins.py +135 -107
- meerk40t/core/node/node.py +1427 -1304
- meerk40t/core/node/nutils.py +117 -114
- meerk40t/core/node/op_cut.py +463 -335
- meerk40t/core/node/op_dots.py +296 -251
- meerk40t/core/node/op_engrave.py +414 -311
- meerk40t/core/node/op_image.py +755 -369
- meerk40t/core/node/op_raster.py +787 -522
- meerk40t/core/node/place_current.py +37 -40
- meerk40t/core/node/place_point.py +329 -126
- meerk40t/core/node/refnode.py +58 -47
- meerk40t/core/node/rootnode.py +225 -219
- meerk40t/core/node/util_console.py +48 -48
- meerk40t/core/node/util_goto.py +84 -65
- meerk40t/core/node/util_home.py +61 -61
- meerk40t/core/node/util_input.py +102 -102
- meerk40t/core/node/util_output.py +102 -102
- meerk40t/core/node/util_wait.py +65 -65
- meerk40t/core/parameters.py +709 -707
- meerk40t/core/planner.py +875 -785
- meerk40t/core/plotplanner.py +656 -652
- meerk40t/core/space.py +120 -113
- meerk40t/core/spoolers.py +706 -705
- meerk40t/core/svg_io.py +1836 -1549
- meerk40t/core/treeop.py +534 -445
- meerk40t/core/undos.py +278 -124
- meerk40t/core/units.py +784 -680
- meerk40t/core/view.py +393 -322
- meerk40t/core/webhelp.py +62 -62
- meerk40t/core/wordlist.py +513 -504
- meerk40t/cylinder/cylinder.py +247 -0
- meerk40t/cylinder/gui/cylindersettings.py +41 -0
- meerk40t/cylinder/gui/gui.py +24 -0
- meerk40t/device/__init__.py +1 -1
- meerk40t/device/basedevice.py +322 -123
- meerk40t/device/devicechoices.py +50 -0
- meerk40t/device/dummydevice.py +163 -128
- meerk40t/device/gui/defaultactions.py +618 -602
- meerk40t/device/gui/effectspanel.py +114 -0
- meerk40t/device/gui/formatterpanel.py +253 -290
- meerk40t/device/gui/warningpanel.py +337 -260
- meerk40t/device/mixins.py +13 -13
- meerk40t/dxf/__init__.py +1 -1
- meerk40t/dxf/dxf_io.py +766 -554
- meerk40t/dxf/plugin.py +47 -35
- meerk40t/external_plugins.py +79 -79
- meerk40t/external_plugins_build.py +28 -28
- meerk40t/extra/cag.py +112 -116
- meerk40t/extra/coolant.py +403 -0
- meerk40t/extra/encode_detect.py +204 -0
- meerk40t/extra/ezd.py +1165 -1165
- meerk40t/extra/hershey.py +834 -340
- meerk40t/extra/imageactions.py +322 -316
- meerk40t/extra/inkscape.py +628 -622
- meerk40t/extra/lbrn.py +424 -424
- meerk40t/extra/outerworld.py +283 -0
- meerk40t/extra/param_functions.py +1542 -1556
- meerk40t/extra/potrace.py +257 -253
- meerk40t/extra/serial_exchange.py +118 -0
- meerk40t/extra/updater.py +602 -453
- meerk40t/extra/vectrace.py +147 -146
- meerk40t/extra/winsleep.py +83 -83
- meerk40t/extra/xcs_reader.py +597 -0
- meerk40t/fill/fills.py +781 -335
- meerk40t/fill/patternfill.py +1061 -1061
- meerk40t/fill/patterns.py +614 -567
- meerk40t/grbl/control.py +87 -87
- meerk40t/grbl/controller.py +990 -903
- meerk40t/grbl/device.py +1084 -768
- meerk40t/grbl/driver.py +989 -771
- meerk40t/grbl/emulator.py +532 -497
- meerk40t/grbl/gcodejob.py +783 -767
- meerk40t/grbl/gui/grblconfiguration.py +373 -298
- meerk40t/grbl/gui/grblcontroller.py +485 -271
- meerk40t/grbl/gui/grblhardwareconfig.py +269 -153
- meerk40t/grbl/gui/grbloperationconfig.py +105 -0
- meerk40t/grbl/gui/gui.py +147 -116
- meerk40t/grbl/interpreter.py +44 -44
- meerk40t/grbl/loader.py +22 -22
- meerk40t/grbl/mock_connection.py +56 -56
- meerk40t/grbl/plugin.py +294 -264
- meerk40t/grbl/serial_connection.py +93 -88
- meerk40t/grbl/tcp_connection.py +81 -79
- meerk40t/grbl/ws_connection.py +112 -0
- meerk40t/gui/__init__.py +1 -1
- meerk40t/gui/about.py +2042 -296
- meerk40t/gui/alignment.py +1644 -1608
- meerk40t/gui/autoexec.py +199 -0
- meerk40t/gui/basicops.py +791 -670
- meerk40t/gui/bufferview.py +77 -71
- meerk40t/gui/busy.py +232 -133
- meerk40t/gui/choicepropertypanel.py +1662 -1469
- meerk40t/gui/consolepanel.py +706 -542
- meerk40t/gui/devicepanel.py +687 -581
- meerk40t/gui/dialogoptions.py +110 -107
- meerk40t/gui/executejob.py +316 -306
- meerk40t/gui/fonts.py +90 -90
- meerk40t/gui/functionwrapper.py +252 -0
- meerk40t/gui/gui_mixins.py +729 -0
- meerk40t/gui/guicolors.py +205 -182
- meerk40t/gui/help_assets/help_assets.py +218 -201
- meerk40t/gui/helper.py +154 -0
- meerk40t/gui/hersheymanager.py +1440 -846
- meerk40t/gui/icons.py +3422 -2747
- meerk40t/gui/imagesplitter.py +555 -508
- meerk40t/gui/keymap.py +354 -344
- meerk40t/gui/laserpanel.py +897 -806
- meerk40t/gui/laserrender.py +1470 -1232
- meerk40t/gui/lasertoolpanel.py +805 -793
- meerk40t/gui/magnetoptions.py +436 -0
- meerk40t/gui/materialmanager.py +2944 -0
- meerk40t/gui/materialtest.py +1722 -1694
- meerk40t/gui/mkdebug.py +646 -359
- meerk40t/gui/mwindow.py +163 -140
- meerk40t/gui/navigationpanels.py +2605 -2467
- meerk40t/gui/notes.py +143 -142
- meerk40t/gui/opassignment.py +414 -410
- meerk40t/gui/operation_info.py +310 -299
- meerk40t/gui/plugin.py +500 -328
- meerk40t/gui/position.py +714 -669
- meerk40t/gui/preferences.py +901 -650
- meerk40t/gui/propertypanels/attributes.py +1461 -1131
- meerk40t/gui/propertypanels/blobproperty.py +117 -114
- meerk40t/gui/propertypanels/consoleproperty.py +83 -80
- meerk40t/gui/propertypanels/gotoproperty.py +77 -0
- meerk40t/gui/propertypanels/groupproperties.py +223 -217
- meerk40t/gui/propertypanels/hatchproperty.py +489 -469
- meerk40t/gui/propertypanels/imageproperty.py +2244 -1384
- meerk40t/gui/propertypanels/inputproperty.py +59 -58
- meerk40t/gui/propertypanels/opbranchproperties.py +82 -80
- meerk40t/gui/propertypanels/operationpropertymain.py +1890 -1638
- meerk40t/gui/propertypanels/outputproperty.py +59 -58
- meerk40t/gui/propertypanels/pathproperty.py +389 -380
- meerk40t/gui/propertypanels/placementproperty.py +1214 -383
- meerk40t/gui/propertypanels/pointproperty.py +140 -136
- meerk40t/gui/propertypanels/propertywindow.py +313 -181
- meerk40t/gui/propertypanels/rasterwizardpanels.py +996 -912
- meerk40t/gui/propertypanels/regbranchproperties.py +76 -0
- meerk40t/gui/propertypanels/textproperty.py +770 -755
- meerk40t/gui/propertypanels/waitproperty.py +56 -55
- meerk40t/gui/propertypanels/warpproperty.py +121 -0
- meerk40t/gui/propertypanels/wobbleproperty.py +255 -204
- meerk40t/gui/ribbon.py +2471 -2210
- meerk40t/gui/scene/scene.py +1100 -1051
- meerk40t/gui/scene/sceneconst.py +22 -22
- meerk40t/gui/scene/scenepanel.py +439 -349
- meerk40t/gui/scene/scenespacewidget.py +365 -365
- meerk40t/gui/scene/widget.py +518 -505
- meerk40t/gui/scenewidgets/affinemover.py +215 -215
- meerk40t/gui/scenewidgets/attractionwidget.py +315 -309
- meerk40t/gui/scenewidgets/bedwidget.py +120 -97
- meerk40t/gui/scenewidgets/elementswidget.py +137 -107
- meerk40t/gui/scenewidgets/gridwidget.py +785 -745
- meerk40t/gui/scenewidgets/guidewidget.py +765 -765
- meerk40t/gui/scenewidgets/laserpathwidget.py +66 -66
- meerk40t/gui/scenewidgets/machineoriginwidget.py +86 -86
- meerk40t/gui/scenewidgets/nodeselector.py +28 -28
- meerk40t/gui/scenewidgets/rectselectwidget.py +592 -346
- meerk40t/gui/scenewidgets/relocatewidget.py +33 -33
- meerk40t/gui/scenewidgets/reticlewidget.py +83 -83
- meerk40t/gui/scenewidgets/selectionwidget.py +2958 -2756
- meerk40t/gui/simpleui.py +362 -333
- meerk40t/gui/simulation.py +2451 -2094
- meerk40t/gui/snapoptions.py +208 -203
- meerk40t/gui/spoolerpanel.py +1227 -1180
- meerk40t/gui/statusbarwidgets/defaultoperations.py +480 -353
- meerk40t/gui/statusbarwidgets/infowidget.py +520 -483
- meerk40t/gui/statusbarwidgets/opassignwidget.py +356 -355
- meerk40t/gui/statusbarwidgets/selectionwidget.py +172 -171
- meerk40t/gui/statusbarwidgets/shapepropwidget.py +754 -236
- meerk40t/gui/statusbarwidgets/statusbar.py +272 -260
- meerk40t/gui/statusbarwidgets/statusbarwidget.py +268 -270
- meerk40t/gui/statusbarwidgets/strokewidget.py +267 -251
- meerk40t/gui/themes.py +200 -78
- meerk40t/gui/tips.py +590 -0
- meerk40t/gui/toolwidgets/circlebrush.py +35 -35
- meerk40t/gui/toolwidgets/toolcircle.py +248 -242
- meerk40t/gui/toolwidgets/toolcontainer.py +82 -77
- meerk40t/gui/toolwidgets/tooldraw.py +97 -90
- meerk40t/gui/toolwidgets/toolellipse.py +219 -212
- meerk40t/gui/toolwidgets/toolimagecut.py +25 -132
- meerk40t/gui/toolwidgets/toolline.py +39 -144
- meerk40t/gui/toolwidgets/toollinetext.py +79 -236
- meerk40t/gui/toolwidgets/toollinetext_inline.py +296 -0
- meerk40t/gui/toolwidgets/toolmeasure.py +163 -216
- meerk40t/gui/toolwidgets/toolnodeedit.py +2088 -2074
- meerk40t/gui/toolwidgets/toolnodemove.py +92 -94
- meerk40t/gui/toolwidgets/toolparameter.py +754 -668
- meerk40t/gui/toolwidgets/toolplacement.py +108 -108
- meerk40t/gui/toolwidgets/toolpoint.py +68 -59
- meerk40t/gui/toolwidgets/toolpointlistbuilder.py +294 -0
- meerk40t/gui/toolwidgets/toolpointmove.py +183 -0
- meerk40t/gui/toolwidgets/toolpolygon.py +288 -403
- meerk40t/gui/toolwidgets/toolpolyline.py +38 -196
- meerk40t/gui/toolwidgets/toolrect.py +211 -207
- meerk40t/gui/toolwidgets/toolrelocate.py +72 -72
- meerk40t/gui/toolwidgets/toolribbon.py +598 -113
- meerk40t/gui/toolwidgets/tooltabedit.py +546 -0
- meerk40t/gui/toolwidgets/tooltext.py +98 -89
- meerk40t/gui/toolwidgets/toolvector.py +213 -204
- meerk40t/gui/toolwidgets/toolwidget.py +39 -39
- meerk40t/gui/usbconnect.py +98 -91
- meerk40t/gui/utilitywidgets/buttonwidget.py +18 -18
- meerk40t/gui/utilitywidgets/checkboxwidget.py +90 -90
- meerk40t/gui/utilitywidgets/controlwidget.py +14 -14
- meerk40t/gui/utilitywidgets/cyclocycloidwidget.py +343 -340
- meerk40t/gui/utilitywidgets/debugwidgets.py +148 -0
- meerk40t/gui/utilitywidgets/handlewidget.py +27 -27
- meerk40t/gui/utilitywidgets/harmonograph.py +450 -447
- meerk40t/gui/utilitywidgets/openclosewidget.py +40 -40
- meerk40t/gui/utilitywidgets/rotationwidget.py +54 -54
- meerk40t/gui/utilitywidgets/scalewidget.py +75 -75
- meerk40t/gui/utilitywidgets/seekbarwidget.py +183 -183
- meerk40t/gui/utilitywidgets/togglewidget.py +142 -142
- meerk40t/gui/utilitywidgets/toolbarwidget.py +8 -8
- meerk40t/gui/wordlisteditor.py +985 -931
- meerk40t/gui/wxmeerk40t.py +1447 -1169
- meerk40t/gui/wxmmain.py +5644 -4112
- meerk40t/gui/wxmribbon.py +1591 -1076
- meerk40t/gui/wxmscene.py +1631 -1453
- meerk40t/gui/wxmtree.py +2416 -2089
- meerk40t/gui/wxutils.py +1769 -1099
- meerk40t/gui/zmatrix.py +102 -102
- meerk40t/image/__init__.py +1 -1
- meerk40t/image/dither.py +429 -0
- meerk40t/image/imagetools.py +2793 -2269
- meerk40t/internal_plugins.py +150 -130
- meerk40t/kernel/__init__.py +63 -12
- meerk40t/kernel/channel.py +259 -212
- meerk40t/kernel/context.py +538 -538
- meerk40t/kernel/exceptions.py +41 -41
- meerk40t/kernel/functions.py +463 -414
- meerk40t/kernel/jobs.py +100 -100
- meerk40t/kernel/kernel.py +3828 -3571
- meerk40t/kernel/lifecycles.py +71 -71
- meerk40t/kernel/module.py +49 -49
- meerk40t/kernel/service.py +147 -147
- meerk40t/kernel/settings.py +383 -343
- meerk40t/lihuiyu/controller.py +883 -876
- meerk40t/lihuiyu/device.py +1181 -1069
- meerk40t/lihuiyu/driver.py +1466 -1372
- meerk40t/lihuiyu/gui/gui.py +127 -106
- meerk40t/lihuiyu/gui/lhyaccelgui.py +377 -363
- meerk40t/lihuiyu/gui/lhycontrollergui.py +741 -651
- meerk40t/lihuiyu/gui/lhydrivergui.py +470 -446
- meerk40t/lihuiyu/gui/lhyoperationproperties.py +238 -237
- meerk40t/lihuiyu/gui/tcpcontroller.py +226 -190
- meerk40t/lihuiyu/interpreter.py +53 -53
- meerk40t/lihuiyu/laserspeed.py +450 -450
- meerk40t/lihuiyu/loader.py +90 -90
- meerk40t/lihuiyu/parser.py +404 -404
- meerk40t/lihuiyu/plugin.py +101 -102
- meerk40t/lihuiyu/tcp_connection.py +111 -109
- meerk40t/main.py +231 -165
- meerk40t/moshi/builder.py +788 -781
- meerk40t/moshi/controller.py +505 -499
- meerk40t/moshi/device.py +495 -442
- meerk40t/moshi/driver.py +862 -696
- meerk40t/moshi/gui/gui.py +78 -76
- meerk40t/moshi/gui/moshicontrollergui.py +538 -522
- meerk40t/moshi/gui/moshidrivergui.py +87 -75
- meerk40t/moshi/plugin.py +43 -43
- meerk40t/network/console_server.py +140 -57
- meerk40t/network/kernelserver.py +10 -9
- meerk40t/network/tcp_server.py +142 -140
- meerk40t/network/udp_server.py +103 -77
- meerk40t/network/web_server.py +404 -0
- meerk40t/newly/controller.py +1158 -1144
- meerk40t/newly/device.py +874 -732
- meerk40t/newly/driver.py +540 -412
- meerk40t/newly/gui/gui.py +219 -188
- meerk40t/newly/gui/newlyconfig.py +116 -101
- meerk40t/newly/gui/newlycontroller.py +193 -186
- meerk40t/newly/gui/operationproperties.py +51 -51
- meerk40t/newly/mock_connection.py +82 -82
- meerk40t/newly/newly_params.py +56 -56
- meerk40t/newly/plugin.py +1214 -1246
- meerk40t/newly/usb_connection.py +322 -322
- meerk40t/rotary/gui/gui.py +52 -46
- meerk40t/rotary/gui/rotarysettings.py +240 -232
- meerk40t/rotary/rotary.py +202 -98
- meerk40t/ruida/control.py +291 -91
- meerk40t/ruida/controller.py +138 -1088
- meerk40t/ruida/device.py +676 -231
- meerk40t/ruida/driver.py +534 -472
- meerk40t/ruida/emulator.py +1494 -1491
- meerk40t/ruida/exceptions.py +4 -4
- meerk40t/ruida/gui/gui.py +71 -76
- meerk40t/ruida/gui/ruidaconfig.py +239 -72
- meerk40t/ruida/gui/ruidacontroller.py +187 -184
- meerk40t/ruida/gui/ruidaoperationproperties.py +48 -47
- meerk40t/ruida/loader.py +54 -52
- meerk40t/ruida/mock_connection.py +57 -109
- meerk40t/ruida/plugin.py +124 -87
- meerk40t/ruida/rdjob.py +2084 -945
- meerk40t/ruida/serial_connection.py +116 -0
- meerk40t/ruida/tcp_connection.py +146 -0
- meerk40t/ruida/udp_connection.py +73 -0
- meerk40t/svgelements.py +9671 -9669
- meerk40t/tools/driver_to_path.py +584 -579
- meerk40t/tools/geomstr.py +5583 -4680
- meerk40t/tools/jhfparser.py +357 -292
- meerk40t/tools/kerftest.py +904 -890
- meerk40t/tools/livinghinges.py +1168 -1033
- meerk40t/tools/pathtools.py +987 -949
- meerk40t/tools/pmatrix.py +234 -0
- meerk40t/tools/pointfinder.py +942 -942
- meerk40t/tools/polybool.py +941 -940
- meerk40t/tools/rasterplotter.py +1660 -547
- meerk40t/tools/shxparser.py +1047 -901
- meerk40t/tools/ttfparser.py +726 -446
- meerk40t/tools/zinglplotter.py +595 -593
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/LICENSE +21 -21
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/METADATA +150 -139
- meerk40t-0.9.7020.dist-info/RECORD +446 -0
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/WHEEL +1 -1
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/top_level.txt +0 -1
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/zip-safe +1 -1
- meerk40t/balormk/elementlightjob.py +0 -159
- meerk40t-0.9.3001.dist-info/RECORD +0 -437
- test/bootstrap.py +0 -63
- test/test_cli.py +0 -12
- test/test_core_cutcode.py +0 -418
- test/test_core_elements.py +0 -144
- test/test_core_plotplanner.py +0 -397
- test/test_core_viewports.py +0 -312
- test/test_drivers_grbl.py +0 -108
- test/test_drivers_lihuiyu.py +0 -443
- test/test_drivers_newly.py +0 -113
- test/test_element_degenerate_points.py +0 -43
- test/test_elements_classify.py +0 -97
- test/test_elements_penbox.py +0 -22
- test/test_file_svg.py +0 -176
- test/test_fill.py +0 -155
- test/test_geomstr.py +0 -1523
- test/test_geomstr_nodes.py +0 -18
- test/test_imagetools_actualize.py +0 -306
- test/test_imagetools_wizard.py +0 -258
- test/test_kernel.py +0 -200
- test/test_laser_speeds.py +0 -3303
- test/test_length.py +0 -57
- test/test_lifecycle.py +0 -66
- test/test_operations.py +0 -251
- test/test_operations_hatch.py +0 -57
- test/test_ruida.py +0 -19
- test/test_spooler.py +0 -22
- test/test_tools_rasterplotter.py +0 -29
- test/test_wobble.py +0 -133
- test/test_zingl.py +0 -124
- {test → meerk40t/cylinder}/__init__.py +0 -0
- /meerk40t/{core/element_commands.py → cylinder/gui/__init__.py} +0 -0
- {meerk40t-0.9.3001.dist-info → meerk40t-0.9.7020.dist-info}/entry_points.txt +0 -0
meerk40t/tools/polybool.py
CHANGED
@@ -1,940 +1,941 @@
|
|
1
|
-
"""
|
2
|
-
https://github.com/KaivnD/pypolybool
|
3
|
-
MIT License
|
4
|
-
"""
|
5
|
-
|
6
|
-
import typing
|
7
|
-
|
8
|
-
tolerance = 1e-10
|
9
|
-
|
10
|
-
T = typing.TypeVar("T")
|
11
|
-
TPoint = typing.TypeVar("TPoint", bound="Point")
|
12
|
-
|
13
|
-
|
14
|
-
class PolyBoolException(Exception):
|
15
|
-
pass
|
16
|
-
|
17
|
-
|
18
|
-
class Point:
|
19
|
-
def __init__(self: TPoint, x: float, y: float) -> None:
|
20
|
-
self.x = x
|
21
|
-
self.y = y
|
22
|
-
|
23
|
-
@staticmethod
|
24
|
-
def collinear(pt1: TPoint, pt2: TPoint, pt3: TPoint) -> bool:
|
25
|
-
dx1 = pt1.x - pt2.x
|
26
|
-
dy1 = pt1.y - pt2.y
|
27
|
-
dx2 = pt2.x - pt3.x
|
28
|
-
dy2 = pt2.y - pt3.y
|
29
|
-
return abs(dx1 * dy2 - dx2 * dy1) < tolerance
|
30
|
-
|
31
|
-
@staticmethod
|
32
|
-
def compare(pt1: TPoint, pt2: TPoint):
|
33
|
-
if abs(pt1.x - pt2.x) < tolerance:
|
34
|
-
return 0 if abs(pt1.y - pt2.y) < tolerance else -1 if pt1.y < pt2.y else 1
|
35
|
-
return -1 if pt1.x < pt2.x else 1
|
36
|
-
|
37
|
-
@staticmethod
|
38
|
-
def pointAboveOrOnLine(point: TPoint, left: TPoint, right: TPoint):
|
39
|
-
return (right.x - left.x) * (point.y - left.y) - (right.y - left.y) * (
|
40
|
-
point.x - left.x
|
41
|
-
) >= -tolerance
|
42
|
-
|
43
|
-
@staticmethod
|
44
|
-
def between(point: TPoint, left: TPoint, right: TPoint):
|
45
|
-
dPyLy = point.y - left.y
|
46
|
-
dRxLx = right.x - left.x
|
47
|
-
dPxLx = point.x - left.x
|
48
|
-
dRyLy = right.y - left.y
|
49
|
-
|
50
|
-
dot = dPxLx * dRxLx + dPyLy * dRyLy
|
51
|
-
if dot < tolerance:
|
52
|
-
return False
|
53
|
-
|
54
|
-
sqlen = dRxLx * dRxLx + dRyLy * dRyLy
|
55
|
-
if dot - sqlen > -tolerance:
|
56
|
-
return False
|
57
|
-
|
58
|
-
return True
|
59
|
-
|
60
|
-
@staticmethod
|
61
|
-
def linesIntersect(a0: TPoint, a1: TPoint, b0: TPoint, b1: TPoint):
|
62
|
-
adx = a1.x - a0.x
|
63
|
-
ady = a1.y - a0.y
|
64
|
-
bdx = b1.x - b0.x
|
65
|
-
bdy = b1.y - b0.y
|
66
|
-
|
67
|
-
axb = adx * bdy - ady * bdx
|
68
|
-
|
69
|
-
if abs(axb) < tolerance:
|
70
|
-
return None
|
71
|
-
|
72
|
-
dx = a0.x - b0.x
|
73
|
-
dy = a0.y - b0.y
|
74
|
-
|
75
|
-
a = (bdx * dy - bdy * dx) / axb
|
76
|
-
b = (adx * dy - ady * dx) / axb
|
77
|
-
|
78
|
-
return IntersectionPoint(
|
79
|
-
Point.__calcAlongUsingValue(a),
|
80
|
-
Point.__calcAlongUsingValue(b),
|
81
|
-
Point(a0.x + a * adx, a0.y + a * ady),
|
82
|
-
)
|
83
|
-
|
84
|
-
@staticmethod
|
85
|
-
def __calcAlongUsingValue(value: float):
|
86
|
-
if value <= -tolerance:
|
87
|
-
return -2
|
88
|
-
elif value < tolerance:
|
89
|
-
return -1
|
90
|
-
elif value - 1 <= -tolerance:
|
91
|
-
return 0
|
92
|
-
elif value - 1 < tolerance:
|
93
|
-
return 1
|
94
|
-
else:
|
95
|
-
return 2
|
96
|
-
|
97
|
-
def __eq__(self, __o: object) -> bool:
|
98
|
-
if not isinstance(__o, Point):
|
99
|
-
return False
|
100
|
-
return abs(self.x - __o.x) < tolerance and abs(self.y - __o.y) < tolerance
|
101
|
-
|
102
|
-
def __repr__(self) -> str:
|
103
|
-
return f"{self.x},{self.y}"
|
104
|
-
|
105
|
-
def __str__(self) -> str:
|
106
|
-
return f"{self.x},{self.y}"
|
107
|
-
|
108
|
-
|
109
|
-
class Fill:
|
110
|
-
def __init__(self, below: bool = None, above: bool = None) -> None:
|
111
|
-
self.below = below
|
112
|
-
self.above = above
|
113
|
-
|
114
|
-
def __repr__(self) -> str:
|
115
|
-
return f"{self.above},{self.below}"
|
116
|
-
|
117
|
-
def __str__(self) -> str:
|
118
|
-
return f"{self.above},{self.below}"
|
119
|
-
|
120
|
-
|
121
|
-
class Segment:
|
122
|
-
def __init__(
|
123
|
-
self, start: Point, end: Point, myfill: Fill = None, otherfill: Fill = None
|
124
|
-
):
|
125
|
-
self.start = start
|
126
|
-
self.end = end
|
127
|
-
self.myfill = myfill
|
128
|
-
self.otherfill = otherfill
|
129
|
-
|
130
|
-
def __repr__(self) -> str:
|
131
|
-
return f"S: {self.start}, E: {self.end}"
|
132
|
-
|
133
|
-
def __str__(self) -> str:
|
134
|
-
return f"S: {self.start}, E: {self.end}"
|
135
|
-
|
136
|
-
|
137
|
-
class PolySegments:
|
138
|
-
def __init__(
|
139
|
-
self, segments: typing.List[Segment] = None, isInverted: bool = False
|
140
|
-
) -> None:
|
141
|
-
self.segments = segments
|
142
|
-
self.isInverted = isInverted
|
143
|
-
|
144
|
-
|
145
|
-
class CombinedPolySegments:
|
146
|
-
def __init__(
|
147
|
-
self,
|
148
|
-
combined: typing.List[Segment] = None,
|
149
|
-
isInverted1: bool = False,
|
150
|
-
isInverted2: bool = False,
|
151
|
-
) -> None:
|
152
|
-
self.combined = combined
|
153
|
-
self.isInverted1 = isInverted1
|
154
|
-
self.isInverted2 = isInverted2
|
155
|
-
|
156
|
-
|
157
|
-
class Matcher:
|
158
|
-
def __init__(
|
159
|
-
self,
|
160
|
-
index: int,
|
161
|
-
matchesHead: bool,
|
162
|
-
matchesPt1: bool,
|
163
|
-
) -> None:
|
164
|
-
self.index = index
|
165
|
-
self.matchesHead = matchesHead
|
166
|
-
self.matchesPt1 = matchesPt1
|
167
|
-
|
168
|
-
|
169
|
-
class IntersectionPoint:
|
170
|
-
def __init__(self, alongA: int, alongB: int, pt: Point) -> None:
|
171
|
-
self.alongA = alongA
|
172
|
-
self.alongB = alongB
|
173
|
-
self.pt = pt
|
174
|
-
|
175
|
-
|
176
|
-
TNode = typing.TypeVar("TNode", bound="Node")
|
177
|
-
|
178
|
-
|
179
|
-
class Node:
|
180
|
-
def __init__(
|
181
|
-
self: TNode,
|
182
|
-
isRoot: bool = False,
|
183
|
-
isStart: bool = False,
|
184
|
-
pt: Point = None,
|
185
|
-
seg: Segment = None,
|
186
|
-
primary: bool = False,
|
187
|
-
next: TNode = None,
|
188
|
-
previous: TNode = None,
|
189
|
-
other: TNode = None,
|
190
|
-
ev: TNode = None,
|
191
|
-
status: TNode = None,
|
192
|
-
remove: typing.Callable = None,
|
193
|
-
):
|
194
|
-
self.status = status
|
195
|
-
self.other = other
|
196
|
-
self.ev = ev
|
197
|
-
self.previous = previous
|
198
|
-
self.next = next
|
199
|
-
self.isRoot = isRoot
|
200
|
-
self.remove = remove
|
201
|
-
self.isStart = isStart
|
202
|
-
self.pt = pt
|
203
|
-
self.seg = seg
|
204
|
-
self.primary = primary
|
205
|
-
|
206
|
-
|
207
|
-
class Transition:
|
208
|
-
def __init__(
|
209
|
-
self, after: Node, before: Node, insert: typing.Callable[[Node], Node]
|
210
|
-
) -> None:
|
211
|
-
self.after = after
|
212
|
-
self.before = before
|
213
|
-
self.insert = insert
|
214
|
-
|
215
|
-
|
216
|
-
class LinkedList:
|
217
|
-
def __init__(self) -> None:
|
218
|
-
self.__root = Node(isRoot=True)
|
219
|
-
|
220
|
-
def exists(self, node: Node):
|
221
|
-
if node is None or node is self.__root:
|
222
|
-
return False
|
223
|
-
return True
|
224
|
-
|
225
|
-
def isEmpty(self):
|
226
|
-
return self.__root.next is None
|
227
|
-
|
228
|
-
def getHead(self):
|
229
|
-
return self.__root.next
|
230
|
-
|
231
|
-
def insertBefore(self, node: Node, check: typing.Callable[[Node], bool]):
|
232
|
-
last = self.__root
|
233
|
-
here = self.__root.next
|
234
|
-
|
235
|
-
while here is not None:
|
236
|
-
if check(here):
|
237
|
-
node.previous = here.previous
|
238
|
-
node.next = here
|
239
|
-
here.previous.next = node
|
240
|
-
here.previous = node
|
241
|
-
return
|
242
|
-
last = here
|
243
|
-
here = here.next
|
244
|
-
last.next = node
|
245
|
-
node.previous = last
|
246
|
-
node.next = None
|
247
|
-
|
248
|
-
def findTransition(self, check: typing.Callable[[Node], bool]):
|
249
|
-
previous = self.__root
|
250
|
-
here = self.__root.next
|
251
|
-
|
252
|
-
while here is not None:
|
253
|
-
if check(here):
|
254
|
-
break
|
255
|
-
previous = here
|
256
|
-
here = here.next
|
257
|
-
|
258
|
-
def insert_func(node: Node):
|
259
|
-
node.previous = previous
|
260
|
-
node.next = here
|
261
|
-
previous.next = node
|
262
|
-
if here is not None:
|
263
|
-
here.previous = node
|
264
|
-
return node
|
265
|
-
|
266
|
-
return Transition(
|
267
|
-
before=(None if previous is self.__root else previous),
|
268
|
-
after=here,
|
269
|
-
insert=insert_func,
|
270
|
-
)
|
271
|
-
|
272
|
-
@staticmethod
|
273
|
-
def node(data: Node):
|
274
|
-
data.previous = None
|
275
|
-
data.next = None
|
276
|
-
|
277
|
-
def remove_func():
|
278
|
-
data.previous
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
data.
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
self.
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
self.
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
self.
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
ev.
|
391
|
-
ev.
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
self.
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
ev.remove()
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
ev.seg.
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
self.
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
self.nextMatch.
|
621
|
-
self.nextMatch.
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
+ (
|
766
|
-
+ (
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
segments1.
|
794
|
-
|
795
|
-
segments2.
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
0,
|
825
|
-
0,
|
826
|
-
0,
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
0,
|
857
|
-
0,
|
858
|
-
0,
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
2,
|
873
|
-
|
874
|
-
0,
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
1
|
+
"""
|
2
|
+
https://github.com/KaivnD/pypolybool
|
3
|
+
MIT License
|
4
|
+
"""
|
5
|
+
|
6
|
+
import typing
|
7
|
+
|
8
|
+
tolerance = 1e-10
|
9
|
+
|
10
|
+
T = typing.TypeVar("T")
|
11
|
+
TPoint = typing.TypeVar("TPoint", bound="Point")
|
12
|
+
|
13
|
+
|
14
|
+
class PolyBoolException(Exception):
|
15
|
+
pass
|
16
|
+
|
17
|
+
|
18
|
+
class Point:
|
19
|
+
def __init__(self: TPoint, x: float, y: float) -> None:
|
20
|
+
self.x = x
|
21
|
+
self.y = y
|
22
|
+
|
23
|
+
@staticmethod
|
24
|
+
def collinear(pt1: TPoint, pt2: TPoint, pt3: TPoint) -> bool:
|
25
|
+
dx1 = pt1.x - pt2.x
|
26
|
+
dy1 = pt1.y - pt2.y
|
27
|
+
dx2 = pt2.x - pt3.x
|
28
|
+
dy2 = pt2.y - pt3.y
|
29
|
+
return abs(dx1 * dy2 - dx2 * dy1) < tolerance
|
30
|
+
|
31
|
+
@staticmethod
|
32
|
+
def compare(pt1: TPoint, pt2: TPoint):
|
33
|
+
if abs(pt1.x - pt2.x) < tolerance:
|
34
|
+
return 0 if abs(pt1.y - pt2.y) < tolerance else -1 if pt1.y < pt2.y else 1
|
35
|
+
return -1 if pt1.x < pt2.x else 1
|
36
|
+
|
37
|
+
@staticmethod
|
38
|
+
def pointAboveOrOnLine(point: TPoint, left: TPoint, right: TPoint):
|
39
|
+
return (right.x - left.x) * (point.y - left.y) - (right.y - left.y) * (
|
40
|
+
point.x - left.x
|
41
|
+
) >= -tolerance
|
42
|
+
|
43
|
+
@staticmethod
|
44
|
+
def between(point: TPoint, left: TPoint, right: TPoint):
|
45
|
+
dPyLy = point.y - left.y
|
46
|
+
dRxLx = right.x - left.x
|
47
|
+
dPxLx = point.x - left.x
|
48
|
+
dRyLy = right.y - left.y
|
49
|
+
|
50
|
+
dot = dPxLx * dRxLx + dPyLy * dRyLy
|
51
|
+
if dot < tolerance:
|
52
|
+
return False
|
53
|
+
|
54
|
+
sqlen = dRxLx * dRxLx + dRyLy * dRyLy
|
55
|
+
if dot - sqlen > -tolerance:
|
56
|
+
return False
|
57
|
+
|
58
|
+
return True
|
59
|
+
|
60
|
+
@staticmethod
|
61
|
+
def linesIntersect(a0: TPoint, a1: TPoint, b0: TPoint, b1: TPoint):
|
62
|
+
adx = a1.x - a0.x
|
63
|
+
ady = a1.y - a0.y
|
64
|
+
bdx = b1.x - b0.x
|
65
|
+
bdy = b1.y - b0.y
|
66
|
+
|
67
|
+
axb = adx * bdy - ady * bdx
|
68
|
+
|
69
|
+
if abs(axb) < tolerance:
|
70
|
+
return None
|
71
|
+
|
72
|
+
dx = a0.x - b0.x
|
73
|
+
dy = a0.y - b0.y
|
74
|
+
|
75
|
+
a = (bdx * dy - bdy * dx) / axb
|
76
|
+
b = (adx * dy - ady * dx) / axb
|
77
|
+
|
78
|
+
return IntersectionPoint(
|
79
|
+
Point.__calcAlongUsingValue(a),
|
80
|
+
Point.__calcAlongUsingValue(b),
|
81
|
+
Point(a0.x + a * adx, a0.y + a * ady),
|
82
|
+
)
|
83
|
+
|
84
|
+
@staticmethod
|
85
|
+
def __calcAlongUsingValue(value: float):
|
86
|
+
if value <= -tolerance:
|
87
|
+
return -2
|
88
|
+
elif value < tolerance:
|
89
|
+
return -1
|
90
|
+
elif value - 1 <= -tolerance:
|
91
|
+
return 0
|
92
|
+
elif value - 1 < tolerance:
|
93
|
+
return 1
|
94
|
+
else:
|
95
|
+
return 2
|
96
|
+
|
97
|
+
def __eq__(self, __o: object) -> bool:
|
98
|
+
if not isinstance(__o, Point):
|
99
|
+
return False
|
100
|
+
return abs(self.x - __o.x) < tolerance and abs(self.y - __o.y) < tolerance
|
101
|
+
|
102
|
+
def __repr__(self) -> str:
|
103
|
+
return f"{self.x},{self.y}"
|
104
|
+
|
105
|
+
def __str__(self) -> str:
|
106
|
+
return f"{self.x},{self.y}"
|
107
|
+
|
108
|
+
|
109
|
+
class Fill:
|
110
|
+
def __init__(self, below: bool = None, above: bool = None) -> None:
|
111
|
+
self.below = below
|
112
|
+
self.above = above
|
113
|
+
|
114
|
+
def __repr__(self) -> str:
|
115
|
+
return f"{self.above},{self.below}"
|
116
|
+
|
117
|
+
def __str__(self) -> str:
|
118
|
+
return f"{self.above},{self.below}"
|
119
|
+
|
120
|
+
|
121
|
+
class Segment:
|
122
|
+
def __init__(
|
123
|
+
self, start: Point, end: Point, myfill: Fill = None, otherfill: Fill = None
|
124
|
+
):
|
125
|
+
self.start = start
|
126
|
+
self.end = end
|
127
|
+
self.myfill = myfill
|
128
|
+
self.otherfill = otherfill
|
129
|
+
|
130
|
+
def __repr__(self) -> str:
|
131
|
+
return f"S: {self.start}, E: {self.end}"
|
132
|
+
|
133
|
+
def __str__(self) -> str:
|
134
|
+
return f"S: {self.start}, E: {self.end}"
|
135
|
+
|
136
|
+
|
137
|
+
class PolySegments:
|
138
|
+
def __init__(
|
139
|
+
self, segments: typing.List[Segment] = None, isInverted: bool = False
|
140
|
+
) -> None:
|
141
|
+
self.segments = segments
|
142
|
+
self.isInverted = isInverted
|
143
|
+
|
144
|
+
|
145
|
+
class CombinedPolySegments:
|
146
|
+
def __init__(
|
147
|
+
self,
|
148
|
+
combined: typing.List[Segment] = None,
|
149
|
+
isInverted1: bool = False,
|
150
|
+
isInverted2: bool = False,
|
151
|
+
) -> None:
|
152
|
+
self.combined = combined
|
153
|
+
self.isInverted1 = isInverted1
|
154
|
+
self.isInverted2 = isInverted2
|
155
|
+
|
156
|
+
|
157
|
+
class Matcher:
|
158
|
+
def __init__(
|
159
|
+
self,
|
160
|
+
index: int,
|
161
|
+
matchesHead: bool,
|
162
|
+
matchesPt1: bool,
|
163
|
+
) -> None:
|
164
|
+
self.index = index
|
165
|
+
self.matchesHead = matchesHead
|
166
|
+
self.matchesPt1 = matchesPt1
|
167
|
+
|
168
|
+
|
169
|
+
class IntersectionPoint:
|
170
|
+
def __init__(self, alongA: int, alongB: int, pt: Point) -> None:
|
171
|
+
self.alongA = alongA
|
172
|
+
self.alongB = alongB
|
173
|
+
self.pt = pt
|
174
|
+
|
175
|
+
|
176
|
+
TNode = typing.TypeVar("TNode", bound="Node")
|
177
|
+
|
178
|
+
|
179
|
+
class Node:
|
180
|
+
def __init__(
|
181
|
+
self: TNode,
|
182
|
+
isRoot: bool = False,
|
183
|
+
isStart: bool = False,
|
184
|
+
pt: Point = None,
|
185
|
+
seg: Segment = None,
|
186
|
+
primary: bool = False,
|
187
|
+
next: TNode = None,
|
188
|
+
previous: TNode = None,
|
189
|
+
other: TNode = None,
|
190
|
+
ev: TNode = None,
|
191
|
+
status: TNode = None,
|
192
|
+
remove: typing.Callable = None,
|
193
|
+
):
|
194
|
+
self.status = status
|
195
|
+
self.other = other
|
196
|
+
self.ev = ev
|
197
|
+
self.previous = previous
|
198
|
+
self.next = next
|
199
|
+
self.isRoot = isRoot
|
200
|
+
self.remove = remove
|
201
|
+
self.isStart = isStart
|
202
|
+
self.pt = pt
|
203
|
+
self.seg = seg
|
204
|
+
self.primary = primary
|
205
|
+
|
206
|
+
|
207
|
+
class Transition:
|
208
|
+
def __init__(
|
209
|
+
self, after: Node, before: Node, insert: typing.Callable[[Node], Node]
|
210
|
+
) -> None:
|
211
|
+
self.after = after
|
212
|
+
self.before = before
|
213
|
+
self.insert = insert
|
214
|
+
|
215
|
+
|
216
|
+
class LinkedList:
|
217
|
+
def __init__(self) -> None:
|
218
|
+
self.__root = Node(isRoot=True)
|
219
|
+
|
220
|
+
def exists(self, node: Node):
|
221
|
+
if node is None or node is self.__root:
|
222
|
+
return False
|
223
|
+
return True
|
224
|
+
|
225
|
+
def isEmpty(self):
|
226
|
+
return self.__root.next is None
|
227
|
+
|
228
|
+
def getHead(self):
|
229
|
+
return self.__root.next
|
230
|
+
|
231
|
+
def insertBefore(self, node: Node, check: typing.Callable[[Node], bool]):
|
232
|
+
last = self.__root
|
233
|
+
here = self.__root.next
|
234
|
+
|
235
|
+
while here is not None:
|
236
|
+
if check(here):
|
237
|
+
node.previous = here.previous
|
238
|
+
node.next = here
|
239
|
+
here.previous.next = node
|
240
|
+
here.previous = node
|
241
|
+
return
|
242
|
+
last = here
|
243
|
+
here = here.next
|
244
|
+
last.next = node
|
245
|
+
node.previous = last
|
246
|
+
node.next = None
|
247
|
+
|
248
|
+
def findTransition(self, check: typing.Callable[[Node], bool]):
|
249
|
+
previous = self.__root
|
250
|
+
here = self.__root.next
|
251
|
+
|
252
|
+
while here is not None:
|
253
|
+
if check(here):
|
254
|
+
break
|
255
|
+
previous = here
|
256
|
+
here = here.next
|
257
|
+
|
258
|
+
def insert_func(node: Node):
|
259
|
+
node.previous = previous
|
260
|
+
node.next = here
|
261
|
+
previous.next = node
|
262
|
+
if here is not None:
|
263
|
+
here.previous = node
|
264
|
+
return node
|
265
|
+
|
266
|
+
return Transition(
|
267
|
+
before=(None if previous is self.__root else previous),
|
268
|
+
after=here,
|
269
|
+
insert=insert_func,
|
270
|
+
)
|
271
|
+
|
272
|
+
@staticmethod
|
273
|
+
def node(data: Node):
|
274
|
+
data.previous = None
|
275
|
+
data.next = None
|
276
|
+
|
277
|
+
def remove_func():
|
278
|
+
if data.previous is not None:
|
279
|
+
data.previous.next = data.next
|
280
|
+
if data.next is not None:
|
281
|
+
data.next.previous = data.previous
|
282
|
+
data.previous = None
|
283
|
+
data.next = None
|
284
|
+
|
285
|
+
data.remove = remove_func
|
286
|
+
return data
|
287
|
+
|
288
|
+
|
289
|
+
RegionInput = typing.Union[typing.List[Point], typing.List[typing.Tuple[float, float]]]
|
290
|
+
Region = typing.List[Point]
|
291
|
+
|
292
|
+
|
293
|
+
class Polygon:
|
294
|
+
def __init__(self, regions: typing.List[RegionInput], isInverted=False) -> None:
|
295
|
+
_regions: typing.List[Region] = []
|
296
|
+
for region in regions:
|
297
|
+
tmp: Region = []
|
298
|
+
for pt in region:
|
299
|
+
if isinstance(pt, Point):
|
300
|
+
tmp.append(pt)
|
301
|
+
elif isinstance(pt, tuple):
|
302
|
+
x, y = pt
|
303
|
+
tmp.append(Point(x, y))
|
304
|
+
_regions.append(tmp)
|
305
|
+
|
306
|
+
self.regions = _regions
|
307
|
+
self.isInverted = isInverted
|
308
|
+
|
309
|
+
|
310
|
+
class Intersecter:
|
311
|
+
def __init__(self, selfIntersection: bool) -> None:
|
312
|
+
self.selfIntersection = selfIntersection
|
313
|
+
self.__eventRoot = LinkedList()
|
314
|
+
|
315
|
+
def newsegment(self, start: Point, end: Point):
|
316
|
+
return Segment(start=start, end=end, myfill=Fill())
|
317
|
+
|
318
|
+
def segmentCopy(self, start: Point, end: Point, seg: Segment):
|
319
|
+
return Segment(
|
320
|
+
start=start, end=end, myfill=Fill(seg.myfill.below, seg.myfill.above)
|
321
|
+
)
|
322
|
+
|
323
|
+
def __eventCompare(
|
324
|
+
self,
|
325
|
+
p1IsStart: bool,
|
326
|
+
p11: Point,
|
327
|
+
p12: Point,
|
328
|
+
p2IsStart: bool,
|
329
|
+
p21: Point,
|
330
|
+
p22: Point,
|
331
|
+
):
|
332
|
+
comp = Point.compare(p11, p21)
|
333
|
+
if comp != 0:
|
334
|
+
return comp
|
335
|
+
|
336
|
+
if p12 == p22:
|
337
|
+
return 0
|
338
|
+
|
339
|
+
if p1IsStart != p2IsStart:
|
340
|
+
return 1 if p1IsStart else -1
|
341
|
+
|
342
|
+
return (
|
343
|
+
1
|
344
|
+
if Point.pointAboveOrOnLine(
|
345
|
+
p12, p21 if p2IsStart else p22, p22 if p2IsStart else p21
|
346
|
+
)
|
347
|
+
else -1
|
348
|
+
)
|
349
|
+
|
350
|
+
def __eventAdd(self, ev: Node, otherPt: Point):
|
351
|
+
def check_func(here: Node):
|
352
|
+
comp = self.__eventCompare(
|
353
|
+
ev.isStart, ev.pt, otherPt, here.isStart, here.pt, here.other.pt
|
354
|
+
)
|
355
|
+
return comp < 0
|
356
|
+
|
357
|
+
self.__eventRoot.insertBefore(ev, check_func)
|
358
|
+
|
359
|
+
def __eventAddSegmentStart(self, segment: Segment, primary: bool):
|
360
|
+
evStart = LinkedList.node(
|
361
|
+
Node(
|
362
|
+
isStart=True,
|
363
|
+
pt=segment.start,
|
364
|
+
seg=segment,
|
365
|
+
primary=primary,
|
366
|
+
)
|
367
|
+
)
|
368
|
+
self.__eventAdd(evStart, segment.end)
|
369
|
+
return evStart
|
370
|
+
|
371
|
+
def __eventAddSegmentEnd(self, evStart: Node, segment: Segment, primary: bool):
|
372
|
+
evEnd = LinkedList.node(
|
373
|
+
Node(
|
374
|
+
isStart=False,
|
375
|
+
pt=segment.end,
|
376
|
+
seg=segment,
|
377
|
+
primary=primary,
|
378
|
+
other=evStart,
|
379
|
+
)
|
380
|
+
)
|
381
|
+
evStart.other = evEnd
|
382
|
+
self.__eventAdd(evEnd, evStart.pt)
|
383
|
+
|
384
|
+
def eventAddSegment(self, segment: Segment, primary: bool):
|
385
|
+
evStart = self.__eventAddSegmentStart(segment, primary)
|
386
|
+
self.__eventAddSegmentEnd(evStart, segment, primary)
|
387
|
+
return evStart
|
388
|
+
|
389
|
+
def __eventUpdateEnd(self, ev: Node, end: Point):
|
390
|
+
ev.other.remove()
|
391
|
+
ev.seg.end = end
|
392
|
+
ev.other.pt = end
|
393
|
+
self.__eventAdd(ev.other, ev.pt)
|
394
|
+
|
395
|
+
def __eventDivide(self, ev: Node, pt: Point):
|
396
|
+
ns = self.segmentCopy(pt, ev.seg.end, ev.seg)
|
397
|
+
self.__eventUpdateEnd(ev, pt)
|
398
|
+
return self.eventAddSegment(ns, ev.primary)
|
399
|
+
|
400
|
+
def __statusCompare(self, ev1: Node, ev2: Node):
|
401
|
+
a1 = ev1.seg.start
|
402
|
+
a2 = ev1.seg.end
|
403
|
+
b1 = ev2.seg.start
|
404
|
+
b2 = ev2.seg.end
|
405
|
+
|
406
|
+
if Point.collinear(a1, b1, b2):
|
407
|
+
if Point.collinear(a2, b1, b2):
|
408
|
+
return 1
|
409
|
+
return 1 if Point.pointAboveOrOnLine(a2, b1, b2) else -1
|
410
|
+
return 1 if Point.pointAboveOrOnLine(a1, b1, b2) else -1
|
411
|
+
|
412
|
+
def __statusFindSurrounding(self, statusRoot: LinkedList, ev: Node):
|
413
|
+
def check_func(here: Node):
|
414
|
+
return self.__statusCompare(ev, here.ev) > 0
|
415
|
+
|
416
|
+
return statusRoot.findTransition(check_func)
|
417
|
+
|
418
|
+
def __checkIntersection(self, ev1: Node, ev2: Node):
|
419
|
+
seg1 = ev1.seg
|
420
|
+
seg2 = ev2.seg
|
421
|
+
a1 = seg1.start
|
422
|
+
a2 = seg1.end
|
423
|
+
b1 = seg2.start
|
424
|
+
b2 = seg2.end
|
425
|
+
|
426
|
+
i = Point.linesIntersect(a1, a2, b1, b2)
|
427
|
+
if i is None:
|
428
|
+
if not Point.collinear(a1, a2, b1):
|
429
|
+
return None
|
430
|
+
if a1 == b2 or a2 == b1:
|
431
|
+
return None
|
432
|
+
a1EquB1 = a1 == b1
|
433
|
+
a2EquB2 = a2 == b2
|
434
|
+
if a1EquB1 and a2EquB2:
|
435
|
+
return ev2
|
436
|
+
|
437
|
+
a1Between = not a1EquB1 and Point.between(a1, b1, b2)
|
438
|
+
a2Between = not a2EquB2 and Point.between(a2, b1, b2)
|
439
|
+
|
440
|
+
if a1EquB1:
|
441
|
+
if a2Between:
|
442
|
+
self.__eventDivide(ev2, a2)
|
443
|
+
else:
|
444
|
+
self.__eventDivide(ev1, b2)
|
445
|
+
|
446
|
+
return ev2
|
447
|
+
elif a1Between:
|
448
|
+
if not a2EquB2:
|
449
|
+
if a2Between:
|
450
|
+
self.__eventDivide(ev2, a2)
|
451
|
+
else:
|
452
|
+
self.__eventDivide(ev1, b2)
|
453
|
+
self.__eventDivide(ev2, a1)
|
454
|
+
else:
|
455
|
+
if i.alongA == 0:
|
456
|
+
if i.alongB == -1:
|
457
|
+
self.__eventDivide(ev1, b1)
|
458
|
+
elif i.alongB == 0:
|
459
|
+
self.__eventDivide(ev1, i.pt)
|
460
|
+
elif i.alongB == 1:
|
461
|
+
self.__eventDivide(ev1, b2)
|
462
|
+
if i.alongB == 0:
|
463
|
+
if i.alongA == -1:
|
464
|
+
self.__eventDivide(ev2, a1)
|
465
|
+
elif i.alongA == 0:
|
466
|
+
self.__eventDivide(ev2, i.pt)
|
467
|
+
elif i.alongA == 1:
|
468
|
+
self.__eventDivide(ev2, a2)
|
469
|
+
return None
|
470
|
+
|
471
|
+
def __checkBothIntersections(self, above: Node, ev: Node, below: Node):
|
472
|
+
if above is not None:
|
473
|
+
eve = self.__checkIntersection(ev, above)
|
474
|
+
if eve is not None:
|
475
|
+
return eve
|
476
|
+
if below is not None:
|
477
|
+
return self.__checkIntersection(ev, below)
|
478
|
+
|
479
|
+
return None
|
480
|
+
|
481
|
+
def calculate(self, primaryPolyInverted: bool, secondaryPolyInverted: bool):
|
482
|
+
statusRoot = LinkedList()
|
483
|
+
segments: typing.List[Segment] = []
|
484
|
+
|
485
|
+
cnt = 0
|
486
|
+
|
487
|
+
while not self.__eventRoot.isEmpty():
|
488
|
+
cnt += 1
|
489
|
+
ev = self.__eventRoot.getHead()
|
490
|
+
if ev.isStart:
|
491
|
+
surrounding = self.__statusFindSurrounding(statusRoot, ev)
|
492
|
+
above = (
|
493
|
+
surrounding.before.ev if surrounding.before is not None else None
|
494
|
+
)
|
495
|
+
below = surrounding.after.ev if surrounding.after is not None else None
|
496
|
+
|
497
|
+
eve = self.__checkBothIntersections(above, ev, below)
|
498
|
+
if eve is not None:
|
499
|
+
if self.selfIntersection:
|
500
|
+
toggle = False
|
501
|
+
if ev.seg.myfill.below is None:
|
502
|
+
toggle = True
|
503
|
+
else:
|
504
|
+
toggle = ev.seg.myfill.above != ev.seg.myfill.below
|
505
|
+
|
506
|
+
if toggle:
|
507
|
+
eve.seg.myfill.above = not eve.seg.myfill.above
|
508
|
+
else:
|
509
|
+
eve.seg.otherfill = ev.seg.myfill
|
510
|
+
ev.other.remove()
|
511
|
+
ev.remove()
|
512
|
+
|
513
|
+
if self.__eventRoot.getHead() is not ev:
|
514
|
+
continue
|
515
|
+
|
516
|
+
if self.selfIntersection:
|
517
|
+
toggle = False
|
518
|
+
if ev.seg.myfill.below is None:
|
519
|
+
toggle = True
|
520
|
+
else:
|
521
|
+
toggle = ev.seg.myfill.above != ev.seg.myfill.below
|
522
|
+
|
523
|
+
if below is None:
|
524
|
+
ev.seg.myfill.below = primaryPolyInverted
|
525
|
+
else:
|
526
|
+
ev.seg.myfill.below = below.seg.myfill.above
|
527
|
+
|
528
|
+
if toggle:
|
529
|
+
ev.seg.myfill.above = not ev.seg.myfill.below
|
530
|
+
else:
|
531
|
+
ev.seg.myfill.above = ev.seg.myfill.below
|
532
|
+
else:
|
533
|
+
if ev.seg.otherfill is None:
|
534
|
+
inside = False
|
535
|
+
if below is None:
|
536
|
+
inside = (
|
537
|
+
secondaryPolyInverted
|
538
|
+
if ev.primary
|
539
|
+
else primaryPolyInverted
|
540
|
+
)
|
541
|
+
else:
|
542
|
+
if ev.primary == below.primary:
|
543
|
+
inside = below.seg.otherfill.above
|
544
|
+
else:
|
545
|
+
inside = below.seg.myfill.above
|
546
|
+
ev.seg.otherfill = Fill(inside, inside)
|
547
|
+
ev.other.status = surrounding.insert(LinkedList.node(Node(ev=ev)))
|
548
|
+
else:
|
549
|
+
st = ev.status
|
550
|
+
if st is None:
|
551
|
+
raise PolyBoolException(
|
552
|
+
"PolyBool: Zero-length segment detected; your epsilon is probably too small or too large"
|
553
|
+
)
|
554
|
+
if statusRoot.exists(st.previous) and statusRoot.exists(st.next):
|
555
|
+
self.__checkIntersection(st.previous.ev, st.next.ev)
|
556
|
+
st.remove()
|
557
|
+
|
558
|
+
if not ev.primary:
|
559
|
+
s = ev.seg.myfill
|
560
|
+
ev.seg.myfill = ev.seg.otherfill
|
561
|
+
ev.seg.otherfill = s
|
562
|
+
segments.append(ev.seg)
|
563
|
+
self.__eventRoot.getHead().remove()
|
564
|
+
return segments
|
565
|
+
|
566
|
+
|
567
|
+
class RegionIntersecter(Intersecter):
|
568
|
+
def __init__(self) -> None:
|
569
|
+
super().__init__(True)
|
570
|
+
|
571
|
+
def addRegion(self, region: Region):
|
572
|
+
pt1: Point
|
573
|
+
pt2 = region[-1]
|
574
|
+
for i in range(len(region)):
|
575
|
+
pt1 = pt2
|
576
|
+
pt2 = region[i]
|
577
|
+
forward = Point.compare(pt1, pt2)
|
578
|
+
|
579
|
+
if forward == 0:
|
580
|
+
continue
|
581
|
+
|
582
|
+
seg = self.newsegment(
|
583
|
+
pt1 if forward < 0 else pt2, pt2 if forward < 0 else pt1
|
584
|
+
)
|
585
|
+
|
586
|
+
self.eventAddSegment(seg, True)
|
587
|
+
|
588
|
+
def calculate(self, inverted: bool):
|
589
|
+
return super().calculate(inverted, False)
|
590
|
+
|
591
|
+
|
592
|
+
class SegmentIntersecter(Intersecter):
|
593
|
+
def __init__(self) -> None:
|
594
|
+
super().__init__(False)
|
595
|
+
|
596
|
+
def calculate(
|
597
|
+
self,
|
598
|
+
segments1: typing.List[Segment],
|
599
|
+
isInverted1: bool,
|
600
|
+
segments2: typing.List[Segment],
|
601
|
+
isInverted2: bool,
|
602
|
+
):
|
603
|
+
for seg in segments1:
|
604
|
+
self.eventAddSegment(self.segmentCopy(seg.start, seg.end, seg), True)
|
605
|
+
|
606
|
+
for seg in segments2:
|
607
|
+
self.eventAddSegment(self.segmentCopy(seg.start, seg.end, seg), False)
|
608
|
+
|
609
|
+
return super().calculate(isInverted1, isInverted2)
|
610
|
+
|
611
|
+
|
612
|
+
class SegmentChainerMatcher:
|
613
|
+
def __init__(self) -> None:
|
614
|
+
self.firstMatch = Matcher(0, False, False)
|
615
|
+
self.secondMatch = Matcher(0, False, False)
|
616
|
+
|
617
|
+
self.nextMatch = self.firstMatch
|
618
|
+
|
619
|
+
def setMatch(self, index: int, matchesHead: bool, matchesPt1: bool):
|
620
|
+
self.nextMatch.index = index
|
621
|
+
self.nextMatch.matchesHead = matchesHead
|
622
|
+
self.nextMatch.matchesPt1 = matchesPt1
|
623
|
+
if self.nextMatch is self.firstMatch:
|
624
|
+
self.nextMatch = self.secondMatch
|
625
|
+
return False
|
626
|
+
self.nextMatch = None
|
627
|
+
return True
|
628
|
+
|
629
|
+
|
630
|
+
def list_shift(list: typing.List):
|
631
|
+
list.pop(0)
|
632
|
+
|
633
|
+
|
634
|
+
def list_pop(list: typing.List):
|
635
|
+
list.pop()
|
636
|
+
|
637
|
+
|
638
|
+
def list_splice(list: typing.List, index: int, count: int):
|
639
|
+
del list[index : index + count]
|
640
|
+
|
641
|
+
|
642
|
+
def list_unshift(list: typing.List[T], element: T):
|
643
|
+
list.insert(0, element)
|
644
|
+
|
645
|
+
|
646
|
+
def segmentChainer(segments: typing.List[Segment]) -> typing.List[Region]:
|
647
|
+
regions: typing.List[Region] = []
|
648
|
+
chains: typing.List[typing.List[Point]] = []
|
649
|
+
|
650
|
+
for seg in segments:
|
651
|
+
pt1 = seg.start
|
652
|
+
pt2 = seg.end
|
653
|
+
if pt1 == pt2:
|
654
|
+
continue
|
655
|
+
|
656
|
+
scm = SegmentChainerMatcher()
|
657
|
+
|
658
|
+
for i in range(len(chains)):
|
659
|
+
chain = chains[i]
|
660
|
+
head = chain[0]
|
661
|
+
tail = chain[-1]
|
662
|
+
|
663
|
+
if head == pt1:
|
664
|
+
if scm.setMatch(i, True, True):
|
665
|
+
break
|
666
|
+
elif head == pt2:
|
667
|
+
if scm.setMatch(i, True, False):
|
668
|
+
break
|
669
|
+
elif tail == pt1:
|
670
|
+
if scm.setMatch(i, False, True):
|
671
|
+
break
|
672
|
+
elif tail == pt2:
|
673
|
+
if scm.setMatch(i, False, False):
|
674
|
+
break
|
675
|
+
|
676
|
+
if scm.nextMatch is scm.firstMatch:
|
677
|
+
chains.append([pt1, pt2])
|
678
|
+
continue
|
679
|
+
|
680
|
+
if scm.nextMatch is scm.secondMatch:
|
681
|
+
index = scm.firstMatch.index
|
682
|
+
pt = pt2 if scm.firstMatch.matchesPt1 else pt1
|
683
|
+
addToHead = scm.firstMatch.matchesHead
|
684
|
+
|
685
|
+
chain = chains[index]
|
686
|
+
grow = chain[0] if addToHead else chain[-1]
|
687
|
+
grow2 = chain[1] if addToHead else chain[-2]
|
688
|
+
oppo = chain[-1] if addToHead else chain[0]
|
689
|
+
oppo2 = chain[-2] if addToHead else chain[1]
|
690
|
+
|
691
|
+
if Point.collinear(grow2, grow, pt):
|
692
|
+
if addToHead:
|
693
|
+
list_shift(chain)
|
694
|
+
else:
|
695
|
+
list_pop(chain)
|
696
|
+
grow = grow2
|
697
|
+
if oppo == pt:
|
698
|
+
list_splice(chains, index, 1)
|
699
|
+
if Point.collinear(oppo2, oppo, grow):
|
700
|
+
if addToHead:
|
701
|
+
list_pop(chain)
|
702
|
+
else:
|
703
|
+
list_shift(chain)
|
704
|
+
regions.append(chain)
|
705
|
+
continue
|
706
|
+
if addToHead:
|
707
|
+
list_unshift(chain, pt)
|
708
|
+
else:
|
709
|
+
chain.append(pt)
|
710
|
+
continue
|
711
|
+
|
712
|
+
def reverseChain(index: int):
|
713
|
+
chains[index].reverse()
|
714
|
+
|
715
|
+
def appendChain(index1: int, index2: int):
|
716
|
+
chain1 = chains[index1]
|
717
|
+
chain2 = chains[index2]
|
718
|
+
tail = chain1[-1]
|
719
|
+
tail2 = chain1[-2]
|
720
|
+
head = chain2[0]
|
721
|
+
head2 = chain2[1]
|
722
|
+
|
723
|
+
if Point.collinear(tail2, tail, head):
|
724
|
+
list_pop(chain1)
|
725
|
+
tail = tail2
|
726
|
+
if Point.collinear(tail, head, head2):
|
727
|
+
list_shift(chain2)
|
728
|
+
|
729
|
+
chains[index1] = chain1 + chain2
|
730
|
+
list_splice(chains, index2, 1)
|
731
|
+
|
732
|
+
f = scm.firstMatch.index
|
733
|
+
s = scm.secondMatch.index
|
734
|
+
|
735
|
+
reverseF = len(chains[f]) < len(chains[s])
|
736
|
+
if scm.firstMatch.matchesHead:
|
737
|
+
if scm.secondMatch.matchesHead:
|
738
|
+
if reverseF:
|
739
|
+
reverseChain(f)
|
740
|
+
appendChain(f, s)
|
741
|
+
else:
|
742
|
+
reverseChain(s)
|
743
|
+
appendChain(s, f)
|
744
|
+
else:
|
745
|
+
appendChain(s, f)
|
746
|
+
else:
|
747
|
+
if scm.secondMatch.matchesHead:
|
748
|
+
appendChain(f, s)
|
749
|
+
else:
|
750
|
+
if reverseF:
|
751
|
+
reverseChain(f)
|
752
|
+
appendChain(s, f)
|
753
|
+
else:
|
754
|
+
reverseChain(s)
|
755
|
+
appendChain(f, s)
|
756
|
+
|
757
|
+
return regions
|
758
|
+
|
759
|
+
|
760
|
+
def __select(segments: typing.List[Segment], selection: typing.List[int]):
|
761
|
+
result: typing.List[Segment] = []
|
762
|
+
for seg in segments:
|
763
|
+
index = (
|
764
|
+
(8 if seg.myfill.above else 0)
|
765
|
+
+ (4 if seg.myfill.below else 0)
|
766
|
+
+ (2 if seg.otherfill is not None and seg.otherfill.above else 0)
|
767
|
+
+ (1 if seg.otherfill is not None and seg.otherfill.below else 0)
|
768
|
+
)
|
769
|
+
|
770
|
+
if selection[index] != 0:
|
771
|
+
result.append(
|
772
|
+
Segment(
|
773
|
+
start=seg.start,
|
774
|
+
end=seg.end,
|
775
|
+
myfill=Fill(selection[index] == 2, above=selection[index] == 1),
|
776
|
+
)
|
777
|
+
)
|
778
|
+
return result
|
779
|
+
|
780
|
+
|
781
|
+
# core API
|
782
|
+
def segments(poly: Polygon) -> PolySegments:
|
783
|
+
i = RegionIntersecter()
|
784
|
+
for region in poly.regions:
|
785
|
+
i.addRegion(region)
|
786
|
+
return PolySegments(i.calculate(poly.isInverted), poly.isInverted)
|
787
|
+
|
788
|
+
|
789
|
+
def combine(segments1: PolySegments, segments2: PolySegments) -> CombinedPolySegments:
|
790
|
+
i = SegmentIntersecter()
|
791
|
+
return CombinedPolySegments(
|
792
|
+
i.calculate(
|
793
|
+
segments1.segments,
|
794
|
+
segments1.isInverted,
|
795
|
+
segments2.segments,
|
796
|
+
segments2.isInverted,
|
797
|
+
),
|
798
|
+
segments1.isInverted,
|
799
|
+
segments2.isInverted,
|
800
|
+
)
|
801
|
+
|
802
|
+
|
803
|
+
def selectUnion(polyseg: CombinedPolySegments) -> PolySegments:
|
804
|
+
return PolySegments(
|
805
|
+
segments=__select(
|
806
|
+
# fmt:off
|
807
|
+
polyseg.combined, [
|
808
|
+
0, 2, 1, 0,
|
809
|
+
2, 2, 0, 0,
|
810
|
+
1, 0, 1, 0,
|
811
|
+
0, 0, 0, 0,
|
812
|
+
]
|
813
|
+
# fmt:on
|
814
|
+
),
|
815
|
+
isInverted=(polyseg.isInverted1 or polyseg.isInverted2),
|
816
|
+
)
|
817
|
+
|
818
|
+
|
819
|
+
def selectIntersect(polyseg: CombinedPolySegments) -> PolySegments:
|
820
|
+
return PolySegments(
|
821
|
+
segments=__select(
|
822
|
+
# fmt:off
|
823
|
+
polyseg.combined, [
|
824
|
+
0, 0, 0, 0,
|
825
|
+
0, 2, 0, 2,
|
826
|
+
0, 0, 1, 1,
|
827
|
+
0, 2, 1, 0
|
828
|
+
]
|
829
|
+
# fmt:on
|
830
|
+
),
|
831
|
+
isInverted=(polyseg.isInverted1 and polyseg.isInverted2),
|
832
|
+
)
|
833
|
+
|
834
|
+
|
835
|
+
def selectDifference(polyseg: CombinedPolySegments) -> PolySegments:
|
836
|
+
return PolySegments(
|
837
|
+
segments=__select(
|
838
|
+
# fmt:off
|
839
|
+
polyseg.combined, [
|
840
|
+
0, 0, 0, 0,
|
841
|
+
2, 0, 2, 0,
|
842
|
+
1, 1, 0, 0,
|
843
|
+
0, 1, 2, 0
|
844
|
+
]
|
845
|
+
# fmt:on
|
846
|
+
),
|
847
|
+
isInverted=(polyseg.isInverted1 and not polyseg.isInverted2),
|
848
|
+
)
|
849
|
+
|
850
|
+
|
851
|
+
def selectDifferenceRev(polyseg: CombinedPolySegments) -> PolySegments:
|
852
|
+
return PolySegments(
|
853
|
+
segments=__select(
|
854
|
+
# fmt:off
|
855
|
+
polyseg.combined, [
|
856
|
+
0, 2, 1, 0,
|
857
|
+
0, 0, 1, 1,
|
858
|
+
0, 2, 0, 2,
|
859
|
+
0, 0, 0, 0
|
860
|
+
]
|
861
|
+
# fmt:on
|
862
|
+
),
|
863
|
+
isInverted=(not polyseg.isInverted1 and polyseg.isInverted2),
|
864
|
+
)
|
865
|
+
|
866
|
+
|
867
|
+
def selectXor(polyseg: CombinedPolySegments) -> PolySegments:
|
868
|
+
return PolySegments(
|
869
|
+
segments=__select(
|
870
|
+
# fmt:off
|
871
|
+
polyseg.combined, [
|
872
|
+
0, 2, 1, 0,
|
873
|
+
2, 0, 0, 1,
|
874
|
+
1, 0, 0, 2,
|
875
|
+
0, 1, 2, 0
|
876
|
+
]
|
877
|
+
# fmt:on
|
878
|
+
),
|
879
|
+
isInverted=(polyseg.isInverted1 != polyseg.isInverted2),
|
880
|
+
)
|
881
|
+
|
882
|
+
|
883
|
+
def polygon(segments: PolySegments):
|
884
|
+
return Polygon(segmentChainer(segments.segments), segments.isInverted)
|
885
|
+
|
886
|
+
|
887
|
+
def __operate(
|
888
|
+
poly1: Polygon,
|
889
|
+
poly2: Polygon,
|
890
|
+
selector: typing.Callable[[CombinedPolySegments], PolySegments],
|
891
|
+
):
|
892
|
+
firstPolygonRegions = segments(poly1)
|
893
|
+
secondPolygonRegions = segments(poly2)
|
894
|
+
combinedSegments = combine(firstPolygonRegions, secondPolygonRegions)
|
895
|
+
seg = selector(combinedSegments)
|
896
|
+
return polygon(seg)
|
897
|
+
|
898
|
+
|
899
|
+
# helper functions for common operations
|
900
|
+
|
901
|
+
|
902
|
+
@typing.overload
|
903
|
+
def union(polygons: typing.List[Polygon]) -> Polygon:
|
904
|
+
...
|
905
|
+
|
906
|
+
|
907
|
+
@typing.overload
|
908
|
+
def union(poly1: Polygon, poly2: Polygon) -> Polygon:
|
909
|
+
...
|
910
|
+
|
911
|
+
|
912
|
+
def union(*args):
|
913
|
+
if len(args) == 1 and isinstance(args[0], list):
|
914
|
+
polygons = args[0]
|
915
|
+
seg1 = segments(polygons[0])
|
916
|
+
for i in range(1, len(polygons)):
|
917
|
+
seg2 = segments(polygons[i])
|
918
|
+
comb = combine(seg1, seg2)
|
919
|
+
seg1 = selectUnion(comb)
|
920
|
+
|
921
|
+
return polygon(seg1)
|
922
|
+
elif (
|
923
|
+
len(args) == 2 and isinstance(args[0], Polygon) and isinstance(args[1], Polygon)
|
924
|
+
):
|
925
|
+
return __operate(args[0], args[1], selectUnion)
|
926
|
+
|
927
|
+
|
928
|
+
def intersect(poly1: Polygon, poly2: Polygon):
|
929
|
+
return __operate(poly1, poly2, selectIntersect)
|
930
|
+
|
931
|
+
|
932
|
+
def difference(poly1: Polygon, poly2: Polygon):
|
933
|
+
return __operate(poly1, poly2, selectDifference)
|
934
|
+
|
935
|
+
|
936
|
+
def differenceRev(poly1: Polygon, poly2: Polygon):
|
937
|
+
return __operate(poly1, poly2, selectDifferenceRev)
|
938
|
+
|
939
|
+
|
940
|
+
def xor(poly1: Polygon, poly2: Polygon):
|
941
|
+
return __operate(poly1, poly2, selectXor)
|