Example #1
0
File: fault.py Project: pgdr/libecl
    def extend_polyline_onto(self, polyline, k):
        if self.intersectsPolyline(polyline, k):
            return None

        if len(polyline) > 1:
            fault_polyline = self.getPolyline(k)
            ext1 = self.__ray_intersect(polyline[-2], polyline[-1],
                                        fault_polyline)
            ext2 = self.__ray_intersect(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")
Example #2
0
 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
Example #3
0
    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))