@@ -294,6 +294,10 @@ def test_triangular_dataset(tmp_path, ds_name, dataset_type_ind, no_vtk=False):
294294 result = tri_grid .sel (x = np .linspace (0 , 1 , 3 ), y = tri_grid .normal_pos , z = [0.3 , 0.4 , 0.5 ])
295295 assert result .name == ds_name
296296
297+ # selecting only along the normal axis is a no-op and should return self
298+ result_normal_only = tri_grid .sel (y = tri_grid .normal_pos )
299+ assert result_normal_only == tri_grid
300+
297301 # can't select out of plane
298302 with pytest .raises (DataError ):
299303 _ = tri_grid .sel (x = np .linspace (0 , 1 , 3 ), y = 1.2 , z = [0.3 , 0.4 , 0.5 ])
@@ -779,105 +783,6 @@ def test_from_vtk():
779783 _ = td .TriangularGridDataset .from_vtk ("tests/data/gmsh_2d.vtk" )
780784
781785
782- def test_triangular_from_vtu_near_planar_large_coordinates (tmp_path ):
783- """Regression for large-coordinate planar slices with small normal-axis jitter."""
784- pytest .importorskip ("vtk" )
785- import vtk
786-
787- import tidy3d as td
788-
789- tri_grid = td .TriangularGridDataset (
790- normal_axis = 1 ,
791- normal_pos = 0.0 ,
792- points = td .PointDataArray (
793- [
794- [100000.0 , 0.0 ],
795- [101000.0 , 0.0 ],
796- [100000.0 , 690.0 ],
797- [101000.0 , 690.0 ],
798- ],
799- dims = ("index" , "axis" ),
800- ),
801- cells = td .CellDataArray ([[0 , 1 , 2 ], [1 , 2 , 3 ]], dims = ("cell_index" , "vertex_index" )),
802- values = td .IndexedDataArray (
803- [1.0 , 2.0 , 3.0 , 4.0 ], coords = {"index" : np .arange (4 )}, name = "temp"
804- ),
805- )
806-
807- vtu_path = tmp_path / "near_planar_large_coords.vtu"
808- tri_grid .to_vtu (vtu_path )
809-
810- # Inject tiny jitter in the nominally planar normal direction.
811- reader = vtk .vtkXMLUnstructuredGridReader ()
812- reader .SetFileName (str (vtu_path ))
813- reader .Update ()
814- grid = reader .GetOutput ()
815- points = grid .GetPoints ()
816- for ind in range (points .GetNumberOfPoints ()):
817- x , _ , z = points .GetPoint (ind )
818- points .SetPoint (ind , x , 6e-6 if (ind % 2 ) == 0 else - 6e-6 , z )
819- points .Modified ()
820-
821- writer = vtk .vtkXMLUnstructuredGridWriter ()
822- writer .SetFileName (str (vtu_path ))
823- writer .SetInputData (grid )
824- writer .Write ()
825-
826- loaded = td .TriangularGridDataset .from_vtu (vtu_path , field = "temp" )
827- assert loaded .normal_axis == 1
828- assert abs (float (loaded .normal_pos )) < 1e-4
829- assert loaded .points .sizes ["index" ] == 4
830-
831-
832- def test_triangular_from_vtu_far_from_origin_small_extent (tmp_path ):
833- """Regression: tolerance must depend on extent, not absolute position."""
834- pytest .importorskip ("vtk" )
835- import vtk
836-
837- import tidy3d as td
838-
839- tri_grid = td .TriangularGridDataset (
840- normal_axis = 1 ,
841- normal_pos = 0.0 ,
842- points = td .PointDataArray (
843- [
844- [1e9 , - 2e9 ],
845- [1e9 + 2.0 , - 2e9 ],
846- [1e9 , - 2e9 + 1.0 ],
847- [1e9 + 2.0 , - 2e9 + 1.0 ],
848- ],
849- dims = ("index" , "axis" ),
850- ),
851- cells = td .CellDataArray ([[0 , 1 , 2 ], [1 , 2 , 3 ]], dims = ("cell_index" , "vertex_index" )),
852- values = td .IndexedDataArray (
853- [1.0 , 2.0 , 3.0 , 4.0 ], coords = {"index" : np .arange (4 )}, name = "temp"
854- ),
855- )
856-
857- vtu_path = tmp_path / "far_origin_small_extent.vtu"
858- tri_grid .to_vtu (vtu_path )
859-
860- reader = vtk .vtkXMLUnstructuredGridReader ()
861- reader .SetFileName (str (vtu_path ))
862- reader .Update ()
863- grid = reader .GetOutput ()
864- points = grid .GetPoints ()
865- for ind in range (points .GetNumberOfPoints ()):
866- x , _ , z = points .GetPoint (ind )
867- points .SetPoint (ind , x , 2e-7 if (ind % 2 ) == 0 else - 2e-7 , z )
868- points .Modified ()
869-
870- writer = vtk .vtkXMLUnstructuredGridWriter ()
871- writer .SetFileName (str (vtu_path ))
872- writer .SetInputData (grid )
873- writer .Write ()
874-
875- loaded = td .TriangularGridDataset .from_vtu (vtu_path , field = "temp" )
876- assert loaded .normal_axis == 1
877- assert abs (float (loaded .normal_pos )) < 1e-5
878- assert loaded .points .sizes ["index" ] == 4
879-
880-
881786def test_tetrahedral_from_vtk_obj_without_cell_types_array ():
882787 """Regression test for VTK objects with missing ``GetCellTypesArray`` output."""
883788 pytest .importorskip ("vtk" )
0 commit comments