Skip to content

Commit 30c4639

Browse files
authored
ensure 0-based indexing always (#107)
* ensure 0-based indexing always * fix docstring
1 parent 08d4c9e commit 30c4639

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/_tetgen.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/tetgen/pytetgen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,10 @@ def tetrahedralize(
598598
minimal output.
599599
nobisect : bool, default: False
600600
Controls if Steiner points are added to the input surface
601-
mesh. When enabled, the surface mesh will be modified.
601+
mesh. When enabled, the surface mesh will not be modified.
602602
603603
Testing has shown that if your input surface mesh is already well
604-
shaped, disabling this setting will improve meshing speed and mesh
604+
shaped, enabling this setting will improve meshing speed and mesh
605605
quality.
606606
edgesout : bool, default: False
607607
Store all the edges of the tetrahedral mesh after

0 commit comments

Comments
 (0)