Jelajahi Sumber

- fixed a borderline issue in CNCJob UI Autolevelling - Voronoi polygons calculations

Marius Stanciu 5 tahun lalu
induk
melakukan
c43b70cba5
2 mengubah file dengan 19 tambahan dan 12 penghapusan
  1. 1 0
      CHANGELOG.md
  2. 18 12
      appObjects/FlatCAMCNCJob.py

+ 1 - 0
CHANGELOG.md

@@ -21,6 +21,7 @@ CHANGELOG for FlatCAM beta
 - Tool Isolation - on Tool start it will attempt to load the Preferences set tools by diameter from Tools Database. If it can't find one there it will add a default tool.
 - in Tools: Transform, SUb, RulesCheck, DistanceMin, Distance - moved the Tool UI in its own class
 - some small fixes
+- fixed a borderline issue in CNCJob UI Autolevelling - Voronoi polygons calculations
 
 26.08.2020
 

+ 18 - 12
appObjects/FlatCAMCNCJob.py

@@ -843,25 +843,31 @@ class CNCJobObject(FlatCAMObj, CNCjob):
 
     def calculate_voronoi_diagram(self, pts):
         env = self.solid_geo.envelope
-        # fact = 1 if self.units == 'MM' else 0.039
-        # env = env.buffer(fact).exterior
+        fact = 1 if self.units == 'MM' else 0.039
+        env = env.buffer(fact)
 
         new_pts = deepcopy(pts)
-        for pt_index in range(len(pts)):
-            try:
-                pts_union = MultiPoint(pts)
-                voronoi_union = voronoi_diagram(geom=pts_union, envelope=env)
-                break
-            except Exception as e:
-                log.debug("CNCJobObject.calculate_voronoi_diagram() --> %s" % str(e))
+        try:
+            pts_union = MultiPoint(pts)
+            voronoi_union = voronoi_diagram(geom=pts_union, envelope=env)
+        except Exception as e:
+            log.debug("CNCJobObject.calculate_voronoi_diagram() --> %s" % str(e))
+            for pt_index in range(len(pts)):
                 new_pts[pt_index] = affinity.translate(
-                    new_pts[pt_index], random.random() *  1e-07, random.random() *  1e-07)
+                    new_pts[pt_index], random.random() *  1e-09, random.random() *  1e-09)
 
-                pts_union = MultiPoint(new_pts)
+            pts_union = MultiPoint(new_pts)
+            try:
                 voronoi_union = voronoi_diagram(geom=pts_union, envelope=env)
+            except Exception:
+                return
+
+        new_voronoi = []
+        for p in voronoi_union:
+            new_voronoi.append(p.intersection(env))
 
         for pt_key in list(self.al_geometry_dict.keys()):
-            for poly in voronoi_union:
+            for poly in new_voronoi:
                 if self.al_geometry_dict[pt_key]['point'].within(poly):
                     self.al_geometry_dict[pt_key]['geo'] = poly