From c43b70cba5edcea6488892ba8bbb7ff2a162ee1f Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 28 Aug 2020 02:25:05 +0300 Subject: [PATCH] - fixed a borderline issue in CNCJob UI Autolevelling - Voronoi polygons calculations --- CHANGELOG.md | 1 + appObjects/FlatCAMCNCJob.py | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df6d10d..1ff06c8f 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/appObjects/FlatCAMCNCJob.py b/appObjects/FlatCAMCNCJob.py index 5edb5ef3..159a0727 100644 --- a/appObjects/FlatCAMCNCJob.py +++ b/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