Skip to content

Commit

Permalink
add more tests, mess with index shifting from R to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsp-spirit committed Apr 4, 2022
1 parent acfddaa commit a3f6a7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/kdtree.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ interp_tris <- function(query_coordinates, mesh_vertices, nearest_face_vertices,
interp_tris_cpp_wrapper <- function(query_coordinates, mesh_vertices, nearest_face_vertices, pervertex_data, iwd_beta = 2.0) {

# adjust indexing for C++
nearest_face_vertices = nearest_face_vertices + 1L;
#nearest_face_vertices = nearest_face_vertices + 1L;

return(.Call("interp_tris_c", query_coordinates, mesh_vertices, nearest_face_vertices, pervertex_data, iwd_beta));
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_kdtree.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ testthat::test_that("The R and CPP versions of the linear_interpolate_kdtree fun
testthat::expect_true(is.double(dest_pervertex_data_CPP));
testthat::expect_equal(length(dest_pervertex_data_CPP), nrow(dest_mesh$vertices));

# The min values should be zero for both.
testthat::expect_equal(min(dest_pervertex_data_R), 0.0);
testthat::expect_equal(min(dest_pervertex_data_CPP), 0.0);

# The max values are not identical for some reason (precision?), but should be in same range.
testthat::expect_true(max(dest_pervertex_data_R) > 4.6 & max(dest_pervertex_data_R) < 4.8);
testthat::expect_true(max(dest_pervertex_data_CPP) > 4.6 & max(dest_pervertex_data_CPP) < 4.8);

# The real test for similar values:
testthat::expect_equal(dest_pervertex_data_R, dest_pervertex_data_CPP, tolerance=1e-1);

Expand Down

0 comments on commit a3f6a7e

Please sign in to comment.