diff --git a/camlib.py b/camlib.py index ef03c221..c0b20fc9 100644 --- a/camlib.py +++ b/camlib.py @@ -583,21 +583,24 @@ class Geometry(object): # No matches on either end #optimized_geometry.append(geo) - optimized_geometry.append(right) - storage.remove(right) - geo = right - print "stored right, now geo<-right" - # Next - #_, geo = storage.nearest(geo.coords[0]) - #optimized_geometry.append(geo) + storage.remove(right) + if type(right) == LinearRing: + # Put the linearring at the beginning so it does + # not iterfere. + optimized_geometry = [right] + optimized_geometry + geo = optimized_geometry[-1] + print "right was LinearRing, getting previous" + else: + optimized_geometry.append(right) + geo = right + print "stored right, now geo<-right" except StopIteration: # Nothing found in storage. pass print path_count - #self.flat_geometry = optimized_geometry return optimized_geometry def convert_units(self, units): diff --git a/tests/test_pathconnect.py b/tests/test_pathconnect.py index d49ae8ca..0bde0528 100644 --- a/tests/test_pathconnect.py +++ b/tests/test_pathconnect.py @@ -53,5 +53,21 @@ class PathConnectTest1(unittest.TestCase): [1 + offset_x, 1 + offset_y], [2 + offset_x, 1 + offset_y]]))) + def test_ring_interfere_connect(self): + print + print "TEST STARTING ..." + + paths = [ + LineString([[0, 0], [1, 1]]), + LineString([[1, 1], [2, 1]]), + LinearRing([[1, 1], [2, 2], [1, 3], [0, 2]]) + ] + + result = Geometry.path_connect(paths) + + self.assertEqual(len(result), 2) + matches = [p for p in result if p.equals(LineString([[0, 0], [1, 1], [2, 1]]))] + self.assertEqual(len(matches), 1) + if __name__ == "__main__": unittest.main() \ No newline at end of file