Fixes polygon finding for painting. Function find_polygon made a method of Geometry. Solves Issue #96.

This commit is contained in:
jpcaram
2015-01-14 20:24:37 -05:00
parent 6582a6c748
commit 4c234fcd55
2 changed files with 64 additions and 20 deletions

View File

@@ -957,12 +957,13 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
def paint_poly(self, inside_pt, tooldia, overlap):
# 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?
if poly is None:
self.app.log.warning('No polygon found.')
self.app.inform('[warning] No polygon found.')
self.app.inform.emit('[warning] No polygon found.')
return
# Initializes the new geometry object

View File

@@ -172,7 +172,7 @@ class Geometry(object):
return self.flat_geometry
def make2Dindex(self):
def make2Dstorage(self):
self.flatten()
@@ -187,11 +187,11 @@ class Geometry(object):
pts += list(o.coords)
return pts
idx = FlatCAMRTreeStorage()
idx.get_points = get_pts
storage = FlatCAMRTreeStorage()
storage.get_points = get_pts
for shape in self.flat_geometry:
idx.insert(shape)
return idx
storage.insert(shape)
return storage
# def flatten_to_paths(self, geometry=None, reset=True):
# """
@@ -441,6 +441,36 @@ class Geometry(object):
"""
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:
"""
@@ -2908,19 +2938,32 @@ def arc_angle(start, stop, direction):
return angle
def find_polygon(poly_set, point):
"""
Return the first polygon in the list of polygons poly_set
that contains the given point.
"""
if poly_set is None:
return None
p = Point(point)
for poly in poly_set:
if poly.contains(p):
return poly
return None
# def find_polygon(poly, point):
# """
# 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 poly is 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):