Skip to content

Commit

Permalink
fix: wk_trans inconsistent meta flags handling (#217)
Browse files Browse the repository at this point in the history
* fixes #216

* test wk_trans meta flags used consistently

* add news
  • Loading branch information
anthonynorth authored Mar 7, 2024
1 parent 67f7013 commit 40573b8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# wk (development version)

- Add `wk_crs()` and `wk_set_crs()` methods for `bbox` (#213)
- Fix wk_trans inconsistent meta flags handling (#217)

# wk 0.9.1

Expand Down
2 changes: 1 addition & 1 deletion src/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int wk_trans_filter_coord(const wk_meta_t* meta, const double* coord, uint32_t c
} else if (meta->flags & WK_FLAG_HAS_Z) {
trans_filter->xyzm_in[2] = coord[2];
trans_filter->xyzm_in[3] = R_NaN;
} else if (new_meta->flags & WK_FLAG_HAS_M) {
} else if (meta->flags & WK_FLAG_HAS_M) {
trans_filter->xyzm_in[2] = R_NaN;
trans_filter->xyzm_in[3] = coord[2];
} else {
Expand Down
70 changes: 70 additions & 0 deletions tests/testthat/test-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,73 @@ test_that("wk_transform_filter() errors when the recursion limit is too high", {
"Too many recursive levels"
)
})

test_that("wk_trans uses meta flags consistently", {
# from paleolimbot/wk#216
# NOTE: using wk_trans_set() because it exposes use_z and use_m parameters
# we could equivalently use wk_trans_explicit()

expect_identical(
wk_transform(
xy(1, 1),
wk_trans_set(xy(1, 1), use_z = TRUE)
),
xyz(1, 1, NaN)
)

expect_identical(
wk_transform(
xy(1, 1),
wk_trans_set(xy(1, 1), use_m = TRUE)
),
xym(1, 1, NaN)
)

expect_identical(
wk_transform(
xy(1, 1),
wk_trans_set(xy(1, 1), use_z = TRUE, use_m = TRUE)
),
xyzm(1, 1, NaN, NaN)
)

expect_identical(
wk_transform(
xym(1, 1, 1),
wk_trans_set(xy(1, 1), use_z = TRUE)
),
xyzm(1, 1, NaN, 1)
)

expect_identical(
wk_transform(
xyz(1, 1, 1),
wk_trans_set(xy(1, 1), use_m = TRUE)
),
xyzm(1, 1, 1, NaN)
)

expect_identical(
wk_transform(
xyzm(1, 1, 1, 1),
wk_trans_set(xy(1, 1), use_z = TRUE)
),
xyzm(1, 1, 1, 1)
)

expect_identical(
wk_transform(
xyzm(1, 1, 1, 1),
wk_trans_set(xy(1, 1), use_m = TRUE)
),
xyzm(1, 1, 1, 1)
)

expect_identical(
wk_transform(
xyzm(1, 1, 1, 1),
wk_trans_set(xy(1, 1), use_z = TRUE, use_m = TRUE)
),
xyzm(1, 1, 1, 1)
)
})

0 comments on commit 40573b8

Please sign in to comment.