Fixes polygon finding for painting. Function find_polygon made a method of Geometry. Solves Issue #96.
This commit is contained in:
@@ -957,12 +957,13 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||||||
def paint_poly(self, inside_pt, tooldia, overlap):
|
def paint_poly(self, inside_pt, tooldia, overlap):
|
||||||
|
|
||||||
# Which polygon.
|
# Which polygon.
|
||||||
poly = find_polygon(self.solid_geometry, inside_pt)
|
#poly = find_polygon(self.solid_geometry, inside_pt)
|
||||||
|
poly = self.find_polygon(inside_pt)
|
||||||
|
|
||||||
# No polygon?
|
# No polygon?
|
||||||
if poly is None:
|
if poly is None:
|
||||||
self.app.log.warning('No polygon found.')
|
self.app.log.warning('No polygon found.')
|
||||||
self.app.inform('[warning] No polygon found.')
|
self.app.inform.emit('[warning] No polygon found.')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Initializes the new geometry object
|
# Initializes the new geometry object
|
||||||
|
|||||||
79
camlib.py
79
camlib.py
@@ -172,7 +172,7 @@ class Geometry(object):
|
|||||||
|
|
||||||
return self.flat_geometry
|
return self.flat_geometry
|
||||||
|
|
||||||
def make2Dindex(self):
|
def make2Dstorage(self):
|
||||||
|
|
||||||
self.flatten()
|
self.flatten()
|
||||||
|
|
||||||
@@ -187,11 +187,11 @@ class Geometry(object):
|
|||||||
pts += list(o.coords)
|
pts += list(o.coords)
|
||||||
return pts
|
return pts
|
||||||
|
|
||||||
idx = FlatCAMRTreeStorage()
|
storage = FlatCAMRTreeStorage()
|
||||||
idx.get_points = get_pts
|
storage.get_points = get_pts
|
||||||
for shape in self.flat_geometry:
|
for shape in self.flat_geometry:
|
||||||
idx.insert(shape)
|
storage.insert(shape)
|
||||||
return idx
|
return storage
|
||||||
|
|
||||||
# def flatten_to_paths(self, geometry=None, reset=True):
|
# def flatten_to_paths(self, geometry=None, reset=True):
|
||||||
# """
|
# """
|
||||||
@@ -441,6 +441,36 @@ class Geometry(object):
|
|||||||
"""
|
"""
|
||||||
self.solid_geometry = [cascaded_union(self.solid_geometry)]
|
self.solid_geometry = [cascaded_union(self.solid_geometry)]
|
||||||
|
|
||||||
|
def find_polygon(self, point, geoset=None):
|
||||||
|
"""
|
||||||
|
Find an object that object.contains(Point(point)) in
|
||||||
|
poly, which can can be iterable, contain iterable of, or
|
||||||
|
be itself an implementer of .contains().
|
||||||
|
|
||||||
|
:param poly: See description
|
||||||
|
:return: Polygon containing point or None.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if geoset is None:
|
||||||
|
geoset = self.solid_geometry
|
||||||
|
|
||||||
|
try: # Iterable
|
||||||
|
for sub_geo in geoset:
|
||||||
|
p = self.find_polygon(point, geoset=sub_geo)
|
||||||
|
if p is not None:
|
||||||
|
return p
|
||||||
|
|
||||||
|
except TypeError: # Non-iterable
|
||||||
|
|
||||||
|
try: # Implements .contains()
|
||||||
|
if geoset.contains(Point(point)):
|
||||||
|
return geoset
|
||||||
|
|
||||||
|
except AttributeError: # Does not implement .contains()
|
||||||
|
return None
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class ApertureMacro:
|
class ApertureMacro:
|
||||||
"""
|
"""
|
||||||
@@ -2908,19 +2938,32 @@ def arc_angle(start, stop, direction):
|
|||||||
return angle
|
return angle
|
||||||
|
|
||||||
|
|
||||||
def find_polygon(poly_set, point):
|
# def find_polygon(poly, point):
|
||||||
"""
|
# """
|
||||||
Return the first polygon in the list of polygons poly_set
|
# Find an object that object.contains(Point(point)) in
|
||||||
that contains the given point.
|
# poly, which can can be iterable, contain iterable of, or
|
||||||
"""
|
# be itself an implementer of .contains().
|
||||||
if poly_set is None:
|
#
|
||||||
return None
|
# :param poly: See description
|
||||||
|
# :return: Polygon containing point or None.
|
||||||
p = Point(point)
|
# """
|
||||||
for poly in poly_set:
|
#
|
||||||
if poly.contains(p):
|
# if poly is None:
|
||||||
return poly
|
# return None
|
||||||
return None
|
#
|
||||||
|
# try:
|
||||||
|
# for sub_poly in poly:
|
||||||
|
# p = find_polygon(sub_poly, point)
|
||||||
|
# if p is not None:
|
||||||
|
# return p
|
||||||
|
# except TypeError:
|
||||||
|
# try:
|
||||||
|
# if poly.contains(Point(point)):
|
||||||
|
# return poly
|
||||||
|
# except AttributeError:
|
||||||
|
# return None
|
||||||
|
#
|
||||||
|
# return None
|
||||||
|
|
||||||
|
|
||||||
def to_dict(obj):
|
def to_dict(obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user