From 27d42268b620fa12cdaad64c9e78c664192141aa Mon Sep 17 00:00:00 2001 From: larsevj Date: Tue, 3 Sep 2024 14:14:13 +0200 Subject: [PATCH] Add test case for Fault.extend_to_b_box --- python/resdata/grid/faults/fault.py | 8 ++++---- python/tests/rd_tests/test_faults.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/python/resdata/grid/faults/fault.py b/python/resdata/grid/faults/fault.py index b25a42758..a02bcfeef 100644 --- a/python/resdata/grid/faults/fault.py +++ b/python/resdata/grid/faults/fault.py @@ -260,7 +260,7 @@ def get_neighbor_cells(self): def get_polyline(self, k): layer = self[k] - return layer.getPolyline(name="Polyline[%s]" % self.getName()) + return layer.getPolyline(name="Polyline[%s]" % self.get_name()) def get_ij_polyline(self, k): layer = self[k] @@ -390,7 +390,7 @@ def extend_to_edge(self, edge, k): return self.extendToPolyline(edge, k) def extend_to_b_box(self, bbox, k, start=True): - fault_polyline = self.getPolyline(k) + fault_polyline = self.get_polyline(k) if start: p0 = fault_polyline[1] p1 = fault_polyline[0] @@ -402,8 +402,8 @@ def extend_to_b_box(self, bbox, k, start=True): intersections = GeometryTools.rayPolygonIntersections(p1, ray_dir, bbox) if intersections: p2 = intersections[0][1] - if self.getName(): - name = "Extend:%s" % self.getName() + if self.get_name(): + name = "Extend:%s" % self.get_name() else: name = None diff --git a/python/tests/rd_tests/test_faults.py b/python/tests/rd_tests/test_faults.py index 7bf5b6249..f6242ffae 100644 --- a/python/tests/rd_tests/test_faults.py +++ b/python/tests/rd_tests/test_faults.py @@ -787,3 +787,24 @@ def test_connectWithPolyline(self): self.assertEqual(p1, (2, 1)) self.assertEqual(p2, (2, 2)) + + def test_extend_to_bbox(self): + bbox = [(0, 0), (10, 0), (10, 10), (0, 10)] + grid = GridGenerator.create_rectangular((4, 4, 1), (1, 1, 1)) + fault1 = Fault(grid, "Fault1") + fault2 = Fault(grid, "Fault2") + fault1.add_record(0, 3, 1, 1, 0, 0, "Y") + fault2.add_record(1, 1, 0, 1, 0, 0, "X") + + with pytest.raises( + Exception, match="Logical error - must intersect with bounding box" + ): + fault1.extend_to_b_box(bbox, 0, start=True) + + line1 = fault1.extend_to_b_box(bbox, 0, start=False) + assert line1.getName() == "Extend:Fault1" + assert line1 == CPolyline(init_points=[(4, 2), (10, 2)]) + + line2 = fault2.extend_to_b_box(bbox, 0, start=True) + assert line2.getName() == "Extend:Fault2" + assert line2 == CPolyline(init_points=[(2, 0), (2, 0)])