Skip to content

Commit

Permalink
Add test case for Fault.extend_to_b_box
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Sep 3, 2024
1 parent 010fedc commit 27d4226
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/resdata/grid/faults/fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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

Expand Down
21 changes: 21 additions & 0 deletions python/tests/rd_tests/test_faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])

0 comments on commit 27d4226

Please sign in to comment.