예제 #1
0
    def test_polyline_intersection(self):
        grid = EclGrid.createRectangular((100, 100, 10), (0.25, 0.25, 1))

        #    Fault1                    Fault4
        #      |                         |
        #      |                         |
        #      |                         |
        #      |   -------  Fault2       |
        #      |                         |
        #      |                         |
        #                              (5 , 2.50)
        #          -------- Fault3
        #

        fault1 = Fault(grid, "Fault1")
        fault2 = Fault(grid, "Fault2")
        fault3 = Fault(grid, "Fault3")
        fault4 = Fault(grid, "Fault4")

        fault1.addRecord(1, 1, 10, grid.getNY() - 1, 0, 0, "X")
        fault2.addRecord(5, 10, 15, 15, 0, 0, "Y")
        fault3.addRecord(5, 10, 5, 5, 0, 0, "Y")
        fault4.addRecord(20, 20, 10, grid.getNY() - 1, 0, 0, "X")

        polyline = Polyline(init_points=[(4, 4), (8, 4)])
        self.assertTrue(fault4.intersectsPolyline(polyline, 0))

        cpolyline = CPolyline(init_points=[(4, 4), (8, 4)])
        self.assertTrue(fault4.intersectsPolyline(cpolyline, 0))

        polyline = Polyline(init_points=[(8, 4), (16, 4)])
        self.assertFalse(fault4.intersectsPolyline(polyline, 0))

        cpolyline = CPolyline(init_points=[(8, 4), (16, 4)])
        self.assertFalse(fault4.intersectsPolyline(cpolyline, 0))
예제 #2
0
    def test_construction_default(self):
        with self.assertRaises(TypeError):
            pl = Polyline(init_points=1)

        with self.assertRaises(TypeError):
            pl = Polyline(init_points=[1.23])

        pl = Polyline(init_points=[(1, 0), (1, 1), (1, 2)])
        self.assertEqual(len(pl), 3)
예제 #3
0
    def get_edge_polygon(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        cell_list = IntVector()

        self._trace_edge(x_list, y_list, cell_list)
        p = Polyline()
        for (x, y) in zip(x_list, y_list):
            p.addPoint(x, y)
        return p
예제 #4
0
    def get_edge_polygon(self):
        x_list = DoubleVector()
        y_list = DoubleVector()
        cell_list = IntVector()

        self._trace_edge(x_list, y_list, cell_list)
        p = Polyline()
        for (x,y) in zip(x_list, y_list):
            p.addPoint(x,y)
        return p
예제 #5
0
    def test_iteration(self):
        values = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1)]

        polyline = Polyline(name="iteration line")

        for p in values:
            polyline.addPoint(*p)

        for index, point in enumerate(polyline):
            self.assertEqual(point, values[index])
예제 #6
0
    def test_save(self):
        with TestAreaContext("polyline/fwrite") as work_area:
            p1 = Polyline(init_points=[(1, 0), (1, 1), (1, 2)])
            p2 = Polyline(init_points=[(1, 0), (1, 1), (1, 2)])
            self.assertTrue(p1 == p2)

            XYZIo.saveXYFile(p1, "poly.xy")

            p2 = XYZIo.readXYFile("poly.xy")
            self.assertTrue(p1 == p2)
예제 #7
0
    def test_closed(self):
        pl = Polyline( init_points = [(1,0) , (1,1) , (0,2)])
        self.assertFalse( pl.isClosed() )
        pl.addPoint( 1,0 )
        self.assertEqual( 4 , len(pl) ) 
        self.assertTrue( pl.isClosed() )

        pl = Polyline( init_points = [(1,0) , (1,1) , (0,2)])
        self.assertFalse( pl.isClosed() )
        pl.assertClosed( )
        self.assertEqual( 4 , len(pl) ) 
        self.assertTrue( pl.isClosed() )
예제 #8
0
    def test_iteration(self):
        values = [(0, 0, 0),
                  (1, 0, 0),
                  (1, 1, 0),
                  (1, 1, 1)]

        polyline = Polyline(name="iteration line")

        for p in values:
            polyline.addPoint(*p)

        for index, point in enumerate(polyline):
            self.assertEqual(point, values[index])
예제 #9
0
    def test_add(self):
        l1 = Polyline(init_points=[(-1, 0.5), (0.5, 0.5)])
        l2 = Polyline(init_points=[(-1, 0.5), (0.5, 0.5)])

        l3 = l1 + l2
        self.assertEqual(len(l3), 4)
        self.assertEqual(l1[0], l3[0])
        self.assertEqual(l1[1], l3[1])
        self.assertEqual(l1[0], l3[2])
        self.assertEqual(l1[1], l3[3])

        l4 = l1
        l4 += l2
        self.assertEqual(l3, l4)
예제 #10
0
    def test_intersection(self):
        p1 = Polyline(init_points=[(0, 0), (1, 0)])
        p2 = Polyline(init_points=[(0.5, 0.5), (0.5, -0.5)])
        p3 = Polyline(init_points=[(0, 1), (1, 1)])

        self.assertTrue(GeometryTools.polylinesIntersect(p1, p2))
        self.assertFalse(GeometryTools.polylinesIntersect(p2, p3))
        self.assertFalse(GeometryTools.polylinesIntersect(p1, p3))

        self.assertTrue(p1.intersects(p2))
        self.assertTrue(p2.intersects(p1))

        self.assertTrue(not p1.intersects(p3))
        self.assertTrue(not p3.intersects(p1))
예제 #11
0
    def test_add_polyline_barrier2(self):
        grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1))
        layer = FaultBlockLayer(self.grid, 0)
        polyline = Polyline(init_points=[(0.1, 0.9), (8.9, 0.9), (8.9, 8.9)])

        points = [
            ((0, 0), (0, 1)),
            ((2, 0), (2, 1)),
            ((4, 0), (4, 1)),
            ((6, 0), (6, 1)),
            ((8, 0), (8, 1)),
            #
            ((8, 1), (9, 1)),
            ((8, 3), (9, 3)),
            ((8, 5), (9, 5)),
            ((8, 7), (9, 7))
        ]

        geo_layer = layer.getGeoLayer()
        for p1, p2 in points:
            self.assertTrue(geo_layer.cellContact(p1, p2))

        layer.addPolylineBarrier(polyline)
        for p1, p2 in points:
            print(p1, p2)
            self.assertFalse(geo_layer.cellContact(p1, p2))
예제 #12
0
    def test_join__polylines(self):
        l1 = Polyline(init_points=[(0, 1), (1, 1)])
        l2 = CPolyline(init_points=[(2, -1), (2, 0)])
        l3 = CPolyline(init_points=[(2, 2), (2, 3)])
        l4 = Polyline()
        l5 = CPolyline(init_points=[(0.5, 0), (0.5, 2)])

        with self.assertRaises(ValueError):
            GeometryTools.joinPolylines(l1, l4)

        with self.assertRaises(ValueError):
            GeometryTools.joinPolylines(l4, l1)

        self.assertIsNone(GeometryTools.joinPolylines(l1, l5))

        self.assertEqual(GeometryTools.joinPolylines(l1, l2), [(1, 1), (2, 0)])
예제 #13
0
    def test_join_extend_polylines_onto(self):
        l1 = Polyline(init_points=[(0, 1), (1, 1)])
        l2 = CPolyline(init_points=[(2, 0), (2, 2)])
        l3 = CPolyline(init_points=[(0.5, 0), (0.5, 2)])
        l4 = Polyline(init_points=[(0, 5), (1, 5)])
        l5 = Polyline(init_points=[(0, 5)])

        self.assertIsNone(GeometryTools.connectPolylines(l1, l3))

        with self.assertRaises(ValueError):
            GeometryTools.connectPolylines(l1, l5)

        with self.assertRaises(ValueError):
            GeometryTools.connectPolylines(l1, l4)

        self.assertEqual(GeometryTools.connectPolylines(l1, l2), [(1, 1),
                                                                  (2, 1)])
예제 #14
0
    def test_intersects(self):
        polyline1 = CPolyline(init_points=[(0, 0), (1, 0), (1, 1)])
        polyline2 = CPolyline(init_points=[(0.50, 0.50), (1.50, 0.50)])
        polyline3 = Polyline(init_points=[(0.50, 0.50), (1.50, 0.50)])
        polyline4 = CPolyline(init_points=[(0.50, 1.50), (1.50, 1.50)])

        self.assertTrue(polyline1.intersects(polyline2))
        self.assertTrue(polyline1.intersects(polyline3))
        self.assertFalse(polyline1.intersects(polyline4))
예제 #15
0
    def test_extend_to_edge(self):
        bound = Polyline( init_points = [(0,0) , (1,0) , (1,1) , (0,1)] )
        l1 = Polyline( init_points = [(-1,0.5) , (0.5, 0.5)])
        l2 = Polyline( init_points = [(0.25,0.25) , (0.75, 0.75)])
        
        # Bound is not closed
        with self.assertRaises(AssertionError):
            GeometryTools.extendToEdge( bound , l1 )
            
        bound.assertClosed()
        # l1 is not fully contained in bound
        with self.assertRaises(ValueError):
            GeometryTools.extendToEdge( bound , l1 )

        l3 = GeometryTools.extendToEdge( bound , l2 )
        self.assertEqual( l3[0] , (0.00,0.00))
        self.assertEqual( l3[1] , (0.25,0.25))
        self.assertEqual( l3[2] , (0.75,0.75))
        self.assertEqual( l3[3] , (1.00,1.00))
        self.assertEqual( len(l3) , 4)
예제 #16
0
    def test_unzip(self):
        p2 = Polyline(init_points=[(1, 0), (1, 1), (1, 2)])
        p3 = Polyline(init_points=[(1, 0, 1), (1, 1, 2), (1, 2, 3)])
        (x, y) = p2.unzip()
        self.assertEqual(x, [1, 1, 1])
        self.assertEqual(y, [0, 1, 2])

        (x, y, z) = p3.unzip()
        self.assertEqual(x, [1, 1, 1])
        self.assertEqual(y, [0, 1, 2])
        self.assertEqual(z, [1, 2, 3])

        with self.assertRaises(ValueError):
            (x, y, z) = p2.unzip()

        with self.assertRaises(ValueError):
            (x, y) = p3.unzip()
예제 #17
0
    def test_add_polyline_barrier1(self):
        grid = EclGrid.createRectangular((4, 1, 1), (1, 1, 1))
        layer = FaultBlockLayer(self.grid, 0)
        polyline = Polyline(init_points=[(1.99, 0.001), (2.01, 0.99)])

        points = [((1, 0), (2, 0))]

        geo_layer = layer.getGeoLayer()
        for p1, p2 in points:
            self.assertTrue(geo_layer.cellContact(p1, p2))

        layer.addPolylineBarrier(polyline)
        for p1, p2 in points:
            print(p1, p2)
            self.assertFalse(geo_layer.cellContact(p1, p2))
예제 #18
0
    def test_intersection(self):
        p1 = Polyline( init_points = [(0,0) , (1,0)])
        p2 = Polyline( init_points = [(0.5 , 0.5) , (0.5,-0.5)])
        p3 = Polyline( init_points = [(0,1) , (1,1)])

        self.assertTrue(GeometryTools.polylinesIntersect( p1 , p2 ))
        self.assertFalse( GeometryTools.polylinesIntersect( p2 , p3 ))
        self.assertFalse( GeometryTools.polylinesIntersect( p1 , p3 ))

        self.assertTrue( p1.intersects(p2) )
        self.assertTrue( p2.intersects(p1) )

        self.assertTrue( not p1.intersects(p3) )
        self.assertTrue( not p3.intersects(p1) )
예제 #19
0
    def test_unzip(self):
        p2 = Polyline( init_points = [(1,0) , (1,1) , (1,2)])
        p3 = Polyline( init_points = [(1,0,1) , (1,1,2) , (1,2,3)])
        (x,y) = p2.unzip()
        self.assertEqual( x , [1,1,1])
        self.assertEqual( y , [0,1,2])

        (x,y,z) = p3.unzip()
        self.assertEqual( x , [1,1,1])
        self.assertEqual( y , [0,1,2])
        self.assertEqual( z , [1,2,3])


        with self.assertRaises(ValueError):
            (x,y,z) = p2.unzip()

        with self.assertRaises(ValueError):
            (x,y) = p3.unzip()
예제 #20
0
    def test_extend_to_edge(self):
        bound = Polyline(init_points=[(0, 0), (1, 0), (1, 1), (0, 1)])
        l1 = Polyline(init_points=[(-1, 0.5), (0.5, 0.5)])
        l2 = Polyline(init_points=[(0.25, 0.25), (0.75, 0.75)])

        # Bound is not closed
        with self.assertRaises(AssertionError):
            GeometryTools.extendToEdge(bound, l1)

        bound.assertClosed()
        # l1 is not fully contained in bound
        with self.assertRaises(ValueError):
            GeometryTools.extendToEdge(bound, l1)

        l3 = GeometryTools.extendToEdge(bound, l2)
        self.assertEqual(l3[0], (0.00, 0.00))
        self.assertEqual(l3[1], (0.25, 0.25))
        self.assertEqual(l3[2], (0.75, 0.75))
        self.assertEqual(l3[3], (1.00, 1.00))
        self.assertEqual(len(l3), 4)
예제 #21
0
    def test_construction(self):
        polyline = Polyline(name="test line")

        with self.assertRaises(IndexError):
            polyline.isClosed()

        self.assertEqual(polyline.getName(), "test line")

        self.assertEqual(len(polyline), 0)

        polyline.addPoint(0, 0, 0)
        self.assertEqual(len(polyline), 1)

        polyline.addPoint(1, 1, 0)
        self.assertEqual(len(polyline), 2)

        polyline.addPoint(1, 1.5)
        self.assertEqual(len(polyline), 3)

        self.assertEqual(polyline[0], (0, 0, 0))
        self.assertEqual(polyline[1], (1, 1, 0))
        self.assertEqual(polyline[2], (1, 1.5))

        polyline.addPoint(0, 1, 0)
        self.assertFalse(polyline.isClosed())

        polyline.addPoint(0, 0, 0)
        self.assertTrue(polyline.isClosed())
예제 #22
0
    def test_nearest_point(self):
        l1 = Polyline(init_points=[(0, 0), (10, 0)])

        p = GeometryTools.nearestPointOnPolyline((5, 5), l1)
        self.assertEqual(p, (5, 0))
예제 #23
0
    def test_construction(self):
        polyline = Polyline(name="test line")

        with self.assertRaises(IndexError):
            polyline.isClosed()

        self.assertEqual(polyline.getName(), "test line")

        self.assertEqual(len(polyline), 0)

        polyline.addPoint(0, 0, 0)
        self.assertEqual(len(polyline), 1)

        polyline.addPoint(1, 1, 0)
        self.assertEqual(len(polyline), 2)

        polyline.addPoint(1, 1.5)
        self.assertEqual(len(polyline), 3)

        self.assertEqual(polyline[0], (0, 0, 0))
        self.assertEqual(polyline[1], (1, 1, 0))
        self.assertEqual(polyline[2], (1, 1.5))

        polyline.addPoint(0, 1, 0)
        self.assertFalse(polyline.isClosed())

        polyline.addPoint(0, 0, 0)
        self.assertTrue(polyline.isClosed())
예제 #24
0
    def test_closed(self):
        pl = Polyline(init_points=[(1, 0), (1, 1), (0, 2)])
        self.assertFalse(pl.isClosed())
        pl.addPoint(1, 0)
        self.assertEqual(4, len(pl))
        self.assertTrue(pl.isClosed())

        pl = Polyline(init_points=[(1, 0), (1, 1), (0, 2)])
        self.assertFalse(pl.isClosed())
        pl.assertClosed()
        self.assertEqual(4, len(pl))
        self.assertTrue(pl.isClosed())