diff --git a/src/mesh.cpp b/src/mesh.cpp
index 5ab7ac3988b..85fe9046c59 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -1472,7 +1472,11 @@ RegularMesh::RegularMesh(hid_t group) : StructuredMesh {group}
int RegularMesh::get_index_in_direction(double r, int i) const
{
- return std::ceil((r - lower_left_[i]) / width_[i]);
+ if (r == lower_left_[i]) {
+ return 1;
+ } else {
+ return std::ceil((r - lower_left_[i]) / width_[i]);
+ }
}
const std::string RegularMesh::mesh_type = "regular";
diff --git a/tests/cpp_unit_tests/test_mesh.cpp b/tests/cpp_unit_tests/test_mesh.cpp
index 24c4f77373f..d2090db1f32 100644
--- a/tests/cpp_unit_tests/test_mesh.cpp
+++ b/tests/cpp_unit_tests/test_mesh.cpp
@@ -255,3 +255,57 @@ TEST_CASE("Test multiple meshes HDF5 roundtrip - spherical")
REQUIRE(regular_mesh_hdf5->lower_left() == regular_mesh_xml->lower_left());
REQUIRE(regular_mesh_hdf5->upper_right() == regular_mesh_xml->upper_right());
}
+
+TEST_CASE("Test get_index_in_direction - regular mesh")
+{
+ // The XML data as a string
+ std::string xml_string = R"(
+
+ 3 4 5
+ -2 -3 -5
+ 2 3 5
+
+ )";
+
+ // Create a pugixml document object
+ pugi::xml_document doc;
+
+ // Load the XML from the string
+ pugi::xml_parse_result result = doc.load_string(xml_string.c_str());
+
+ pugi::xml_node root = doc.child("mesh");
+
+ auto mesh = RegularMesh(root);
+
+ REQUIRE(mesh.get_index_in_direction(-2.0, 0) == 1);
+ REQUIRE(mesh.get_index_in_direction(-1.99, 0) == 1);
+ REQUIRE(mesh.get_index_in_direction(1.99, 0) == 3);
+ REQUIRE(mesh.get_index_in_direction(2.0, 0) == 3);
+}
+
+TEST_CASE("Test get_index_in_direction - rectilinear mesh")
+{
+ // The XML data as a string
+ std::string xml_string = R"(
+
+ 0.0 1.0 5.0 10.0
+ -10.0 -5.0 0.0
+ -100.0 0.0 100.0
+
+ )";
+
+ // Create a pugixml document object
+ pugi::xml_document doc;
+
+ // Load the XML from the string
+ pugi::xml_parse_result result = doc.load_string(xml_string.c_str());
+
+ pugi::xml_node root = doc.child("mesh");
+
+ auto mesh = RectilinearMesh(root);
+
+ REQUIRE(mesh.get_index_in_direction(0.0, 0) == 1);
+ REQUIRE(mesh.get_index_in_direction(0.01, 0) == 1);
+ REQUIRE(mesh.get_index_in_direction(9.99, 0) == 3);
+ REQUIRE(mesh.get_index_in_direction(10.0, 0) == 3);
+}
diff --git a/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat b/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat
index b457a245c7c..8a4d3368cc4 100644
--- a/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat
+++ b/tests/regression_tests/weightwindows/survival_biasing/local/results_true.dat
@@ -1 +1 @@
-386e507008ed3c72c6e1a101aafc01cfaaff2c0b10555558d1eab6332441f7b17264b55002d721151bac2f3e7c1a8aac4c5ed243f5270533d171850f985206ed
\ No newline at end of file
+0d7b17d4e364bda2be21feb2e5b2aae4be69fc8ed634c4f45062e8efc61b7bd24dcf448837692fd603afe3756501fe8821d134f2d6289179618f85178ddb8793
\ No newline at end of file
diff --git a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat
index 11e5ffa77f5..2e88e2f0e81 100644
--- a/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat
+++ b/tests/regression_tests/weightwindows/survival_biasing/shared/results_true.dat
@@ -1 +1 @@
-d17a437262d3316985fba4b48e21a7fcd5f32ac2d96ef0e66849f567deaeadc1e0f18d5d0bf5e9cab4246dbf823e7f43f249a1f67e928b27ae8c70b89f3cefbf
\ No newline at end of file
+2f1c8efbf6ab0b0c7319fadd7ee8f27b545c1ebab94ebe15cf1133b54227487542966b6d798970c8b37bc19e7041e687687d5285803241bb83f4c8dc40a4d276
\ No newline at end of file