Skip to content

Commit

Permalink
fix the vertex filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Oct 17, 2023
1 parent 89d82c8 commit 8d12366
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
10 changes: 6 additions & 4 deletions R/vertex-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ wk_vertex_filter <- function(handler, add_details = FALSE) {
#' @export
wk_coords.wk_xy <- function(handleable, ...) {
feature_id <- seq_along(handleable)
not_empty <- !Reduce("&", lapply(unclass(handleable), is.nan))
is_na <- Reduce("&", lapply(unclass(handleable), is.na))
is_nan <- Reduce("&", lapply(unclass(handleable), is.nan))
has_coord <- !is_na & !is_nan

if (!all(not_empty)) {
handleable <- handleable[not_empty]
feature_id <- feature_id[not_empty]
if (!all(has_coord)) {
handleable <- handleable[has_coord]
feature_id <- feature_id[has_coord]
}

new_data_frame(
Expand Down
6 changes: 0 additions & 6 deletions src/vertex-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ int wk_vertex_filter_feature_start(const wk_vector_meta_t* meta, R_xlen_t feat_i
return WK_CONTINUE;
}

int wk_vertex_filter_feature_null(void* handler_data) {
vertex_filter_t* vertex_filter = (vertex_filter_t*)handler_data;
return vertex_filter->next->null_feature(vertex_filter->next->handler_data);
}

int wk_vertex_filter_feature_end(const wk_vector_meta_t* meta, R_xlen_t feat_id,
void* handler_data) {
return WK_CONTINUE;
Expand Down Expand Up @@ -234,7 +229,6 @@ SEXP wk_c_vertex_filter_new(SEXP handler_xptr, SEXP add_details) {
handler->vector_end = &wk_vertex_filter_vector_end;

handler->feature_start = &wk_vertex_filter_feature_start;
handler->null_feature = &wk_vertex_filter_feature_null;
handler->feature_end = &wk_vertex_filter_feature_end;

handler->geometry_start = &wk_vertex_filter_geometry_start;
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-vertex-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
test_that("wk_vertices() works", {
expect_identical(
wk_vertices(wkt(c("POINT (0 0)", "POINT (1 1)", NA))),
wkt(c("POINT (0 0)", "POINT (1 1)", NA))
wkt(c("POINT (0 0)", "POINT (1 1)"))
)
expect_identical(
wk_vertices(wkt(c("LINESTRING (0 0, 1 1)", NA))),
wkt(c("POINT (0 0)", "POINT (1 1)", NA))
wkt(c("POINT (0 0)", "POINT (1 1)"))
)
expect_error(wk_vertices(new_wk_wkt("POINT ENTPY")), "ENTPY")

Expand Down

0 comments on commit 8d12366

Please sign in to comment.