Commit d45b6dcb authored by Whitham D. Reeve II's avatar Whitham D. Reeve II

Fixed a floating point issue that caused a zero length line in a polygon simplification algorithm.

parent ce372171
...@@ -25,7 +25,8 @@ from pycam.Geometry.PointUtils import * ...@@ -25,7 +25,8 @@ from pycam.Geometry.PointUtils import *
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
from pycam.Geometry import TransformableContainer, IDGenerator, get_bisector from pycam.Geometry import TransformableContainer, IDGenerator, get_bisector
from pycam.Geometry.utils import number, epsilon from pycam.Geometry.utils import number, epsilon
import pycam.Utils.log from pycam.Utils import log
log = log.get_logger()
# import later to avoid circular imports # import later to avoid circular imports
#from pycam.Geometry.Model import ContourModel #from pycam.Geometry.Model import ContourModel
...@@ -39,9 +40,6 @@ except ImportError: ...@@ -39,9 +40,6 @@ except ImportError:
LINE_WIDTH_INNER = 0.7 LINE_WIDTH_INNER = 0.7
LINE_WIDTH_OUTER = 1.3 LINE_WIDTH_OUTER = 1.3
log = pycam.Utils.log.get_logger()
class PolygonInTree(IDGenerator): class PolygonInTree(IDGenerator):
""" This class is a wrapper around Polygon objects that is used for sorting. """ This class is a wrapper around Polygon objects that is used for sorting.
""" """
...@@ -909,8 +907,7 @@ class Polygon(TransformableContainer): ...@@ -909,8 +907,7 @@ class Polygon(TransformableContainer):
line1 = new_group[index1] line1 = new_group[index1]
line2 = new_group[index2] line2 = new_group[index2]
intersection, factor = line1.get_intersection(line2) intersection, factor = line1.get_intersection(line2)
if intersection and (intersection != line1.p1) \ if intersection and (pnorm(psub(intersection, line1.p1)) > epsilon) and (pnorm(psub(intersection, line1.p2)) > epsilon):
and (intersection != line1.p2):
del new_group[index1] del new_group[index1]
new_group.insert(index1, new_group.insert(index1,
Line(line1.p1, intersection)) Line(line1.p1, intersection))
...@@ -942,6 +939,7 @@ class Polygon(TransformableContainer): ...@@ -942,6 +939,7 @@ class Polygon(TransformableContainer):
for group_start in group_starts: for group_start in group_starts:
groups.append(new_group[last_start:group_start]) groups.append(new_group[last_start:group_start])
last_start = group_start last_start = group_start
# Add the remaining lines to the first group or as a new # Add the remaining lines to the first group or as a new
# group. # group.
if groups[0][0].p1 == new_group[-1].p2: if groups[0][0].p1 == new_group[-1].p2:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment