Repository: equinor/fmu-dataio

Issue:
Add bounding box to tsurf file
https://github.com/equinor/fmu-dataio/blob/d8a1377619c3cfd5533d7613e031810f0e738902/src/fmu/dataio/_readers/tsurf.py#L139

Need to add bounding box to triangulated surfaces as part of #1108.
Appropriate tests should also be made

Discussion:

Solution patch:
diff --git a/src/fmu/dataio/_readers/tsurf.py b/src/fmu/dataio/_readers/tsurf.py
index 950bdfdb7..e137723a6 100644
--- a/src/fmu/dataio/_readers/tsurf.py
+++ b/src/fmu/dataio/_readers/tsurf.py
@@ -285,6 +285,33 @@ class TSurfData(BaseModel):
     def num_triangles(self: TSurfData) -> int:
         return len(self.triangles)
 
+    def bbox(self: TSurfData) -> dict[str, float]:
+        """
+        Return the bounding box of the triangulated surface.
+        The bounding box is defined by the minimum and maximum coordinates
+        in the x, y and z directions.
+        """
+
+        xmin = ymin = zmin = float("inf")
+        xmax = ymax = zmax = float("-inf")
+        for vertex in self.vertices:
+            xcoord, ycoord, zcoord = vertex
+            xmin = min(xcoord, xmin)
+            ymin = min(ycoord, ymin)
+            zmin = min(zcoord, zmin)
+            xmax = max(xcoord, xmax)
+            ymax = max(ycoord, ymax)
+            zmax = max(zcoord, zmax)
+
+        return {
+            "xmin": xmin,
+            "xmax": xmax,
+            "ymin": ymin,
+            "ymax": ymax,
+            "zmin": zmin,
+            "zmax": zmax,
+        }
+
 
 def read_tsurf_file(filepath: Path) -> TSurfData:
     """


Test patch:
diff --git a/tests/test_units/test_reader_tsurf.py b/tests/test_units/test_reader_tsurf.py
index d00cf8405..0f162e632 100644
--- a/tests/test_units/test_reader_tsurf.py
+++ b/tests/test_units/test_reader_tsurf.py
@@ -125,6 +125,14 @@ def test_tsurf_class_methods(tsurf: reader.TSurfData, rootpath: Path) -> None:
 
     assert tsurf.num_vertices() == 4
     assert tsurf.num_triangles() == 2
+    assert tsurf.bbox() == {
+        "xmin": 0.1,
+        "xmax": 3.1,
+        "ymin": 0.2,
+        "ymax": 3.2,
+        "zmin": 0.3,
+        "zmax": 3.3,
+    }
 
 
 def test_tsurf_reader_comments_emptylines(