def extendPolylineOnto(self, polyline, k): if self.intersectsPolyline(polyline, k): return None if len(polyline) > 1: fault_polyline = self.getPolyline(k) ext1 = self.__rayIntersect(polyline[-2], polyline[-1], fault_polyline) ext2 = self.__rayIntersect(polyline[0], polyline[1], fault_polyline) if ext1 and ext2: d1 = GeometryTools.distance(ext1[0], ext1[1]) d2 = GeometryTools.distance(ext2[0], ext2[1]) if d1 < d2: return ext1 else: return ext2 if ext1: return ext1 else: return ext2 else: raise ValueError("Polyline must have length >= 2")
def extendToFault(self , other_fault , k): polyline = self.getIJPolyline(k) p0 = polyline[-2] p1 = polyline[-1] ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , other_fault.getIJPolyline(k)) if intersections: p2 = intersections[0][1] return [p1 , (int(p2[0]) , int(p2[1])) ] p0 = polyline[1] p1 = polyline[0] ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , other_fault.getIJPolyline(k)) if intersections: if len(intersections) > 1: d_list = [ GeometryTools.distance( p1 , p[1] ) for p in intersections ] index = d_list.index( min(d_list) ) else: index = 0 p2 = intersections[index][1] return [p1 , (int(p2[0]) , int(p2[1])) ] raise ValueError("The fault %s can not be extended to intersect with:%s in layer:%d" % (self.getName() , other_fault.getName() , k+1 ))
def __rayIntersect(p0, p1 , polyline): ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , polyline) if intersections: if len(intersections) > 1: d_list = [ GeometryTools.distance( p1 , p[1] ) for p in intersections ] index = d_list.index( min(d_list) ) else: index = 0 p2 = intersections[index][1] return [p1 , p2] else: return None
def extendPolylineOnto(self , polyline , k): if self.intersectsPolyline( polyline , k): return None if len(polyline) > 1: fault_polyline = self.getPolyline(k) ext1 = self.__rayIntersect( polyline[-2] , polyline[-1] , fault_polyline ) ext2 = self.__rayIntersect( polyline[0] , polyline[1] , fault_polyline ) if ext1 and ext2: d1 = GeometryTools.distance( ext1[0] , ext1[1] ) d2 = GeometryTools.distance( ext2[0] , ext2[1] ) if d1 < d2: return ext1 else: return ext2 if ext1: return ext1 else: return ext2 else: raise ValueError("Polyline must have length >= 2")
def test_distance(self): p1 = (1,1) p2 = (1,2,3) with self.assertRaises(ValueError): GeometryTools.distance( p1 , p2) with self.assertRaises(TypeError): GeometryTools.distance( 1 , p2 ) p2 = (2,2) self.assertEqual( GeometryTools.distance( p1 , p2) , math.sqrt(2)) p1 = (1,1,1) p2 = (2,2,2) self.assertEqual( GeometryTools.distance( p1 , p2) , math.sqrt(3))
def test_distance(self): p1 = (1, 1) p2 = (1, 2, 3) with self.assertRaises(ValueError): GeometryTools.distance(p1, p2) with self.assertRaises(TypeError): GeometryTools.distance(1, p2) p2 = (2, 2) self.assertEqual(GeometryTools.distance(p1, p2), math.sqrt(2)) p1 = (1, 1, 1) p2 = (2, 2, 2) self.assertEqual(GeometryTools.distance(p1, p2), math.sqrt(3))