@@ -47,6 +47,16 @@ struct PyTetgen {
4747 int n_cells = io_out.numberoftetrahedra ;
4848 auto arr = MakeNDArray<int , 2 >({n_cells, n_nodes});
4949 std::memcpy (arr.data (), io_out.tetrahedronlist , sizeof (int ) * n_cells * n_nodes);
50+
51+ // ensure it's 1 based regardless of internal indexing
52+ if (io_out.firstnumber == 1 ) {
53+ int *p = arr.data ();
54+ int total = n_cells * n_nodes;
55+ for (int i = 0 ; i < total; ++i) {
56+ --p[i];
57+ }
58+ }
59+
5060 return arr;
5161 }
5262
@@ -263,18 +273,13 @@ struct PyTetgen {
263273 int *faces = faces_arr.data ();
264274 std::memcpy (faces, io_out.trifacelist , sizeof (int ) * 3 * n_faces);
265275
266- // // Determine if indices are 1-based (tetgen might be 1-based)
267- // int n_points = io_out.numberofpoints;
268- // int max_index = 0;
269- // for (int i = 0; i < n_faces * 3; ++i)
270- // if (faces[i] > max_index)
271- // max_index = faces[i];
272-
273- // // Only convert to 0-based if max index ≥ number of points
274- // if (max_index >= n_points) {
275- // for (int i = 0; i < n_faces * 3; ++i)
276- // faces[i] -= 1;
277- // }
276+ // ensure it's 1 based regardless of internal indexing
277+ if (io_out.firstnumber == 1 ) {
278+ int total = n_faces * 3 ;
279+ for (int i = 0 ; i < total; ++i) {
280+ --faces[i];
281+ }
282+ }
278283
279284 return faces_arr;
280285 }
0 commit comments